# Cancel Payment


> Cancel a payment transaction that is still pending.

Canonical: https://docs.chiwapay.com/payment-cancel

`POST /payments/:id/cancel`

Cancel a transaction that is still `pending`.
The ShopeePay Partner SDK does not support cancellation.
When the request succeeds, the transaction status changes to `cancelled` and a `payment.cancelled` event is sent to webhooks.

The `POST /transactions/:id/cancel` alias is available with the same behavior.

## Status Rules

| Initial status | Result |
| --- | --- |
| `pending` | `cancelled` |
| `refund_processing` | `paid`, the refund process is cancelled. |
| `created`, `paid`, `expired`, `failed`, `cancelled`, `settled`, `refund_failed`, `refunded` | Cannot be cancelled. |

## Path Params

| Param | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | Transaction UUID or `reference_id`. |

## Request Example

```tsx
<ApiExample method="POST" path="/payments/f2b1d5b0-7b1f-4c5d-9c37-93f0c8f6a001/cancel" />
```

## Response

```json
{
  "payment": {
    "id": "f2b1d5b0-7b1f-4c5d-9c37-93f0c8f6a001",
    "reference_id": "PAY-LXAMPLE",
    "merchant_reference_id": "ORDER-1024",
    "payment_method_code": "qris",
    "currency": "IDR",
    "amount": 150000,
    "fee_amount": 1050,
    "net_amount": 150000,
    "total_amount": 151050,
    "status": "cancelled",
    "cancelled_at": "2026-05-19T10:05:00Z"
  }
}
```

## HTTP Error Codes

| HTTP | Code | Description |
| --- | --- | --- |
| `400` | `payment_cancel_failed` | Transaction cannot be cancelled from its current status. |
| `401` | `invalid_api_key` | Secret key is invalid. |
| `403` | `merchant_not_approved` | Merchant is not active yet. |
| `403` | `api_key_ip_not_allowed` | Request IP is not in the API key allowlist. |
| `404` | `not_found` | Transaction was not found. |
