> For the complete index of the 402pay docs, see [llms.txt](https://developer.402pay.co/llms.txt).

# Cancel a payment

Stop a payment created through the API before any funds arrive.

`POST https://dash.402pay.co/api/v1/payments/{id}/cancel`

Works on a payment you created through the API that hasn't received funds. It becomes `failed` with `canceled_at` set, its timeline ends with a `failed` event whose `reason` is `canceled`, and any open checkout for it closes. You receive `payment.failed`.

Canceling twice returns the payment as it is, so a retry can't fail.

### Path

- `id` (string, required): The payment's ID, such as `pmt_QI02vLdJGd48hBbg`.

### Errors

- 404 `not_found` No payment with that ID belongs to your business.
- 403 `test_mode_unavailable` A test key can't cancel a payment on a live business, so use a live key.
- 409 `payment_not_cancelable` Funds have arrived, or the payment came from a link. Archive the link instead.
- 409 `payment_in_flight` A transfer for the payment is on its way.

Any request can also fail on its key or its body. See [errors](https://developer.402pay.co/api/errors.md).

Request, cURL:

```bash
curl -X POST "https://dash.402pay.co/api/v1/payments/pmt_cQL3ct8r16YeUw4l/cancel" \
  -H "Authorization: Bearer $PAY402_SECRET_KEY"
```

Request, Node.js:

```js
const response = await fetch("https://dash.402pay.co/api/v1/payments/pmt_cQL3ct8r16YeUw4l/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAY402_SECRET_KEY}`,
  },
});
const { data } = await response.json();
```

Request, Python:

```python
import os

import requests

response = requests.post(
    "https://dash.402pay.co/api/v1/payments/pmt_cQL3ct8r16YeUw4l/cancel",
    headers={
        "Authorization": f"Bearer {os.environ['PAY402_SECRET_KEY']}",
    },
)
data = response.json()["data"]
```

Response, 200 OK:

```json
{
  "data": {
    "id": "pmt_cQL3ct8r16YeUw4l",
    "kind": "payment",
    "status": "failed",
    "amount": 4900,
    "currency": "USD",
    "fee_payer": "business",
    "customer_fee": 0,
    "amount_received": 0,
    "reporting": {
      "currency": "USD",
      "amount": 4900,
      "fee": 0,
      "transaction_fee": 0,
      "customer_fee": 0,
      "net": 0
    },
    "fee_rate_bps": 0,
    "method": {
      "rail": "crypto",
      "asset": null,
      "network": null,
      "amount": null,
      "expected_amount": null,
      "overpaid_amount": null,
      "from_address": null,
      "tx_hash": null,
      "explorer_url": null
    },
    "settlement": {
      "destination": "wallet",
      "asset": "USDC",
      "network": "polygon",
      "amount": "0.00",
      "wallet_id": null,
      "address": null,
      "tx_hash": null,
      "explorer_url": null
    },
    "customer_id": null,
    "link_id": null,
    "url": "https://checkout.402pay.co/checkout/cd6dfqk65a",
    "reference": "order_1043",
    "metadata": {
      "order_id": "1043"
    },
    "success_url": "https://example.com/thanks",
    "cancel_url": "https://example.com/cart",
    "expires_at": "2026-09-27T21:23:16.653Z",
    "canceled_at": "2026-09-26T21:23:16.669Z",
    "checkout_id": null,
    "description": "Pro plan, monthly",
    "country": "",
    "failure_code": null,
    "failure_message": "The business canceled the payment.",
    "confirmed_at": null,
    "created_at": "2026-09-26T21:23:16.653Z",
    "updated_at": "2026-09-26T21:23:16.669Z",
    "events": [
      {
        "type": "created",
        "created_at": "2026-09-26T21:23:16.653Z",
        "data": null
      },
      {
        "type": "failed",
        "created_at": "2026-09-26T21:23:16.669Z",
        "data": {
          "reason": "canceled"
        }
      }
    ]
  }
}
```
