# Cancel Payment

A payment with a **PENDING** status due to an **AUTHORIZE** transaction status can be canceled before it is completed if the payment is no longer required. Sending a cancel request will update the payment status to **CANCELLED**.

<Warning>
**3DS Payments**

Payments in a **PENDING** status due to 3DS authentication cannot be canceled. These payments are in a temporary state awaiting user authentication. The payment status will automatically update to either **FRAUD VERIFIED** or **CANCELLED** based on the outcome of the authentication process.
</Warning>

<Note>
**Alternative Payment Methods**

Alternative payment methods such as PIX also support payment cancellation with a PENDING status. Reach out to your technical account manager for more information.
</Note>

If you need a receipt for the canceled transaction, you can retrieve it after it has been created. To do this, use the [Retrieve Payment by ID](/reference/payments/retrieve-payment-by-id-v2) endpoint and check the `receipt_url` field in the `payment.transaction` object. See [The Payment Object](/reference/payments/the-payment-object) for `receipt`, `receipt_url`, and `receipt_language`.

To use this endpoint, you have to provide an `X-Idempotency-Key` in your request. Check the [Authentication](/reference/authentication#idempotency) page for more information.

**POST** `/payments/{payment_id}/transactions/{transaction_id}/cancel`

Base URL: `https://api-sandbox.whitelabel.com/v1`

Cancel Payment

## Authorization

- public-api-key (apiKey in header)
- private-secret-key (apiKey in header)
- X-Idempotency-Key (apiKey in header)

## Path parameters

- `payment_id` (string, required)
  The unique identifier of the payment (UUID, 36 chars).
- `transaction_id` (string, required)
  The unique identifier of the transaction (UUID, 36 chars).

## Body

Content type: `application/json`

- `description` (string)
  Description of the cancellation.(MAX 255; MIN 3)
- `reason` ("DUPLICATE" | "FRAUDULENT" | "REQUESTED_BY_CUSTOMER")
  Reason for the cancellation. Values can be `DUPLICATE`, `FRAUDULENT`, and `REQUESTED_BY_CUSTOMER`.
- `merchant_reference` (string, required)
  Identification of the payment transaction defined by the merchant (MAX 255; MIN 3).
- `response_additional_data` (object)
  Specifies additional data for required the transaction response
  - `receipt` (boolean)
    Indicates if a receipt is necessary for the transaction response
  - `receipt_language` ("ES" | "EN" | "PT")
    Indicates the language of the receipt to be generated
  - `transactions_history` (boolean)
    When true, includes the transactions history in the response
  - `raw_request` (boolean)
    When true, includes the provider raw request in the output
  - `raw_response` (boolean)
    When true, includes the provider raw response in the output

Example:

```json
{
  "description": "string",
  "reason": "DUPLICATE",
  "merchant_reference": "string",
  "response_additional_data": {
    "receipt": true,
    "receipt_language": "ES",
    "transactions_history": true,
    "raw_request": true,
    "raw_response": true
  }
}
```

## Responses

### 200

200

- `id` (string)
- `type` (string)
- `status` (string)
- `category` (string)
- `amount` (object)
  - `captured` (integer)
  - `currency` (string)
  - `currency_conversion` (any)
  - `refunded` (integer)
  - `value` (integer)
- `merchant_reference` (string)
- `created_at` (string)
- `updated_at` (string)
- `provider_data` (object)
  - `id` (string)
  - `transaction_id` (string)
  - `account_id` (string)
  - `status` (string)
  - `sub_status` (string)
  - `status_detail` (string)
  - `response_message` (any)
  - `response_code` (string)
  - `raw_request` (object)
    Obfuscated copy of the request WHITELABEL sent to the provider. Only returned for allowlisted organizations.
  - `raw_response` (object)
    - `message` (string)
  - `third_party_transaction_id` (any)
  - `third_party_account_id` (any)
  - `iso8583_response_code` (string)
  - `iso8583_response_message` (string)
- `connection_data` (object)
  - `id` (string)
  - `name` (string)
- `response_code` (string)
- `response_message` (string)
- `payment` (object)
  - `id` (string)
  - `account_id` (string)
  - `description` (string)
  - `country` (string)
  - `status` (string)
  - `sub_status` (string)
  - `merchant_order_id` (string)
  - `created_at` (string)
  - `updated_at` (string)
  - `amount` (object)
    - `captured` (integer)
    - `currency` (string)
    - `currency_conversion` (any)
    - `refunded` (integer)
    - `value` (integer)
  - `split_marketplace` (any[])
- `customer_payer` (any)
- `simplified_mode` (boolean)
- `receipt` (boolean)
- `receipt_url` (any)
- `receipt_language` (any)

Example:

```json
{
  "id": "438bea6c-9061-4416-b824-469c3c05868d",
  "type": "CANCEL",
  "status": "SUCCEEDED",
  "category": "CARD",
  "amount": {
    "captured": 0,
    "currency": "USD",
    "currency_conversion": null,
    "refunded": 0,
    "value": 30000
  },
  "merchant_reference": "",
  "created_at": "2024-06-06T14:03:08.384014Z",
  "updated_at": "2024-06-06T14:03:08.453617Z",
  "provider_data": {
    "id": "YUNO_TEST_PAYMENT_GW",
    "transaction_id": "",
    "account_id": "",
    "status": "SUCCEEDED",
    "sub_status": "",
    "status_detail": "SUCCEEDED",
    "response_message": null,
    "response_code": "SUCCEEDED",
    "raw_request": {},
    "raw_response": {
      "message": "provider response"
    },
    "third_party_transaction_id": null,
    "third_party_account_id": null,
    "iso8583_response_code": "00",
    "iso8583_response_message": "Approved or completed successfully"
  },
  "connection_data": {
    "id": "58cc35f4-faef-4107-8e09-d18d60121d38",
    "name": "Connection name"
  },
  "response_code": "SUCCEEDED",
  "response_message": "Transaction successful",
  "payment": {
    "id": "2d6f75c1-c4bc-4d2d-80ec-0af4d12c85da",
    "account_id": "",
    "description": "Test",
    "country": "US",
    "status": "CANCELED",
    "sub_status": "CANCELED",
    "merchant_order_id": "0000023",
    "created_at": "2024-06-06T14:01:34.286228Z",
    "updated_at": "2024-06-06T14:03:08.484781Z",
    "amount": {
      "captured": 0,
      "currency": "USD",
      "currency_conversion": null,
      "refunded": 0,
      "value": 30000
    },
    "split_marketplace": [
      null
    ]
  },
  "customer_payer": null,
  "simplified_mode": false,
  "receipt": false,
  "receipt_url": null,
  "receipt_language": null
}
```

### 400

400

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "INVALID_REQUEST",
  "messages": [
    "Invalid request"
  ]
}
```

### 401

401

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "INVALID_CREDENTIALS",
  "messages": [
    "Invalid credentials"
  ]
}
```

### 403

403

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "AUTHORIZATION_REQUIRED",
  "messages": [
    "The merchant has no authorization to use this API."
  ]
}
```