> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sayabelipay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel a Pending Transaction

> POST /api/transaction/{ref}/cancel

Cancels a transaction that the customer has not paid yet.

SayaBeliPay cancels the payment with the payment processor first, so the customer's checkout page stops accepting payment, and only then marks the transaction `Cancelled`. If the customer has already paid, or is paying at that moment, nothing is cancelled and you get a `409` response instead (see below).

## Request

```bash theme={null}
curl -X POST https://sayabelipay.com/api/transaction/9B8FEEB60F9E3/cancel \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET"
```

| Path parameter | Notes |
| - | - |
| `ref` | The `transaction_id` of a transaction currently in `Pending` status. |

## Response

```json theme={null}
{
  "success": true,
  "data": {
    "transaction_id": "9B8FEEB60F9E3",
    "order_no": "ORDER-1234",
    "status": "Cancelled",
    "...": "..."
  }
}
```

A `Cancelled` transaction is final. The customer can no longer pay it.

## Errors

| HTTP status | Meaning | What to do |
| - | - | - |
| `404` | The transaction is not `Pending` (already `Success`, `Cancelled`, or another final state), or it doesn't exist. | Nothing to cancel. Check its status with [Transaction Details](https://docs.sayabelipay.com/api-reference/transaction-details.md). |
| `409` | The customer has already paid, or their bank is still processing the payment. Nothing was cancelled. | Don't cancel the order. Check the status again shortly: it will become `Success` (or fail on its own). |
| `502` | The payment processor could not be reached. Nothing was cancelled. | Safe to retry the same request. |

### Not eligible: `404`

```json theme={null}
{ "success": false, "message": "Pending transaction not found" }
```

### Already paid: `409`

```json theme={null}
{ "success": false, "message": "This payment has already been completed by the customer and cannot be cancelled." }
```

### Payment in progress: `409`

```json theme={null}
{ "success": false, "message": "The customer is completing this payment right now. Please check its status again shortly." }
```

### Processor unreachable: `502`

```json theme={null}
{ "success": false, "message": "Could not reach the payment provider to cancel this payment. Please try again." }
```


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