> For the complete documentation index, see [llms.txt](https://docs.2checkout.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.2checkout.com/soap-api-reference/soap-api-6.0/api-requests/subscription/revert-a-subscription.md).

# 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`      | <p><strong>Required (string)</strong><br>Session identifier, the output of the <strong>Login</strong> method. Include <code>sessionID</code> into all your requests. 2Checkout throws an exception if the values are incorrect. The <code>sessionID</code> expires in <strong>10 minutes</strong>.</p> |
| `LicenceCode`    | <p><strong>Required (string)</strong><br>Unique, system-generated subscription identifier of the subscription to revert.</p>                                                                                                                                                                           |
| `OrderReference` | <p><strong>Required (string)</strong><br>The 2Checkout reference number of the order whose changes should be undone. Must be the last order placed on the subscription.</p>                                                                                                                            |
| `Reason`         | <p><strong>Required (string)</strong></p><p>Free-text explanation for the revert. Recorded against the subscription's history alongside the revert event.</p>                                                                                                                                          |

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.

You cannot revert a subscription that has addon subscriptions linked to it.

### Request sample

```php
<?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

<table><thead><tr><th width="110.5333251953125">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Boolean</strong></td><td><strong>true</strong> or <strong>false</strong> depending on whether the changes were successful or not.</td></tr></tbody></table>

## 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.                                      |
| **ADDON\_REVERT\_NOT\_ALLOWED**        | Revert is not allowed for subscriptions with add-ons.                                          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.2checkout.com/soap-api-reference/soap-api-6.0/api-requests/subscription/revert-a-subscription.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
