Refund of Transaction

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.

// 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 = 'http://localhost/pap/'; // URL to PAP
$pap_user = ''; // 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

//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 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

$result = $transaction->refundByOrderId();
//$result = $transaction->chargeBackByOrderId();
//$result = $transaction->refundByOrderId('affiliate note', '0.1');
//$result = $transaction->chargeBackByOrderId('affiliate note', '0.1');

if ($result->isError()) {
    echo 'Error: '.$result->getErrorMessage();
} else {
    echo 'Success: '.$result->getInfoMessage();