Cancel a Transaction

Endpoints

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

This call permits to a merchant to cancel the given transaction. The cancel call must be done only for transaction operations than can be cancelled: authorize and submission. Note that the transactionID that uniquely identifies the transaction is part of the URL (the string {transactionID} in the URL must be replaced by the transactionID returned in the initial payment status). The information for the payment are serialized in JSON format and are transmitted in the body of the request.

Accepted parameters

Name Type Description Required API Version
apiVersion String(8) API version to be used (default 002.51) yes >= 002.51
amount Integer(32bits) The amount for the capture in cents (for 1€ => 100) yes >= 002.51

Response

The body of the response to a payment cancel request is in JSON format.

The following fields are present in the response :


Name Type Description API Version
code String(3) API response code (see API response codes in annexe for possible values) >= 002.51
message String(255) Human readable message associated with the code >= 002.51
transactionID String(20) The unique identifier of the transaction >= 002.51
operation String(32) The effective operation done for the operation >= 002.51

Code samples

       
    use PayXpert\Connect2Pay\Connect2PayClient;

    $url = "https://paiement.payzone.ma";
    // This will be provided once your account is approved
    $originator  = "000000";
    $password    = "Gr3atPassw0rd!";

    $transactionId = "example";
    $amount = "100";
    $c2pClient = new Connect2PayClient($url, $originator, $password);

    $status = $c2pClient->cancelTransaction($transactionId, $amount);

    if ($status != null && $status->getCode() != null) {
        $code = (int) $status->getCode();
        echo "Error code: " . $status->getCode() . "\n";
        echo "Error message: " . $status->getMessage() . "\n";
        echo "Transaction ID: " . $status->getTransactionID() . "\n";
    } else {
        echo "Error: " . $c2pClient->getClientErrorMessage() . "\n";
    }
                    
   
    // Instantiate the client and send the cancel request
    // Second argument is the originator ID, third one is the associated API key
    Connect2payClient c2p = new Connect2payClient("https://paiement.payzone.ma", "123456", 
    "GreatP4ssw0rd");

    TransactionCancelRequest request = new TransactionCancelRequest();
    TransactionCancelResponse response = null;

    request.setAmount(100);
    request.setTransactionId("example");

    try {
        response = c2p.cancelTransaction(request);
    } catch (Exception e) {
        logger.error("Ooops, an error occurred canceling the transaction: " + e.getMessage());
        // Handle the error...
    }
                      
   
    const paymentPage = require("payxpert")("123456", "GreatP4ssw0rd").connect2pay;

    // To make this request we need to know TransactionID of original transaction to be cancelled
    const responseCancel = await paymentPage.cancelTransaction(transactionId, amount);

    if (responseCancel) {
        console.log("Error code: " + responseCancel.code);
        console.log("Error message: " + responseCancel.message);
        console.log("Transaction ID: " + responseCancel.transactionID);
    } else {
        console.log("Error occurred");
    }     
                        
   
    var client = new Connect2PayClient(OriginatorConfig.ORIGINATOR_ID, 
    OriginatorConfig.ORIGINATOR_PASSWORD);

    var requestCancel = client.NewRequestTransactionCancel(transactionID);
    requestCancel.SetAmount(1500);
    var responseCancel = await requestCancel.Send();

    if (responseCancel.IsSuccessfull())
    {
        Console.WriteLine("Cancellation transaction ID: " + responseCancel.transactionID);
    } else {
        Console.WriteLine("Cancellation request failure: " + responseCancel.code + ": " + responseCancel.message);
    }
                        
                        

© Payzone | 2023