# Simulate an embedded payment

> Sandbox only.

Source: https://docs.tappay.mn/reference/embedded-sessions/simulate/

[Sandbox](https://docs.tappay.mn/glossary.md#sandbox) only. Used by the checkout script to test the [customer](https://docs.tappay.mn/glossary.md#customer)'s [payment](https://docs.tappay.mn/glossary.md#payment) with a [test card](https://docs.tappay.mn/glossary.md#test-card) or a QR scan, without moving real money.

`POST /api/checkout/embedded/sessions/{id}/sandbox/simulate`

### Authentication

Publishable key + X-Client-Secret

### Headers

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `X-Client-Secret` | string | yes | | |

### Path parameters

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

### Request body

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `channel` | string | yes | `QPAY`, `NODE_QR`, `WECHAT`, `CARD`, `R2P` | |
| `outcome` | string | no | `SUCCEEDED`, `DECLINED`, `TIMEOUT` | |
| `card` | object | no | | |
| `card.pan` | string | yes | | |
| `card.expiry` | string | yes | | |
| `card.cvv` | string | yes | | |
| `consent` | boolean | no | | |

### Response 201

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

### Errors

| Code | Status | Message |
| - | - | - |
| [`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. |
| [`VAL-014`](https://docs.tappay.mn/errors.md#VAL-014) | 400 | The TapPay-Version header is not a known API version. |
| [`AUTH-001`](https://docs.tappay.mn/errors.md#AUTH-001) | 401 | The API key is missing, invalid or revoked. |
| [`AUTH-058`](https://docs.tappay.mn/errors.md#AUTH-058) | 403 | The API key does not have the scope this operation requires. |
| [`PAY-010`](https://docs.tappay.mn/errors.md#PAY-010) | 422 | The requested payment channel is not available for this payment. |
| [`PAY-033`](https://docs.tappay.mn/errors.md#PAY-033) | 409 | The checkout session is not open. |
| [`PAY-034`](https://docs.tappay.mn/errors.md#PAY-034) | 404 | The checkout session was not found, or the client secret does not match. |
| [`PAY-035`](https://docs.tappay.mn/errors.md#PAY-035) | 422 | The payer's consent is required for this payment. |
| [`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. |
| [`SET-002`](https://docs.tappay.mn/errors.md#SET-002) | 400 | A required platform setting is missing or unknown. |
| [`FSC-013`](https://docs.tappay.mn/errors.md#FSC-013) | 500 | The fee could not be calculated because the destination cannot be resolved. |
| [`EVT-201`](https://docs.tappay.mn/errors.md#EVT-201) | 403 | This operation is not available for the key environment: sandbox-only operations need a sandbox key, and the others need a production key. |
| [`EVT-202`](https://docs.tappay.mn/errors.md#EVT-202) | 422 | The test card number is not a known sandbox test card. |
| [`EVT-203`](https://docs.tappay.mn/errors.md#EVT-203) | 409 | The payment intent is not open, so it cannot be simulated. |
| [`EVT-205`](https://docs.tappay.mn/errors.md#EVT-205) | 422 | The channel is not available in the sandbox. |
| [`AFP-001`](https://docs.tappay.mn/errors.md#AFP-001) | 409 | The payment intent is locked by another operation. |
| [`PSP-003`](https://docs.tappay.mn/errors.md#PSP-003) | 422 | The provider terminal required for this payment is not configured. |
| [`PRE-005`](https://docs.tappay.mn/errors.md#PRE-005) | 409 | The payment is not a pre-authorization. |

Try it in the playground: https://docs.tappay.mn/reference/embedded-sessions/simulate/

*The SDKs do not cover this API (browser checkout script) — the example calls HTTP directly.*

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/checkout/embedded/sessions/SESSION_ID/sandbox/simulate" \
  -H "Authorization: Bearer pk_test_YOUR_PUBLISHABLE_KEY" \
  -H "X-Client-Secret: CLIENT_SECRET" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"channel":"CARD","card":{"pan":"4242424242424242","expiry":"12/30","cvv":"123"},"consent":true}'
```

```js title="Node.js"
const res = await fetch('https://api.tappay.mn/api/checkout/embedded/sessions/SESSION_ID/sandbox/simulate', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer pk_test_YOUR_PUBLISHABLE_KEY',
    'X-Client-Secret': 'CLIENT_SECRET',
    'TapPay-Version': '2026-09-27',
    'Idempotency-Key': crypto.randomUUID(),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    channel: 'CARD',
    card: {
      pan: '4242424242424242',
      expiry: '12/30',
      cvv: '123',
    },
    consent: true,
  }),
});
console.log(await res.text());
```

```php title="PHP"
<?php
$body = json_encode([
    'channel' => 'CARD',
    'card' => [
        'pan' => '4242424242424242',
        'expiry' => '12/30',
        'cvv' => '123',
    ],
    'consent' => true,
]);
$ch = curl_init('https://api.tappay.mn/api/checkout/embedded/sessions/SESSION_ID/sandbox/simulate');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer pk_test_YOUR_PUBLISHABLE_KEY',
        'X-Client-Secret: CLIENT_SECRET',
        'TapPay-Version: 2026-09-27',
        'Idempotency-Key: ' . bin2hex(random_bytes(16)),
        'Content-Type: application/json',
    ],
]);
echo curl_exec($ch);
```

```python title="Python"
import json, urllib.request, uuid

req = urllib.request.Request(
    'https://api.tappay.mn/api/checkout/embedded/sessions/SESSION_ID/sandbox/simulate',
    data=json.dumps({
        'channel': 'CARD',
        'card': {
            'pan': '4242424242424242',
            'expiry': '12/30',
            'cvv': '123',
        },
        'consent': True,
    }).encode(),
    method='POST',
    headers={
        'Authorization': 'Bearer pk_test_YOUR_PUBLISHABLE_KEY',
        'X-Client-Secret': 'CLIENT_SECRET',
        'TapPay-Version': '2026-09-27',
        'Idempotency-Key': str(uuid.uuid4()),
        'Content-Type': 'application/json',
    },
)
print(urllib.request.urlopen(req).read().decode())
```

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

> **Note:** **Test key only**
>
> Call the [simulator](https://docs.tappay.mn/glossary.md#simulator) with a test [publishable key](https://docs.tappay.mn/glossary.md#publishable-key). A live key on a [production](https://docs.tappay.mn/glossary.md#production) session is refused with `EVT-201`.

> **Note:** **One pre-auth payment**
>
> The session was created with `PREAUTH`, so this payment stays open for the [finalize](https://docs.tappay.mn/glossary.md#finalize) call. The saved card also gets the usage `RECURRING`.

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