Cancel Subscription

This function allows merchant to cancel the Automated rebilling. When automated rebilling is set, the system automatically performs future rebill transactions.
To setup automated rebilling, the merchant needs to send information defining rebill amount and period when performing the initial transaction via a Sale request.

This is only available on items that have an initial trial period that has been defined in the initial transaction via Sale request.
If there is no initial period, the request will be rejected. Instant upgrade is only available for credit card transactions. Alternate payments are not supported.

Note: The codes in the range 0000-1004 cause the subscription to be canceled immediately. For other codes, we wait the end of the last paid period. This mean that, for a monthly subscription, if John Smith made the payment for March (typically on March 1st), his subscription will end after March 31st. If on the other hand the current date is March 5th, and the payment for March hasn’t arrived yet, then the subscription for March is canceled (the cancellation date is set to March 1st).


HTTP Method API URL API Version
POST{subscriptionID}/cancel >= 002

Accepted parameters

Field Type Max Length Required Description Version
cancelReason Integer 4 yes Only codes in the range 1000-1099 are allowed. See CancelReason for possible values >= 002

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 'CancelSubscription', once you create a new transaction passing this as parameter, 
    *   you need to set the mandatory data using the following method:
    *    setSubscriptionID()
    *    setCancelReason()

    $client = new GatewayClient();

    $transaction = $client->newTransaction('CancelSubscription', 'testMerchant', 'testPassword');

    $response = $transaction->send();

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

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

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

    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 subscriptionId = "111222...";

    let responseCancelSubscription = await gateway.cancelSubscription(subscriptionId, 1022);

    if (responseCancelSubscription.code == "000") {
        // Success
    var client = new GatewayClient(OriginatorConfig.ORIGINATOR_ID, OriginatorConfig.ORIGINATOR_PASSWORD);
    var cancelTransaction = client.NewSubscriptionCancelTransaction(subscriptionID);
    cancelTransaction.SetCancelReason(1022); // Mandatory!!!

    var cancelResponse = await cancelTransaction.Send();

    if (cancelResponse.IsSuccessfull())
        Console.WriteLine("Cancel is ok: " + cancelResponse.errorMessage);
        Console.WriteLine("Error while cancelling subscription: " + cancelResponse.errorMessage);


The body of the response is in JSON format.

The following fields are present in the response :

Name Type Description
errorCode String See API Response Codes
errorMessage String See API Response Codes
subscription Object The subscription object

© Payzone | 2023