Make sure the Recurring commissions feature is turned on in the Features section in your merchant panel. As soon as it is turned on click the Configure button next to it and check in the "Use only API to trigger commissions (planned task will be disabled)" check box.
Afterwards, when you are setting up a recurring commission in a campaign, make sure that for the period of recurrence you choose varied. It is essential! And also make sure, that the particular recurring prescription at Transactions > Recurring commission rules is approved.
When everything is configured you can use a similar code like this one below to trigger a recurring commission for a specific Order ID:
include 'PapApi.class.php'; $session = new Pap_Api_Session("URL_TO_PAP/scripts/server.php"); //authentication is not needed if you disable 'Require authentication' in feature configuration if(!@$session->login("merchant@login.com","merchantPassword")) { die("Cannot login. Message: ". $session->getMessage()); } $recurringCommission = new Pap_Api_RecurringCommission($session); $recurringCommission->setOrderId('order_123456789'); try { $recurringCommission->createCommissions(); } catch (Exception $e) { die("Can not process recurring commission: ".$e->getMessage()); }
If you want to create a recurring commission with different total cost than what was used for its initial payment you can use function setTotalCost($value); (since version 4.5.87.1). This is handy in cases when the initial payment has a different total cost than the recurring payment.
$session = new Pap_Api_Session("URL_TO_PAP/scripts/server.php"); $recurringCommission = new Pap_Api_RecurringCommission($session); $recurringCommission->setOrderId('order_123456789'); $recurringCommission->setTotalCost('100'); try { $recurringCommission->createCommissions(); } catch (Exception $e) { die("Can not process recurring commission: ".$e->getMessage()); }
Since version 5.4.12.5 it is possible to use function 'createCommissionsReturnIds()' which returns list of IDs of all created recurring commissions.
$session = new Pap_Api_Session("URL_TO_PAP/scripts/server.php"); $recurringCommission = new Pap_Api_RecurringCommission($session); $recurringCommission->setOrderId('order_123456789'); $recurringCommission->setTotalCost('100'); try { $recordsetIdsObject = $recurringCommission->createCommissionsReturnIds(); } catch (Exception $e) { die("Can not process recurring commission: ".$e->getMessage()); } $recordsetIds = new Gpf_Data_RecordSet(); $recordsetIds->loadFromArray($recordsetIdsObject); foreach ($recordsetIds as $recordId) { echo 'ID: '.$recordId->get('id'); }
If your recurring commission is using a different currency than what your default is then you will have to set currency of the recurring transaction with function 'setCurrency()' (available since version 5.9.22.3). Here is the code :
$recurringCommission->setCurrency('EUR');
Another helpful feature is to use different extra data values for each recurring commission. It is possible to specify data1 to data5 with any value since version 5.11.3.12. Here's an example of use:
$recurringCommission = new Pap_Api_RecurringCommission($session);
$recurringCommission->setOrderId('order_123456789');
$recurringCommission->setTotalCost('100');
$recurringCommission->setData1('dd1');
$recurringCommission->setData2('dd2');
$recurringCommission->setData3('dd3');
$recurringCommission->setData4('dd4');
$recurringCommission->setData5('dd5');
try {
$recordsetIdsObject = $recurringCommission->createCommissions();
echo 'processed';
} catch (Exception $e) {
//var_export($e);
die("Can not process recurring commission: ".$e->getMessage());
}
If you want a recurring commission to be created with a different ID (to keep tracking of unique transaction IDs from your store) you may use the following code. It will match the recurring transaction with its original (initial) order yet it will use transaction's unique ID:
$recurringCommission->setNewOrderId('transaction_987654321');