Cancel Transaction

A cancel is the process of reversing a previously authorized, but not yet captured, transaction. It means that the cancel transaction will never appear on the card-holder’s credit card statement. Usually authorization is valid for a given period of time (the period of time varies based on the issuing bank of the credit card). Whilst this call cancels an authorization, in most cases though the card-holder’s funds remain ring-fenced and deducted from their available credit for 7 to 30 days.


A Cancel can only happen on a non-captured, non-canceled CCAuthorize transaction.


Endpoints

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

Accepted parameters

Field Type Max Length Required Description
transactionID Integer 20 yes Initial transaction reference to refund
amount Integer 10 yes Number in minor unit, e.g. cents; 100 dollar cent equals to 1 dollar

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 'Cancel', 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('Cancel', 'testMerchant', 'testPassword');
    $transaction->setReferralInformation($transactionID, 200);

    $response = $transaction->send();

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

    CancelResponse response = null;
    CancelRequest request = new CancelRequest();
    request.setTransactionId(1234567L);
    request.setAmount(2500);

    try {
        response = connector.doCancelTransaction(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;

    const body = {
        customerIP: "8.8.4.4",
        amount: 1500,
        currency: "EUR",
        orderID: "HELLO NODEJS",

        cardNumber: "4111111111111111",
        cardSecurityCode: "000",
        cardHolderName: "CARDHOLDER NAME",
        cardExpireMonth: "10",
        cardExpireYear: "2024",

        shopperName: "NodeJS Test",
        shopperAddress: "NA",
        shopperZipcode: "NA",
        shopperCity: "NA",
        shopperState: "NA",
        shopperCountryCode: "NA",
        shopperPhone: "NA",
        shopperEmail: "NA"
    };

    const response = await gateway.creditCardAuthorize(body);

    if (response.code == "000") {
        // Success: authorization done
        // now will cancel the transaction

        let cancelBody = {
            transactionID: response.transactionID,
            amount: amountForTest
        };

        let responseCancel = await gateway.cancelTransaction(response.transactionID, cancelBody);

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

        
   
    var client = new GatewayClient(OriginatorConfig.ORIGINATOR_ID, OriginatorConfig.ORIGINATOR_PASSWORD);
    var transaction = client.NewAuthorizeTransaction();

    var amount = 1000;

    transaction.SetTransactionInformation(amount, "EUR", "50", "8.8.8.8");
    transaction.SetCardInformation("4111111111111111", "000", "CSHARP SDK", "10", "2024");
    transaction.SetShopperInformation("CSHARP SDK", "MICROSOFT HELL", "666", "REDMOND", "WA", "US", "12445", "x@x.rr");

    var response = await transaction.Send();

    if (response.IsSuccessfull())
    {
        Console.WriteLine("Authorize operation ok. Transaction ID: " + response.transactionID);

        // Now will cancel this authorization
        var cancelTransaction = client.NewCancelTransaction(response.transactionID);
        cancelTransaction.SetAmount(amount);

        var cancelResponse = cancelTransaction.Send().Result;

        if (cancelResponse.IsSuccessfull())
        {
            Console.WriteLine("Cancel is ok. New transaction ID: " + cancelResponse.transactionID);
        }
        else
        {
            Console.WriteLine("Error performing cancel: " + cancelResponse.errorMessage);
        }
    }
                        
                        

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