The following php API example shows how to update the payout option information of a particular affiliate.
<?php
//your PapApi.class.php file can be downloaded in the merchant panel: Tools>Integration>API Integration>Download PAP API
include ("PapApi.class.php"); //this include assumes the PapApi.class.php is in the same dir as this script
$papURL = "https://localhost/pap"; //URL leading to your Post Affiliate Pro (or Network) without trailing slash
$merchantUsername = "test@merchant.com"; //your merchant username
$merchantPassword = "testPassword"; //your merchant password
//userid of affiliate whose payout info you wish to display, update
$affiliateUserId = "11111111";
$session = new Pap_Api_Session($papURL."/scripts/server.php");
if(@!$session->login($merchantUsername,$merchantPassword)) {
die('Cannot login. Message: '. $session->getMessage());
}
$minimumPayout="";
$payoutOptionId="";
//array of fields (code, name, type, status)
$payoutFields = array();
//Payout Option ID and Minimimum payout
//a request to find out the payout option id and minimum payout limit
$request = new Gpf_Rpc_FormRequest('Pap_Merchants_User_AffiliateForm', 'loadPayouts', $session);
$request->setField('Id',$affiliateUserId);
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die('API call error: '.$e->getMessage());
}
$responseForm = $request->getForm();
if ($responseForm->isSuccessful()) {
$minimumPayout = $responseForm->getFieldValue('minimumpayout');
$payoutOptionId = $responseForm->getFieldValue('payoutoptionid');
}
if ($payoutOptionId == '') {
die("The affiliate $affiliateUserId does not have a payout option chosen");
}
$request = new Gpf_Rpc_Request('Pap_Merchants_PayoutOptionListBox', 'getRow', $session);
$request->addParam('search', $payoutOptionId);
try {
$request->sendNow();
} catch(Exception $e) {
die('API call error: '.$e->getMessage());
}
$responseRecordSet = new Gpf_Data_RecordSet();
$responseRecordSet->loadFromObject($request->getStdResponse());
$record = $responseRecordSet->getRecord(0);
echo 'Payout Option name: ' . $record->get('name');
echo '<br>';
echo 'Payout Option id: ' . $payoutOptionId;
echo '<br>';
//Fields
//find out what fields are included in the particular payout option
$request = new Gpf_Rpc_Request('Gpf_Db_Table_FormFields', 'getFields', $session);
$request->addParam('formId','payout_option_'.$payoutOptionId);
$request->addParam('status','M,O,P,R,S,W,H'); //M - mandatory,O - optional, P - optional not in signup, R - readonly, S - writable only in signup, W - writable only in signup (mandatory), H - hidden
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die('API call error: '.$e->getMessage());
}
$responseRecordSet = new Gpf_Data_RecordSet();
$responseRecordSet->loadFromObject($request->getStdResponse());
foreach ($responseRecordSet as $record) {
$payoutFields[] = array($record->get('code'), $record->get('name'), $record->get('type'), $record->get('status'));
}
//---------------------------------------------------
//display (load) the payout fields and their data
$request = new Gpf_Rpc_FormRequest('Pap_Merchants_User_AffiliateForm', 'loadPayoutFields', $session);
$request->setField('Id',$affiliateUserId);
$request->setField('payoutOptionId', $payoutOptionId);
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die('API call error: '.$e->getMessage());
}
$responseForm = $request->getForm();
if ($responseForm->isSuccessful()) {
echo 'Payout Option fields values: ';
echo '<br>';
foreach ($payoutFields as $payoutField) {
echo trim($payoutField[1], '#') . ': ' . $responseForm->getFieldValue($payoutField[0]);
echo '<br>';
}
}
echo 'Minumum payout: '.$minimumPayout;
//---------------------------------------------------
//---------------------------------------------------
//update a particular field (or multiple fields)
$request = new Gpf_Rpc_FormRequest('Pap_Merchants_User_AffiliateForm', 'savePayouts', $session);
$request->setField('Id',$affiliateUserId);
$request->setField('payoutoptionid', $payoutOptionId);
//for each payout option there are different fields available
//in this example we update the fields of a WireTransfer payout option
//no matter which field you wish to change, all of them have to be present
$request->setField("accnt_name","TestBankAccount");
$request->setField("accnt_number", "22222222222");
$request->setField("bank_name","TestBANK");
$request->setField("bank_code","1212");
$request->setField("bank_address","TestBank Street");
$request->setField("swift","swift123");
//---------------------------------------------------
// enabling, updating VAT invoicing
// no matter which field you wish to change, all of them have to be present
// otherwise, if the affiliate had it enabled and the rows are not present
// the VAT invoicing would be disabled for the particular affiliate
$request->setField("support_vat","Y");
$request->setField("applyVatInvoicing","Y");
$request->setField("vatPercentage","10");
$request->setField("vatNumber","VT123456");
$request->setField("amountOfRegCapital","222");
$request->setField("regNumber","7777");
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die('API call error: '.$e->getMessage());
}
?>