Example code that loads transactions (even tier commissions) with the defined order ID and refunds them, which means that another transaction with the same order ID, total cost, but negative commission and with type of 'refund' will be created.

 
<?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();
}
Since version 5.5.16.1 you can use functions `refundByOrderId()` or `chargeBackByOrderId()` on object `Pap_Api_Transaction`
 

$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();
}
 
 
×