> ## Documentation Index
> Fetch the complete documentation index at: https://adyen-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel

> Learn to cancel a payment that has not been captured.

You can cancel a payment before you capture it, in the following scenario: if the payment was made with a payment method that allows you to [capture](https://adyen-preview.mintlify.site/online-payments/capture) it separately from authorization. When you cancel the payment, the financial institution releases the funds back to the shopper's bank account.

## Requirements

| Requirement | Description |
| - | - |
| **Integration type** | An [online payments integration](https://adyen-preview.mintlify.site/online-payments/build-your-integration). |
| **[Customer Area roles](https://adyen-preview.mintlify.site/account/user-roles.md)** | Make sure that you have the following roles: **View Payments** **Merchant manage payments** |
| **[Webhooks](https://adyen-preview.mintlify.site/development-resources/webhooks.md)** | Listen for webhook messages with the following `eventCode` values: [**CANCELLATION**](https://adyen-preview.mintlify.site/development-resources/webhooks/webhook-types#transaction-events) **TECHNICAL\_CANCEL** |
| **Limitations** | After a payment has been captured, you can no longer cancel it. |

## Ways to cancel a payment

After you determine that a [payment has not been captured](https://adyen-preview.mintlify.site/account/manage-payments.md#look-up-payments), you can cancel it in the following using one of the following:

* [Customer Area](#cancel-ca)
* [Checkout API](#cancel-api)

## Cancel a payment using the Customer Area

To cancel a payment in your [Customer Area](https://ca-test.adyen.com/):

1. Go to **Transactions** > **Payments**.
2. Select the **PSP reference** of the payment that you want to cancel.\
   This opens the **Payment details** page.
3. Select **Manage payment** > **Cancel payment**. The **Cancel payment** button is available only if the payment has not been captured.
4. Enter the confirmation code.
5. Select **Cancel payment**.

## Cancel a payment using the Checkout API

You can cancel a payment with the following information:

* [Adyen's PSP reference](#with-psp): the `pspReference` from the **AUTHORISATION** webhook to cancel the payment.
* [Your payment reference](#cancel-without-psp): the `reference` that you included in the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) or [/sessions](https://docs.adyen.com/api-explorer/Checkout/latest/post/sessions) request for the original payment. You can do this up to 24 hours after authorization.

### Cancel with PSP reference

To cancel a payment that has been authorized but not captured yet:

1. Get the PSP reference of the authorized payment you want to cancel. You can get it from your transaction list in Customer Area or the [AUTHORISATION](https://docs.adyen.com/api-explorer/Webhooks/latest/post/AUTHORISATION) webhook for the payment.

2. Make a [/payments/\{paymentPspReference}/cancels](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/cancels) request including the following:

   | Parameter | Required | Description |
   | - | - | - |
   | `paymentPspReference` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | The PSP reference of the payment that you want to cancel. |
   | `merchantAccount` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | The name of your merchant account that is used to process the payment. |
   | `reference` | | Your reference for this cancel request. |

   If you do not know if the payment has been captured, use the [/payments/\{paymentPspReference}/reversals](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/reversals) endpoint instead.

   **Example request to cancel a payment with a PSP reference**

   #### curl

   ```bash theme={null}
   curl https://checkout-test.adyen.com/v72/payments/XB7XNCQ8HXSKGK82/cancels \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'Content-Type: application/json' \
   -d '{
       "reference": "YOUR_UNIQUE_REFERENCE",
       "merchantAccount": "ADYEN_MERCHANT_ACCOUNT"
   }'
   ```

   #### Java

   ```java theme={null}
   // Adyen Java API Library v39.3.0
   import com.adyen.Client;
   import com.adyen.enums.Environment;
   import com.adyen.model.checkout.*;
   import java.time.OffsetDateTime;
   import java.util.*;
   import com.adyen.model.RequestOptions;
   import com.adyen.service.checkout.*;

   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   Client client = new Client("ADYEN_API_KEY", Environment.TEST);

   // Create the request object(s)
   // Send the request
   ModificationsApi service = new ModificationsApi(client);
   PaymentCancelResponse response = service.cancelAuthorisedPaymentByPspReference("paymentPspReference", paymentCancelRequest, new RequestOptions().idempotencyKey("UUID"));
   ```

   #### PHP

   ```php theme={null}
   <?php
   // Adyen PHP API Library v28.2.0
   use Adyen\Client;
   use Adyen\Environment;
   use Adyen\Service\Checkout\ModificationsApi;

   $client = new Client();
   $client->setXApiKey("ADYEN_API_KEY");
   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   $client->setEnvironment(Environment::TEST);


   // Create the request object(s)
   $requestOptions['idempotencyKey'] = 'UUID';

   // Send the request
   $service = new ModificationsApi($client);
   $response = $service->cancelAuthorisedPaymentByPspReference('paymentPspReference', $paymentCancelRequest, $requestOptions);
   ```

   #### C\#

   ```cs theme={null}
   // Adyen .net API Library v32.1.1
   using Adyen;
   using Environment = Adyen.Model.Environment;
   using Adyen.Model;
   using Adyen.Model.Checkout;
   using Adyen.Service.Checkout;

   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   var config = new Config()
   {
       XApiKey = "ADYEN_API_KEY",
       Environment = Environment.Test
   };
   var client = new Client(config);

   // Create the request object(s)
   // Send the request
   var service = new ModificationsService(client);
   var response = service.CancelAuthorisedPaymentByPspReference("paymentPspReference", paymentCancelRequest, requestOptions: new RequestOptions { IdempotencyKey = "UUID"});
   ```

   #### NodeJS (JavaScript)

   ```js theme={null}
   // Adyen Node API Library v29.0.0
   const { Client, CheckoutAPI } = require('@adyen/api-library');

   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   const config = new Config({
     apiKey: "ADYEN_API_KEY",
     environment: EnvironmentEnum.TEST
   });

   const client = new Client(config);

   // Create the request object(s)
   const paymentCancelRequest = {
     reference: "YOUR_UNIQUE_REFERENCE",
     merchantAccount: "ADYEN_MERCHANT_ACCOUNT"
   }

   // Send the request
   const checkoutAPI = new CheckoutAPI(client);
   const response = checkoutAPI.ModificationsApi.cancelAuthorisedPaymentByPspReference("paymentPspReference", paymentCancelRequest, { idempotencyKey: "UUID" });
   ```

   #### Go

   ```go theme={null}
   // Adyen Go API Library v21.0.0
   import (
     "context"
     "github.com/adyen/adyen-go-api-library/v21/src/common"
     "github.com/adyen/adyen-go-api-library/v21/src/adyen"
     "github.com/adyen/adyen-go-api-library/v21/src/checkout"
   )
   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   client := adyen.NewClient(&common.Config{
     ApiKey:      "ADYEN_API_KEY",
     Environment: common.TestEnv,
   })

   // Create the request object(s)
   // Send the request
   service := client.Checkout()
   req := service.ModificationsApi.CancelAuthorisedPaymentByPspReferenceInput("paymentPspReference").IdempotencyKey("UUID").PaymentCancelRequest(paymentCancelRequest)
   res, httpRes, err := service.ModificationsApi.CancelAuthorisedPaymentByPspReference(context.Background(), req)
   ```

   #### Python

   ```py theme={null}
   # Adyen Python API Library v13.6.0
   import Adyen

   adyen = Adyen.Adyen()
   adyen.client.xapikey = "ADYEN_API_KEY"
   # For the LIVE environment, also include your liveEndpointUrlPrefix.
   adyen.client.platform = "test" # The environment to use library in.

   # Create the request object(s)
   json_request = {
     "reference": "YOUR_UNIQUE_REFERENCE",
     "merchantAccount": "ADYEN_MERCHANT_ACCOUNT"
   }

   # Send the request
   result = adyen.checkout.modifications_api.cancel_authorised_payment_by_psp_reference(request=json_request, paymentPspReference="paymentPspReference", idempotency_key="UUID")
   ```

   #### Ruby

   ```rb theme={null}
   # Adyen Ruby API Library v10.4.0
   require "adyen-ruby-api-library"

   adyen = Adyen::Client.new
   adyen.api_key = 'ADYEN_API_KEY'
   # For the LIVE environment, also include your liveEndpointUrlPrefix.
   adyen.env = :test # Set to "live" for live environment

   # Create the request object(s)
   request_body = {
     :reference => 'YOUR_UNIQUE_REFERENCE',
     :merchantAccount => 'ADYEN_MERCHANT_ACCOUNT'
   }

   # Send the request
   result = adyen.checkout.modifications_api.cancel_authorised_payment_by_psp_reference(request_body, 'paymentPspReference', headers: { 'Idempotency-Key' => 'UUID' })
   ```

   #### NodeJS (TypeScript)

   ```ts theme={null}
   // Adyen Node API Library v29.0.0
   import { Client, CheckoutAPI, Types } from "@adyen/api-library";

   // For the LIVE environment, also include your liveEndpointUrlPrefix.
   const config = new Config({
     apiKey: "ADYEN_API_KEY",
     environment: EnvironmentEnum.TEST
   });

   const client = new Client(config);

   // Create the request object(s)
   // Send the request
   const checkoutAPI = new CheckoutAPI(client);
   const response = checkoutAPI.ModificationsApi.cancelAuthorisedPaymentByPspReference("paymentPspReference", paymentCancelRequest, { idempotencyKey: "UUID" });
   ```

   The response includes the following:

   | Parameter | Description |
   | - | - |
   | `paymentPspReference` | The PSP reference of the payment you want to cancel. |
   | `pspReference` | The unique reference for this request to cancel the payment. |

   **Example response to cancel a payment with a PSP reference**

   ```json theme={null}
   {
      "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
      "paymentPspReference": "XB7XNCQ8HXSKGK82",
      "pspReference" : "JDD6LKT8MBLZNN84",
      "reference": "YOUR_UNIQUE_REFERENCE",
      "status" : "received"
   }
   ```

3. Get the outcome of the cancellation request in the [**CANCELLATION** webhook](#cancellation-webhook).

### Cancel with your reference

Canceling a payment using your reference is possible up to 24 hours after authorization.

We recommend that you only cancel using the `reference` if you generate a *unique* references for each payment request and do not have the `pspReference` available.

1. Make a [/cancels](https://docs.adyen.com/api-explorer/Checkout/latest/post/cancels) request including the following:

   | Parameter | Required | Description |
   | - | - | - |
   | `paymentReference` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | Your reference for the payment that you want to cancel. This is the `reference` that you included in the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) or [/sessions](https://docs.adyen.com/api-explorer/Checkout/latest/post/sessions) request for the original the payment. |
   | `merchantAccount` | ![-white\_check\_mark-](https://docs.adyen.com/user/data/smileys/emoji/white_check_mark.png) | The name of your merchant account that is used to process the payment. |
   | `reference` | | Your reference for this cancel request. |

   **Example request to cancel a payment with your reference for the original payment**

   ```bash theme={null}
   curl https://checkout-test.adyen.com/v71/cancels \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'Content-Type: application/json' \
   -d '{
       "paymentReference": "yourPaymentReference123",
       "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
       "reference": "yourCancelRequestReference123"
   }'
   ```

   The response includes the following:

   | Parameter | Description |
   | - | - |
   | `paymentReference` | Your reference for the payment you want to cancel. |
   | `pspReference` | The unique reference for this request to cancel the payment. |

   **Example response to cancel a payment with your reference for the original payment**

   ```json theme={null}
   {
    "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
    "paymentReference": "yourPaymentReference123",
    "pspReference" : "XB7XNCQ8HXSKGK82",
    "reference": "yourCancelRequestReference123",
    "status" : "received"
   }
   ```

2. Get the outcome of the cancellation request in the [**TECHNICAL\_CANCEL** webhook](#cancellation-webhook).

## Webhooks for cancellations

The webhook that you get depends on if you made the cancel request [with the PSP reference](#cancellation-webhook) or with [your own reference](#technical-cancel-webhook).

### CANCELLATION webhook

If you made the cancel request with the PSP reference, you get the outcome of the cancel request in the **CANCELLATION** webhook. It contains the following:

* `eventCode`: **CANCELLATION**.

* `originalReference`: the PSP reference for the payment that you requested to cancel.

* `pspReference`: the PSP reference for the cancel request. same as the `pspReference` in the [/payments/\{paymentPspReference}/cancels](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/cancels) response.

* `success`: indicates whether the cancel request was successful. Possible values:

  * **true**: the cancel request was successful.
  * **false**: the cancel request failed. The webhook event includes a `reason` field with a short description of the problem. Review the reason, fix the issue if possible, and resubmit the cancel request.

> [tab] success: true
>
> **Example CANCELLATION webhook for a successful cancellation**
>
> ```json theme={null}
> {
>    "live":"false",
>    "notificationItems":[
>       {
>          "NotificationRequestItem":{
>             "amount":{
>                "currency":"EUR",
>                "value":500
>             },
>             "eventCode":"CANCELLATION",
>             "eventDate":"2021-03-05T09:08:05+01:00",
>             "merchantAccountCode":"ADYEN_MERCHANT_ACCOUNT",
>             "originalReference":"XB7XNCQ8HXSKGK82",
>             "paymentMethod":"mc",
>             "pspReference":"JDD6LKT8MBLZNN84",
>             "reason":"",
>             "success":"true"
>          }
>       }
>    ]
> }
> ```

> [tab] success: false
>
> **Example CANCELLATION webhook for a failed cancellation**
>
> ```json theme={null}
> {
>    "live":"false",
>    "notificationItems":[
>       {
>          "NotificationRequestItem":{
>             "amount":{
>                "currency":"EUR",
>                "value":500
>             },
>             "eventCode":"CANCELLATION",
>             "eventDate":"2021-03-05T09:08:05+01:00",
>             "merchantAccountCode":"ADYEN_MERCHANT_ACCOUNT",
>             "originalReference":"XB7XNCQ8HXSKGK82",
>             "paymentMethod":"mc",
>             "pspReference":"JDD6LKT8MBLZNN84",
>             "reason":"Transaction not found",
>             "success":"false"
>          }
>       }
>    ]
> }
> ```
>
> #### Reasons for an unsuccessful cancel request
>
> When a cancel request fails, you receive a **CANCELLATION** webhook with `success`: **false** and the `reason` for the failure. The table below shows the most common reasons:
>
> | Reason | Description |
> | - | - |
> | **Insufficient balance on payment** | There is not enough remaining balance on your payment to process the cancel. **Note:** The *balance on the payment* refers to the amount that remains from the original payment. For example, if a transaction has a total of EUR 10 and no refund or chargeback is processed, the balance on the payment is EUR 10. After a refund or chargeback of EUR 3 is processed, the remaining balance on the payment is EUR 7. This transaction-specific balance is independent of, and not to be confused with, your [merchant or company account balances](https://adyen-preview.mintlify.site/account/balances). Check the payment status in your Customer Area. |
> | **Transaction not found** | The cancel failed because: The `paymentReference` is missing or incorrect. You provided an incorrect `merchantAccount`.Check that the `paymentReference` you provided is correct and linked to the right account. |
> | **Transaction is expired** | The authorization for this payment has expired. You can no longer cancel it. |
> | **Operation not available** | The cancel operation is not available for this payment. |
>
> For more information about the included fields, see the [CANCELLATION](https://docs.adyen.com/api-explorer/Webhooks/latest/post/CANCELLATION) webhook reference.
>
> ### TECHNICAL\_CANCEL webhook
>
> If you made the cancel request with your reference, you get the outcome of the request in the **TECHNICAL\_CANCEL** webhook. It contains the following:
>
> * `eventCode`: **TECHNICAL\_CANCEL**
> * `pspReference`: The PSP reference for the cancel request. This is the same as the `pspReference`from the  [/cancels](https://docs.adyen.com/api-explorer/Checkout/latest/post/cancels) response. 
> * `originalReference`: The PSP reference for the payment that you requested to cancel.
> * `success`: Indicates whether the cancel request was successful. 
>
> **Example TECHNICAL\_CANCEL webhook for a successful cancellation**
>
> ```json theme={null}
> {
>    "live":"false",
>    "notificationItems":[
>       {
>          "NotificationRequestItem":{
>             "additionalData":{
>                "paymentMethodVariant":"visa"
>             },
>             "amount":{
>                "currency":"EUR",
>                "value":5000
>             },
>             "eventCode":"TECHNICAL_CANCEL",
>             "eventDate":"2021-07-18T22:35:14+02:00",
>             "merchantAccountCode":"ADYEN_MERCHANT_ACCOUNT",
>             "merchantReference":"yourPaymentReference123",
>             "originalReference":"XB7XNCQ8HXSKGK82",
>             "paymentMethod":"visa",
>             "pspReference":"JDD6LKT8MBLZNN84",
>             "reason":"",
>             "success":"true"
>          }
>       }
>    ]
> }
> ```
>
> For more information about the included fields, see the [TECHNICAL\_CANCEL](https://docs.adyen.com/api-explorer/Webhooks/latest/post/TECHNICAL_CANCEL) webhook reference.
>
> ## See also
>
> * [Manage payments in your Customer Account](https://adyen-preview.mintlify.site/account/manage-payments.md)
> * [Payments lifecycle](https://adyen-preview.mintlify.site/account/payments-lifecycle.md)
> * [Captures](https://adyen-preview.mintlify.site/online-payments/capture)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.