# Simulate automatic finalization

> Sandbox only.

Source: https://docs.tappay.mn/reference/sandbox/auto-finalize-payment/

[Sandbox](https://docs.tappay.mn/glossary.md#sandbox) only. Runs the automatic finalization of a held [payment](https://docs.tappay.mn/glossary.md#payment), as TapPay does when the [finalize](https://docs.tappay.mn/glossary.md#finalize) period ends.

`POST /api/v1/sandbox/payments/{id}/auto-finalize` 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 | | |

### Response 200

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `success` | boolean | yes | `true` | |
| `data` | object | yes | | |
| `data.payment` | object | yes | | |
| `data.payment.id` | string (uuid) | yes | | |
| `data.payment.status` | string | yes | | |
| `data.payment.failureCode` | string \| null | no | | |

### 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. |
| [`PRE-005`](https://docs.tappay.mn/errors.md#PRE-005) | 409 | The payment is not a pre-authorization. |
| [`PRE-006`](https://docs.tappay.mn/errors.md#PRE-006) | 409 | The pre-authorization was already finalized. |
| [`PRE-007`](https://docs.tappay.mn/errors.md#PRE-007) | 409 | The pre-authorization has expired and can no longer be finalized. |
| [`PRE-008`](https://docs.tappay.mn/errors.md#PRE-008) | 422 | The finalize amount is not valid. |
| [`PRE-009`](https://docs.tappay.mn/errors.md#PRE-009) | 409 | A finalize for this pre-authorization is already in progress. |
| [`PRE-010`](https://docs.tappay.mn/errors.md#PRE-010) | 409 | The pre-authorization capture failed. |

Try it in the playground: https://docs.tappay.mn/reference/sandbox/auto-finalize-payment/

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/sandbox/payments/PAYMENT_ID/auto-finalize" \
  -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 result = await tappay.sandbox.autoFinalizePayment({ id: 'PAYMENT_ID' });
console.log(JSON.stringify(result));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->sandbox->autoFinalizePayment(['id' => 'PAYMENT_ID']);
echo json_encode($result);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.sandbox.auto_finalize_payment({"id": "PAYMENT_ID"})
print(json.dumps(result))
```

```json title="Response"
{
  "success": true,
  "data": {
    "payment": {
      "id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9e04",
      "status": "SUCCEEDED",
      "failureCode": null
    }
  }
}
```

> **Note:** **Open pre-auth only**
>
> The payment must still have the `preauthStatus` `OPEN`, or TapPay returns `PRE-006`. Create it with `authorizationType` `PREAUTH` and pay it in the sandbox first. A [production](https://docs.tappay.mn/glossary.md#production) key is refused with `EVT-201`.

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