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).

Note: The first parameter of setLimit() is an offset that is no longer used since version 5.11.8.1 — always pass 0. Paging is handled automatically: sending the same request object again returns the next page of records. The maximum number of records returned in one request is 500. Use the largest page size your script can handle, as it means fewer API calls. Details are described in the Gpf_Rpc_GridRequest article.

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');

// sets the page size to 500 rows, which is the maximum per request
// the first parameter is an offset which is not used, always keep it at 0
$request->setLimit(0, 500);

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

// execute request in a loop to load all data
// sending the same request again returns the next page
do {
    // send request
    try {
        $request->sendNow();
    } catch(Exception $e) {
        die("API call error: ".$e->getMessage());
    }
    // request was successful, get the grid result and its recordset
    $grid = $request->getGrid();
    $recordset = $grid->getRecordset();

    echo "Total number of records matching the filter: ".$grid->getTotalCount()."<br>";
    echo "Number of records returned on this page: ".$recordset->getSize()."<br>";

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

Example of paging in older versions than 5.11.8.1

Important: The example below is kept for reference only. Do not use it on version 5.11.8.1 and newer. If your script sends an offset, the request fails with the error API: Using "offset" in grid requests is not allowed. To resolve it, download a new PapApi.class.php file in the merchant panel at Tools > Integration > API Integration > Download PAP API and use the paging shown in the first example.


$request->sendNow();
$grid = $request->getGrid();
$recordset = $grid->getRecordset();

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

if ($maxRecords > 0) {
    $cycles = ceil($totalRecords / $maxRecords);
    for($i=1; $i<$cycles; $i++) {
        // now get the next page of 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>';
        }
    }
}

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.