For the complete documentation index, see llms.txt. This page is also available as Markdown.

Revert a subscription

Use the revertSubscription method to roll a subscription back to the state it was in immediately before its last order (e.g. a renewal, upgrade, or extend). Revert restores the expiration date and product/quantity values captured in the pre-order snapshot, and records the reversal — along with the reason provided — in the subscription's history.

Request parameters

Parameter
Type / Description

sessionID

Required (string) Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes.

LicenceCode

Required (string) Unique, system-generated subscription identifier of the subscription to revert.

OrderReference

Required (string) The 2Checkout reference number of the order whose changes should be undone. Must be the last order placed on the subscription.

Reason

Required (string)

Free-text explanation for the revert. Recorded against the subscription's history alongside the revert event.

Revert restores the subscription to its pre-order snapshot:

  • Expiration date is reverted to the snapshot value.

  • Product, product name, and quantity are reverted to the snapshot values.

  • The renewal record created by the order is soft-deleted (its IdLicence/IdDetail values are negated), rather than physically removed.

  • A new history entry is written, capturing the before/after values and the Reason supplied.

If reverting a prolong-license action causes the expiration date to fall in the past, the expiration date will be left to the current value.

Revert only accepts subscriptions whose last change was order-driven (renewal, upgrade, extend, etc.). If the subscription was modified some other way after that order, for example, directly by a merchant user, the revert will fail.

Request sample

<?php

$vendorCode = 'YOUR_VENDOR_CODE';
$apiKey     = 'YOUR_API_KEY';
$date       = gmdate('Y-m-d H:i:s');
$hash       = hash_hmac('md5', strlen($vendorCode) . $vendorCode . strlen($date) . $date, $apiKey);

try {
    $client = new SoapClient(
        'https://secure.2checkout.com/soap/6.0/?wsdl',
        ['cache_wsdl' => WSDL_CACHE_NONE]
    );

    $sessionId = $client->login($vendorCode, $date, $hash);

    $result = $client->revertSubscription(
        $sessionId,
        'YOUR_LICENCE_CODE',    // LicenceCode — subscription reference
        'YOUR_ORDER_REFNO',     // OrderReference — public RefNo of the last order
        'Customer requested revert after accidental renewal' // Reason — mandatory free text
    );

    echo 'Revert successful: ' . var_export($result, true) . PHP_EOL;

} catch (SoapFault $e) {
    echo 'SoapFault: ' . $e->getMessage() . PHP_EOL;
}

Response parameters

Type
Description

Boolean

true or false depending on whether the changes were successful or not.

Error codes

Error code
Description

LICENCE_NOT_FOUND

The licence or order cannot be found.

NOT_LAST_ORDER

The provided order is not the last order on this subscription.

NO_SNAPSHOT

No snapshot exists for this subscription before the given order.

SUBSCRIPTION_MODIFIED_EXTERNALLY

The subscription was modified outside of an order after the last order and cannot be reverted.

SUBSEQUENT_CHANGES

The subscription was modified after this order. Revert is not allowed.

INVALID_ORDER

A valid OrderReference (order RefNo) is required.

MISSING_REASON

Reason for revert is required.

REVERT_FAILED

Revert transaction rolled back due to a database failure.

Last updated

Was this helpful?