Pap_Api_RecurringCommission

Triggering the recurring commission via php API can be useful when you want some special recurence presets or you are integrating PAP with some custom payment processor.

So, make sure the Recurring commissions feature is turned on in the Features section in the 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 commissions  is approved.

When everything is set up, you can use a similar code like this one below to trigger a recurring commission for a specified 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 authentification' in feautre 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());
}
 
This API is available since version 4.1.4.14
 
If you want to create recurring commission with different total cost as was used for initial payment you can use function setTotalCost($value); (since version 4.5.87.1)
 
$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, 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');
}