Get the list of recurring rules (recurring commissions)

The following API example shows how to obtain the unique IDs (or other details) of recurring rules that you see in the merchant panel at Transactions > Recurring commissions.
 
<?php
include_once ("PapApi.class.php"); //this include assumes the PapApi.class.php is in the same dir as this script
  
  
//change localhost/pap to the path of your Post Affiliate Pro installation
$session = new Pap_Api_Session("https://URL_TO_PAP/scripts/server.php"); 
   
//login as merchant
if(!$session->login("merchant@username.com", "MerchantPassword")) { // change it here for your username and password 
	die("Cannot login. Message: ".$session->getMessage());
}

$request = new Gpf_Rpc_GridRequest("Pap_Features_RecurringCommissions_RecurringCommissionsGrid", "getRows", $session);

//enable all columns
//id,userid,username,firstname,lastname,totalcost,orderid,datecreated,datelastcommission,rstatus,recurrencepresetname
$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('userid'), 
array('username'), array('firstname'), array('lastname'), array('totalcost'), 
array('orderid'), array('datecreated'), array('datelastcommission'), array('rstatus'), 
array('recurrencepresetname'))));


$request->setLimit(0, 30);


//Add some filter
//filtering only the approved ones
$request->addFilter('rstatus',Gpf_Data_Filter::EQUALS,'A');

// send request
try {
  $request->sendNow();
} catch(Exception $e) {
  die("API call error: ".$e->getMessage());
}

// request was successful, get the grid result
$grid = $request->getGrid();

// get recordset from the grid
$recordset = $grid->getRecordset();


//available columns
//id,userid,username,firstname,lastname,totalcost,orderid,datecreated,datelastcommission,rstatus,recurrencepresetname

// iterate through the records
foreach($recordset as $rec) {
  echo 'ID of recurring prescription: '.$rec->get('id').', OrderID:'.$rec->get('orderid').'<br>';
}

//----------------------------------------------
// in case there are more than 30 records in total,
// we should load and display the rest of the records
// via the cycle below

$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();
if ($maxRecords > 0) {
	$cycles = ceil($totalRecords / $maxRecords);
	for($i=1; $i<$cycles; $i++) {
	  // now get next 30 records
		$request->setLimit($i * $maxRecords, $maxRecords);
		$request->sendNow();
		$recordset = $request->getGrid()->getRecordset();
		// iterate through the records
		foreach($recordset as $rec) {
			echo 'ID of recurring prescription: '.$rec->get('id').', OrderID:'.$rec->get('orderid').'<br>';
		}	  
	}
}
?>
 
×