Refund Transaction

A refund is the process of refunding a previously settled transaction. A refund appears as a credit on the card holder’s credit card statement. It is possible to do multiple refunds on a transaction, but the sum of the refunded amounts must be equal to or less than the amount of the original transaction.


A Refund can only happen on a CCSale, Capture or Rebill transaction. In the case of a Capture transaction, the transactionID of the Capture (not the initial CCAuthorize) must be passed as a parameter.


Endpoints

HTTP Method API URL API Version
POST https://api.payzone.ma/transaction/{transactionID}/refund >= 002

Accepted parameters

Field Type Max Length Required Description Version
transactionID Integer 20 yes Initial transaction reference to capture
amount Integer 10 yes Number in minor unit, e.g. cents; 100 dollar cent equals to 1 dollar
cancelSubscription Integer NA no/td> If true (default), also cancel an eventual subscription associated with the refunded transaction >= 0204

Code samples

Note: Gateway API transactions are done with a different library than payment-page API. See the code sample comments for more info:

   
    /*
    *   Transaction name is 'Refund', once you create a new transaction passing this as parameter, 
    *   you need to set the mandatory data using the following method:
    *    setReferralInformation()
    */

    $client = new GatewayClient();

    $transaction = $client->newTransaction('Refund', 'testMerchant', 'testPassword');
    $transaction->setReferralInformation($saleOrCaptureTransactionID, 200);

    $response = $transaction->send();

    if ('000' === $response->errorCode) {
        $refundTransactionID  = $response->transactionID;
    } else {
        echo "Error {$response->errorCode} with message {$response->errorMessage}";
    }
                      
   
    PaymentGatewayConnector connector = new PaymentGatewayConnector(API_URL, ORIGINATOR, PASSWORD);

    RefundResponse response = null;
    RefundRequest request = new RefundRequest();
    request.setTransactionId(1234567L);
    request.setAmount(2500);

    try {
        response = connector.doRefundTransaction(request);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (response != null) {
        if (TransactionResultCode.TRANSACTION_SUCCESSFULLY.equals(response.getErrorCode()) {
        System.out.println("Success: " + response.getErrorMessage());
        } else {
        System.out.println("Failure: " + response.getErrorMessage());
        }
    }
                      


    const gateway = require("payxpert")("123456", "GreatP4ssw0rd").gateway;

    let transactionId = "111222";

    let refundBody = {
        transactionID: transactionId,
        amount: 1000
    };

    let responseRefund = await gateway.refundTransaction(transactionId, refundBody);

    if (responseRefund.code == "000") {
        // Success
    }
        
        

    var client = new GatewayClient(OriginatorConfig.ORIGINATOR_ID, OriginatorConfig.ORIGINATOR_PASSWORD);
    var refundTransaction = client.NewRefundTransaction(response.transactionID);
    refundTransaction.SetInformationForRefund(1000, null);

    var response = await refundTransaction.Send();

    if (response.IsSuccessfull())
    {
        Console.WriteLine("Capture operation ok. Capture transaction ID: " + response.transactionID);
    }

                        

Response

The body of the response is in JSON format.

The following fields are present in the response :


Name Type Description
transactionID String Transaction reference returned by the system
errorCode String See API Response Codes
errorMessage String See API Response Codes

© Payzone | 2022