Cancel a Subscription

Endpoints

HTTP Method API URL API Version
POST https://paiement.payzone.ma/subscription/{subscriptionId}/cancel >= 002

Call used to cancel a subscription with all the required data. The information for the cancellation are serialized in JSON format and are transmitted in the body of the request. The following fields are accepted/required:

The following request parameter is accepted (in query string):

Accepted parameters

Name Type Description Required API Version
cancelReason String(32) Reason code for the cancellation (see cancel codes list here) yes >= 002.60
apiVersion String(8) API version to be used (default 002.50) yes >= 002.50

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 API response code (see API Response Codes for possible values) >= 002
message String Human readable message associated with the code >= 002

Code samples

   
    use PayXpert\Connect2Pay\Connect2PayClient;

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

    $c2pClient = new Connect2PayClient($url, $originator, $password);

    $result = $c2pClient->cancelSubscription($subscriptionID, 
    Connect2PayClient::_SUBSCRIPTION_CANCEL_BANK_DENIAL);

    if ($result == "200") {
        echo "Subscription " . $subscriptionID . " cancelled succcessfully: "
             . $c2pClient->getClientErrorMessage() . "\n";
    } else {
        echo "Error cancelling subscription " . $subscriptionID . ": code " . $result . " with message: " .    
        $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");

    SubscriptionCancelRequest  request  = new SubscriptionCancelRequest();
    SubscriptionCancelResponse response = null;

    request.setCancelReason("example");
    request.setSubscription("example");

    try {

        response = c2p.cancelSubscription(request);
        System.out.println(response.getMessage());
        System.out.println(response.geCode());

    } catch (Exception e) {
        logger.error("Ooops, an error occurred preparing the payment: " + e.getMessage());
        // Handle the error...
    }
                      
   
    const paymentPage = require("payxpert")("123456", "GreatP4ssw0rd").connect2pay;

    // To make this request we need to know SubscriptionID from original transaction
    // also we need to set cancel reason

    const response = await paymentPage.cancelSubscription(subscriptionId, 1022);

    if (response) {
        console.log("Error code: " + response.code);
        console.log("Error message: " + response.message);
    } else {
        console.log("Error occured");
    }     
                        
   
    var client = new Connect2PayClient(OriginatorConfig.ORIGINATOR_ID, 
    OriginatorConfig.ORIGINATOR_PASSWORD);

    // To make this request we need to know SubscriptionID from original transaction
    // also we need to set cancel reason

    var requestCancel = client.NewRequestSubscriptionCancel(subscriptionID);
    requestCancel.SetReason(SubscriptionCancelCodes.DID_NOT_LIKE);
    var responseCancel = await requestCancel.Send();

    if (responseCancel.IsSuccessfull())
    {
        Console.WriteLine("Cancellation of subscription performed");
    } else {
        Console.WriteLine("Cancellation request failure: " + responseCancel.code + ": " 
        + responseCancel.message);
    }


© Payzone | 2023