# Cancel an invoice

> Cancels an invoice that nobody has paid yet, together with its open intents.

Source: https://docs.tappay.mn/reference/invoices/cancel/

Cancels an [invoice](https://docs.tappay.mn/glossary.md#invoice) that nobody has paid yet, together with its open intents. You cannot cancel an invoice that is already paid.

`POST /api/v1/invoices/{id}/cancel` Since 2026-09-27

### Authentication

Secret key (Bearer)

### Headers

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `TapPay-Version` | string | no | | |
| `TapPay-Timestamp` | string | no | | |
| `TapPay-Nonce` | string | no | | |
| `TapPay-Signature` | string | no | | |
| `Idempotency-Key` | string | yes | | |

### Path parameters

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `id` | string (uuid) | yes | | |

### Query parameters

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `terminalId` | string (uuid) | no | | |

### Response 201

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `success` | boolean | yes | `true` | |
| `data` | object | yes | | |
| `data.id` | string | yes | | |
| `data.orderId` | string | yes | | |
| `data.status` | string | yes | `OPEN`, `PARTIALLY_PAID`, `PAID`, `EXPIRED`, `CANCELLED` | |
| `data.amount` | number | yes | | |
| `data.amountPaid` | number | yes | | |
| `data.amountReserved` | number | yes | | |
| `data.partialMode` | string | yes | `NONE`, `AMOUNT`, `LINES` | |
| `data.merchantServiceId` | string \| null | yes | | |
| `data.currency` | string | yes | | |
| `data.description` | string \| null | yes | | |
| `data.allowedChannels` | array \| null | yes | | |
| `data.expiresAt` | string | yes | | |
| `data.paidAt` | string \| null | yes | | |
| `data.createdAt` | string | yes | | |
| `data.terminalId` | string | yes | | |
| `data.customer` | string \| null | yes | | |
| `data.intentIds` | array\<string> | yes | | |
| `data.lines` | array\<object> | yes | | |
| `data.lines[].seq` | integer | yes | | |
| `data.lines[].name` | string | yes | | |
| `data.lines[].quantity` | string | yes | | |
| `data.lines[].unitPrice` | string | yes | | |
| `data.lines[].totalAmount` | string | yes | | |
| `data.lines[].quantityPaid` | string | yes | | |
| `data.lines[].quantityReserved` | string | yes | | |
| `data.intents` | array\<object> | yes | | |
| `data.intents[].id` | string | yes | | |
| `data.intents[].amount` | number | yes | | |
| `data.intents[].status` | string | yes | `OPEN`, `PROCESSING`, `SUCCEEDED`, `EXPIRED`, `CANCELLED` | |
| `data.intents[].expiresAt` | string | yes | | |
| `data.intents[].serviceFee` | number \| null | yes | | |
| `data.intents[].total` | number | yes | | |
| `data.fulfillment` | object \| null | yes | | |
| `data.fulfillment.status` | string | yes | `PENDING`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED` | |
| `data.fulfillment.stage` | string \| null | yes | | |
| `data.fulfillment.message` | string \| null | yes | | |
| `data.fulfillment.updatedAt` | string (date-time) | yes | | |
| `data.ebarimtIssuer` | string \| null | yes | `MERCHANT`, `NONE`, `NODE`, `null` | |

### Errors

| Code | Status | Message |
| - | - | - |
| [`AUTH-001`](https://docs.tappay.mn/errors.md#AUTH-001) | 401 | The API key is missing, invalid or revoked. |
| [`EVT-206`](https://docs.tappay.mn/errors.md#EVT-206) | 401 | Production keys are not accepted in the sandbox. Use a sandbox key (sk_test\_/pk_test\_). |
| [`EVT-207`](https://docs.tappay.mn/errors.md#EVT-207) | 401 | Sandbox keys are not accepted in production. Use a production key (sk_live\_/pk_live\_). |
| [`AUTH-018`](https://docs.tappay.mn/errors.md#AUTH-018) | 403 | The request came from an IP address that is not on the key's allowlist. |
| [`AUTH-058`](https://docs.tappay.mn/errors.md#AUTH-058) | 403 | The API key does not have the scope this operation requires. |
| [`SIG-002`](https://docs.tappay.mn/errors.md#SIG-002) | 401 | The request timestamp is outside the allowed time window. |
| [`SIG-003`](https://docs.tappay.mn/errors.md#SIG-003) | 401 | The request signature is missing or does not match. |
| [`SIG-005`](https://docs.tappay.mn/errors.md#SIG-005) | 409 | This request nonce was already used. |
| [`VAL-014`](https://docs.tappay.mn/errors.md#VAL-014) | 400 | The TapPay-Version header is not a known API version. |
| [`BIZ-004`](https://docs.tappay.mn/errors.md#BIZ-004) | 403 | The terminal is not active. |
| [`BIZ-005`](https://docs.tappay.mn/errors.md#BIZ-005) | 403 | The merchant account is not in a state that allows this request. |
| [`VAL-002`](https://docs.tappay.mn/errors.md#VAL-002) | 400 | A required field or header is missing. |
| [`VAL-010`](https://docs.tappay.mn/errors.md#VAL-010) | 409 | This Idempotency-Key was already used with a different request body. |
| [`VAL-013`](https://docs.tappay.mn/errors.md#VAL-013) | 409 | A request with this Idempotency-Key is still being processed. |
| [`PAY-001`](https://docs.tappay.mn/errors.md#PAY-001) | 404 | The invoice was not found. |
| [`PAY-002`](https://docs.tappay.mn/errors.md#PAY-002) | 409 | The invoice has already been paid. |
| [`PAY-003`](https://docs.tappay.mn/errors.md#PAY-003) | 410 | The invoice has expired. |
| [`PAY-004`](https://docs.tappay.mn/errors.md#PAY-004) | 410 | The invoice was cancelled. |
| [`PRE-015`](https://docs.tappay.mn/errors.md#PRE-015) | 409 | The payment is authorized and waiting for capture, so it cannot be cancelled. |
| [`ORD-011`](https://docs.tappay.mn/errors.md#ORD-011) | 409 | The fulfillment of an order invoice is managed by the order. |

Try it in the playground: https://docs.tappay.mn/reference/invoices/cancel/

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices/INVOICE_ID/cancel" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)"
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.cancel({ id: 'INVOICE_ID' });
console.log(JSON.stringify(invoice));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->cancel(['id' => 'INVOICE_ID']);
echo json_encode($invoice);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.cancel({"id": "INVOICE_ID"})
print(json.dumps(invoice))
```

```json title="Response"
{
  "success": true,
  "data": {
    "id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9e01",
    "orderId": "order-1048",
    "status": "CANCELLED",
    "amount": 1000,
    "amountPaid": 0,
    "amountReserved": 0,
    "partialMode": "NONE",
    "merchantServiceId": null,
    "currency": "MNT",
    "description": "Order 1",
    "allowedChannels": null,
    "expiresAt": "2026-10-03T08:45:00.000Z",
    "paidAt": null,
    "createdAt": "2026-10-03T08:15:00.000Z",
    "terminalId": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9e05",
    "customer": null,
    "intentIds": [
      "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9e03"
    ],
    "lines": [],
    "intents": [
      {
        "id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9e03",
        "amount": 1000,
        "serviceFee": null,
        "total": 1000,
        "status": "CANCELLED",
        "expiresAt": "2026-10-03T08:45:00.000Z"
      }
    ],
    "fulfillment": null,
    "ebarimtIssuer": "MERCHANT"
  }
}
```

> **Warning:** **Only an unpaid invoice**
>
> A paid invoice returns `409` with `PAY-002`. An authorized [payment](https://docs.tappay.mn/glossary.md#payment) that waits for capture returns `409` with `PRE-015`.

For the full flow, read the [guide](https://docs.tappay.mn/guides/orders.md).
