Pap_Api_TransactionsGrid

Grid object - this class handles requests to the list of transactions. You can use it to search and filter in the registered transactions (commissions).

Example retrieving list of all transactions (do not forget to login via api as merchant):

//----------------------------------------------
// get recordset of list of transactions
$request = new Pap_Api_TransactionsGrid($session);

// set filter
$request->addFilter('dateinserted', Gpf_Data_Filter::DATERANGE_IS, Gpf_Data_Filter::RANGE_THIS_YEAR);

// list here all columns which you want to read from grid
$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'),array('transid'),array('campaignid'), array('orderid'), array('commission'),  array('userid'))));

$request->addFilter('orderid', Gpf_Data_Filter::EQUALS, 'ORD_123');

$request->setLimit(0, 100);

$request->setSorting('orderid', false);

$request->sendNow();

$grid = $request->getGrid();

$recordset = $grid->getRecordset();

echo "Total number of records: ".$grid->getTotalCount()."<br>";

echo "Number of returned records: ".$recordset->getSize()."<br>";

// iterate through the records
foreach($recordset as $rec) {
  echo 'Transaction OrderID: '.$rec->get('orderid').', Commission: '.$rec->get('commission').'<br>';
}
//----------------------------------------------
//The first grid request returns only a limited number of records, depends on setLimit() function. If you want to retrieve all records, see using the cycle in the code below:

while ($recordset->getSize() == $request->getLimit()) {
     $request->sendNow();
     $recordset = $request->getGrid()->getRecordset();
     // iterate through the records
     foreach($recordset as $rec) {
       echo 'Transaction OrderID: '.$rec->get('orderid'). ', Commission: '.$rec->get('commission').'<br>';
     }
}

Example of paging in older versions than 5.11.8.1


$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();

if ($maxRecords > 0) {
    $cycles = ceil($totalRecords / $maxRecords);
    for($i=1; $i<$cycles; $i++) {
      // now get next 100 records
      $request->setLimit($i * $maxRecords, $maxRecords);
      $request->sendNow();
      $recordset = $request->getGrid()->getRecordset();
      // iterate through the records
      foreach($recordset as $rec) {
        echo 'Transaction OrderID: '.$rec->get('orderid'). ', Commission: '.$rec->get('commission').'<br>';
      }
    }
}
The grid returns only a limited number of records, depends on setLimit() function. If you want to retrieve all records, check how we did it using the cycle in the code above.

You can request all these parameters with $rec->get() function:

id or transid (they are the same), userid, campaignid, commission, totalcost, fixedcost, orderid, productid, dateinserted, dateapproved, countrycode, name, rtype, commissionTypeName, commtypeid, tier, username, firstname, lastname, rstatus, payoutstatus, ip, refererurl, browser, recurringcommid, payouthistoryid, clickcount, firstclicktime, firstclickreferer, firstclickip, firstclickdata1, firstclickdata2, lastclicktime, lastclickreferer, lastclickip, lastclickdata1, lastclickdata2, data1, data2, data3, data4, data5, originalcurrencyid, original_currency_code, originalcurrencyrate, originalcurrencyvalue, merchantnote, systemnote, banner_name, banner_type, bannerid, payoutdate, loggroupid, accountid

e.g. $rec->get('username');

Notice that these columns are available only if you list them in 'columns' param:
$request->addParam('columns', new Gpf_Rpc_Array(array(array('username'),array('transid'),...

Affiliate Filter

If you want to load transactions per affiliate User ID or Referral ID you can use filter:

//if you have user ID

$request->addFilter('userid', Gpf_Data_Filter::EQUALS, '761b2a5d');

//for more affiliates:

$request->addFilter('userid', 'IN', '761b2a5d,ceba10bf');

//if you have refid

$request->addFilter('refid', Gpf_Data_Filter::EQUALS, 'refidaff1');

//or for more affiliates:

$request->addFilter('refid', 'IN', 'refidaff1,refidaff2');

Additional methods:

refund($note = '', $fee = 0, $refundValue = 0) - makes refunds of all transactions filtered by transactions grid, into transactions grid is needed to add filter.

chargeback($note = '', $fee = 0$refundValue = 0) - makes chargebacks of all transactions filtered by transactions grid, into transactions grid is needed to add filter

 

Use these methods very carefully, they can easily make refunds of all transactions!!!

 

Example creating refunds of all transactions with orderid: 'oid_123'

// make refunds of all transactions with orderid: 'oid_123'
$request = new Pap_Api_TransactionsGrid($session);
// set filter
$request->addFilter("orderid", Gpf_Data_Filter::EQUALS, 'oid_123');
//you can set additional fee
$fee = 0;
$response = $request->refund('note', $fee);

echo $response->toText();

 

FAQ:

Q: How can I select transactions from specific date range?
A: Use this filters after creating request object

$request->addFilter('dateinserted', 'D>=', '2011-03-30');

$request->addFilter('dateinserted', 'D<=', '2011-03-31');
This will select you transactions from 2011-03-30 00:00:00 to 2011-03-31 23:59:59. 
Selecting wit specific time is possible since version higher than 4.5.71.1, example: 
$request->addFilter('dateinserted', 'D>=', '2011-03-30 15:50:00');

$request->addFilter('dateinserted', 'D<=', '2011-03-31 23:59:59');
This will select you transactions from 2011-03-30 15:50:00 to 2011-03-31 23:59:59. 
Notice, that these dates are in server timezone (PAP uses by default 'America/Los_Angeles' timezone), but dates displayed through merchant/affiliate panel are shifted into client timezone. Read more here.
×