How to recompute transaction

This examples show how to recompute commission of transaction. 
 
If you know campaignid, userid, commissiontypeid you can compute commission so:
 
<?php
include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory

//----------------------------------------------
// login (as merchant)

$session = new Pap_Api_Session("URL_to_PAP/scripts/server.php");

if(!$session->login("merchant@example.com","merchant_password")) {
  die("Cannot login. Message: ".$session->getMessage());
} 

$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CampaignForm", "computeAutomaticCommissionRpc", $session);

$request->addParam('campaignid', '11111111');  //Id column in Campaign manager
$request->addParam('userid', '22222222');  //Id column in Affiliate manager
$request->addParam('type', '2a1c1bb2');  //Commissiontypeid, can be found in Merchant panel: Start -> Campaigns manager -> Edit -> Commissions settings
$request->addParam('tier', '1');
$request->addParam('totalcost', '580');
$request->addParam('fixedcost', '0');


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

$response = $request->getStdResponse();
$fields = $response->fields;
echo 'new computed commission: ' . $fields[1][1];

?>
If you know transactionid, you can change totalcost and recompute and save transaction this way:
 
<?php
include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory

//----------------------------------------------
// login (as merchant)
$session = new Pap_Api_Session("URL_to_PAP/scripts/server.php");

if(!$session->login("merchant@example.com","merchant_password")) {
  die("Cannot login. Message: ".$session->getMessage());
}

$transactionId = 'fced0452';
//----------------------------------------------
//loading transaction with id = fced0452
$transaction = new Pap_Api_Transaction($session);

$transaction->setTransId($transactionId);
if (!($transaction->load())) { //loads the record with the given transaction id.
die ("<br>Loading of transaction failed!<br>".$transaction->getMessage());
}

$newTotalCost = '111';

//----------------------------------------------
//computing commission
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CampaignForm", "computeAutomaticCommissionRpc", $session);

$request->addParam('campaignid', $transaction->getCampaignid());
$request->addParam('userid', $transaction->getUserid());
$request->addParam('type', $transaction->getCommTypeId());
$request->addParam('tier', $transaction->getTier());
$request->addParam('totalcost', $newTotalCost);
//$request->addParam('fixedcost', '0');  //you can set fixedcost also

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

$response = $request->getStdResponse();
$fields = $response->fields;
$newCommission = $fields[1][1];
echo 'new computed commission: ' . $fields[1][1];

//----------------------------------------------
//saving transaction with new totalcost and commission
$transaction->setTotalCost($newTotalCost);
$transaction->setCommission($newCommission);

$transaction->save();
echo "<br>Transaction has been recomputed.";


?>
 
×