To refund the commissions generated for a specific order you can call this simple code where you specify the ID of the order for which the commission of type refund should be created. Refund is a commission holding all the same details as the original commission but it has negative commission value.

$transaction = new Pap_Api_Transaction($session);
$orderid = "ORD_123_AC"; //ID of order to be refunded, all transactions with this order id will be refunded
$transaction->setOrderId($orderid);
$result = $transaction->refundByOrderId();
//$result = $transaction->chargeBackByOrderId();
//$result = $transaction->refundByOrderId('affiliate note', '0.1');
//$result = $transaction->refundByOrderId('affiliate note', '0.1', 50);
/* you can use parameters for affiliate note, fee and refunded value.
* With defined fee the refunded commission value is calculated as (originalCommission * -1) - definedFee.
* For example refund of a $5 commission with fee set to 10 would produce a negative $15 commission for the affiliate.
* With defined refundValue only a partial refund for the defined value will be created.
*/
//$result = $transaction->chargeBackByOrderId('affiliate note', '0.1');
//$result = $transaction->chargeBackByOrderId('affiliate note', '0.1', 50);
if ($result->isError()) {
    echo 'Error: '.$result->getErrorMessage();
} else {
    echo 'Success: '.$result->getInfoMessage();
}

If you need to select the exact commission for refund, e.g. you have recurring commissions with the same order ID, you can use additional filters for product ID and data1 to data5 fields:

    $transaction = new Pap_Api_Transaction($session);
    $orderid = "ORD_123_AC";
    $transaction->setOrderId($orderid);
    $transaction->setProductId('prod');
    $transaction->setData1('d1');
    $transaction->setData2('d2');
    $transaction->setData3('d3');
    $transaction->setData4('d4');
    $transaction->setData5('d5');
    $result = $transaction->refundByOrderId();

Alternatively if you need more advanced filtering, you can first find the specific commission using the TransactionsGrid API as explained below:

<?php
//-----------------------------------------------------------------------
// PapApi.class.php can be downloaded from the merchant panel at:
// Tools > Integration > API Integration > Download PAP API
require_once 'PapApi.class.php';
$pap_url = 'https://localhost/pap/'; // URL to PAP
$pap_user = 'merchant@example.com'; // Merchant username
$pap_password = 'demo'; // Merchant password
// log in as merchant
$session = new Pap_Api_Session($pap_url . "scripts/server.php");
if(@!$session->login($pap_user, $pap_password)) {
	die("Cannot login. Message: ".$session->getMessage());
}
//-----------------------------------------------------------------------
$transactionsGrid = new Pap_Api_TransactionsGrid($session);
$orderid = "ORD_123_AC"; //ID of order to be refunded.
// filter orders with the given order id -- so we filter also tier commissions, you can use here also another transactions filter
// Use filters very carefully, you can easily make refunds of all transactions!!!
//$transactionsGrid->addFilter("orderid", Gpf_Data_Filter::LIKE, '%'.$orderid.'%');
$transactionsGrid->addFilter("orderid", Gpf_Data_Filter::EQUALS, $orderid);
$response = $transactionsGrid->refund();
//$response = $transactionsGrid->refund('refund note', 0.5);
/* you can use parameters for affiliate note and fee.
* With defined fee the refunded commission value is calculated as (originalCommission * -1) - definedFee.
* For example refund of a $5 commission with fee set to 10 would produce a negative $15 commission for the affiliate.
*/
//for chargeback use: $response = $transactionsGrid->chargeback();
//or $response = $transactionsGrid->chargeback('chargeback note', 0.5);
if ($response->isError()) {
    echo 'Error: '.$response->toText();
} else {
    echo 'Success: '.$response->toText();
}

 

 
×