using setTransactionSettings in the Authorize.net PHP API - php

I am trying to set the duplicateWindow time using:
$transactionRequestType->setTransactionSettings();
I found this in the PHP SDK code,
public function setTransactionSettings(array $transactionSettings) {...}
That tells me this method accepts an array, but I'm not sure how to format the data I send.
I found the XML version:
<transactionSettings>
<setting>
<settingName>duplicateWindow</settingName>
<settingValue>0</settingValue>
</setting>
</transactionSettings>
But I'm not sure how to translate that into a PHP array.
Thanks,
D

This works if you only want to set a single setting.
I'm still trying to figure out how to set multiple settings (you get duplicate key issues if you try to set more than one).
$transactionSettings = array(
'setting' => array(
'settingName' => 'duplicateWindow',
'settingValue' => 0
)
);

Here is the solution I ended up using and it works fine.
$duplicateWindowSetting = new AnetAPI\SettingType();
$duplicateWindowSetting->setSettingName("duplicateWindow");
$duplicateWindowSetting->setSettingValue("120");
$transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
To add multiple new settings, it would be pretty similar, just making a new instance of class SettingType() for each different setting you wanted.
Something like:
//add the values for each setting
$duplicateWindowSetting = new AnetAPI\SettingType();
$duplicateWindowSetting->setSettingName("duplicateWindow");
$duplicateWindowSetting->setSettingValue("600");
$allowPartialAuthSetting = new AnetAPI\SettingType();
$allowPartialAuthSetting->setSettingName("allowPartialAuth");
$allowPartialAuthSetting->setSettingValue("true");
and so on, then adding each transaction setting to the transaction request by doing something like:
$transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
$transactionRequestType->addToTransactionSettings($allowPartialAuthSetting);

Related

PHP and Protobuf FieldMasks for Google API

I found the documentation just fine, but for the life of me I can't figure out how to set up the FieldMasks in PHP to update a CloudSchedulerClient.
The command should be like this:
$client->updateJob($job, $updateMask); but no matter what I set the $updateMask variable to, my code keeps saying Expect Google\Protobuf\FieldMask. If for instance I wanted to update the description of a cron job to "test", 'description' => 'test', how should I go about that?
If you share some code, that would be helpful.
The error suggests that you are not providing the proper type. Your code should look something like this:
use Google\Protobuf\FieldMask;
$updateMask = new FieldMask([
'paths' => ['description']
]);
$client->updateJob($job, $updateMask);

PHRets using POST

I'm using PHRets and trying to return some search results. Below is the code, which is very basic and should work:
include('../include/common.php');
include('../classes/phrets.php');
$rets = new phRETS();
$connect = $rets->connect(RETS_LOGIN_URL, RETS_USERNAME, RETS_PASSWORD);
if($connect){
$search = $rets->SearchQuery('PROPERTY', 'RES', '((COUNTY=Dallas))', array('LIMIT'=>20));
print_r($rets->Error());
echo $rets->TotalRecordsFound($search);
$rets->Disconnect();
}else{
$error = $rets->Error();
print_r($error);
}
When I run the page, I receive the following error:
Array ( [type] => rets [code] => 20203 [text] => The request limit is too large for a GET. Please use the POST method to submit your search. ) 0
I don't see a parameter to force PHRets to send the request as a POST. Will this require a hack of the class, or am I missing something?
Thanks
EDIT: I just heard back from the developer. It's not supported at this time. Perhaps a less-busier person should clone it and work on that.. :) Anyway, if anyone has already has modified the code to make this work, let me know, please.
Get the latest phRETS version which supports POST method from here and replace with your old phrets.php.
then you need to add an extra line to the script
$rets->SetParam('use_post_method', true);
Note: By default it will be GET method.
I've published an updated version supporting POST searches available at https://github.com/nathanklick/PHRETS or via composer by adding "nathanklick/phrets": "1.0.2" to your composer.json file.

Cleanest way to include urls in Moodle emails

I'd like to know which is the cleanest way to insert an url in an email sent by Moodle module.
So far I'm using this formula, what IMHO I don't think is the cleanest way:
$url = $CFG->wwwroot.'/mod/<mymodulename>/view.php?id='.$cm->id;
The things I don't like here are:
Using $CFG->wwwroot
/mod/<mymodulename> needs to be provided always. (Assume here that I'm using a constant instead of a hardcoded string).
I expected Moodle to have a function to provide this out of the box just when providing module script. I've tried moodle_url but this function doesn't provide the path to the php script when used this way:
new moodle_url('view.php?id='.$cm->id);
I just get:
view.php?id=XX
Thanks in advance.
I would do it like this
$url = new moodle_url('/mod/<mymodulename>/view.php', array('id' => $cm->id));
echo html_writer::link($url, get_string('linktitle', 'mod_mymodulename'));
You can use following statement:
This is Absolute path of file
$url = new moodle_url($CFG->wwwroot.'/mod//view.php', array('id' => $cm->id));

Three JSON strings in one AJAX request conflicting in Zend

I have three different request for my ajax:
$result = Map_Model_Map_Factory::getCityByRegionAlias($alias);
$resultCountUsers = User_Model_User_Factory::countUserByRegion($alias);
$resultCountPartners = User_Model_User_Factory::countPartnersByRegion($alias);
First request works pretty well. But second and third conflicts with each other. If $this->_helper->json($resultCountUsers); comes first, then it works:
$this->_helper->json($resultCountUsers);
$this->_helper->json($resultCountPartners);
$this->_helper->json($result);
I get what I need countUsers: "1" but I don't have countPartners. And vice versa, if $this->_helper->json($resultCountPartners); comes first, then I get countPartners without countUsers.
Maybe somebody know, what's going on and how I can receive that.
I don't use Zend, but there is clearly a problem: you are not providing attribute names for the JavaScript object. I wonder whether you are overwriting each response with the next one.
See what effect this has in your AJAX viewer:
$this->_helper->json(
array(
'resultCountUsers' => $resultCountUsers,
'resultCountPartners' => $resultCountPartners,
'result' => $result,
)
);

How to mail to a static list segment with mailchimp API

Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used

Categories