# Simulate a terminal action

> Simulates what happens on the bank terminal in the sandbox, such as a QR or card payment.

Source: https://docs.tappay.mn/reference/pos/sandbox/simulate-terminal-request/

Simulates an action on the bank [terminal](https://docs.tappay.mn/glossary.md#terminal) in the [sandbox](https://docs.tappay.mn/glossary.md#sandbox): shown on screen, paid by QR, card approved or declined, or cancelled.

`POST /api/pos/v1/sandbox/terminal-requests/{id}/simulate`

### Authentication

Secret key (Bearer)

### Headers

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `X-TapPay-Request-Timestamp` | string | yes | | |
| `X-TapPay-Request-Signature` | string | yes | | |
| `Idempotency-Key` | string | yes | | |

### Path parameters

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `id` | string | yes | | |

### Request body

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `action` | string | yes | `DELIVERED`, `QR_PAY`, `CARD_APPROVED`, `CARD_DECLINED`, `TERMINAL_CANCEL` | |

### Response 200

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `id` | string | yes | | |
| `tid` | string | yes | | |
| `amount` | number | yes | | |
| `currency` | string | yes | | |
| `description` | string \| null | yes | | Text the bank sent for the terminal display (request \`description\`) |
| `narrative` | string \| null | yes | | Statement narrative TapPay builds: \<terminal narrative_name> \<token> (max 50); null when the intent has no token |
| `emvco_payload` | string \| null | yes | | |
| `status` | string | yes | `OPEN`, `DISPLAYED`, `PAID`, `CANCELLED`, `FAILED` | |
| `expires_at` | string | yes | | |
| `updated_at` | string | yes | | |
| `paid_method` | string \| null | yes | `QR`, `CARD`, `null` | |
| `card` | object \| null | yes | | |
| `merchant` | object | yes | | |
| `merchant.name` | string | yes | | |
| `merchant.register_no` | string \| null | yes | | |

### Errors

| Code | Status | Message |
| - | - | - |
| [`POS-002`](https://docs.tappay.mn/errors.md#POS-002) | 401 | The POS access token is missing, invalid or expired. |
| [`POS-003`](https://docs.tappay.mn/errors.md#POS-003) | 401 | The POS API key is invalid or revoked. |
| [`POS-004`](https://docs.tappay.mn/errors.md#POS-004) | 401 | The request timestamp is outside the allowed time window. |
| [`POS-005`](https://docs.tappay.mn/errors.md#POS-005) | 401 | The request signature is invalid. |
| [`POS-006`](https://docs.tappay.mn/errors.md#POS-006) | 401 | This request signature was already used. |
| [`AUTH-055`](https://docs.tappay.mn/errors.md#AUTH-055) | 403 | The caller's scope does not allow this operation. |
| [`POS-007`](https://docs.tappay.mn/errors.md#POS-007) | 401 | A client certificate is required for 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. |
| [`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. |
| [`POS-091`](https://docs.tappay.mn/errors.md#POS-091) | 403 | The terminal push flow is not enabled for this POS client. |
| [`POS-083`](https://docs.tappay.mn/errors.md#POS-083) | 404 | The terminal payment request was not found. |
| [`POS-084`](https://docs.tappay.mn/errors.md#POS-084) | 409 | The terminal payment request cannot change in its current state. |
| [`POS-085`](https://docs.tappay.mn/errors.md#POS-085) | 409 | The QR is locked by a wallet payment in progress; do not start the card payment. |
| [`POS-087`](https://docs.tappay.mn/errors.md#POS-087) | 409 | The terminal payment request is already paid. |
| [`POS-088`](https://docs.tappay.mn/errors.md#POS-088) | 409 | The terminal payment request is already closed. |

```bash title="curl"
TOKEN=$(curl -sS -X POST "https://sandbox-api.tappay.mn/api/pos/v1/auth/token" -H "Content-Type: application/json" -d '{"grant_type":"client_credentials","client_id":"YOUR_POS_CLIENT_ID","client_secret":"YOUR_POS_CLIENT_SECRET"}' | sed -E 's/.*"access_token":"([^"]+)".*/\1/')
BODY='{"action":"QR_PAY"}'
TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)
SIG=$(printf '%s\n%s\n%s\n%s' 'POST' '/api/pos/v1/sandbox/terminal-requests/REQUEST_ID/simulate' "$TS" "$BODY" | openssl dgst -sha256 -hmac 'YOUR_POS_SIGNING_SECRET' | sed 's/^.* //')
curl -sS -X POST "https://sandbox-api.tappay.mn/api/pos/v1/sandbox/terminal-requests/REQUEST_ID/simulate" \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-API-Key: YOUR_POS_API_KEY" \
  -H "X-TapPay-Request-Timestamp: $TS" \
  -H "X-TapPay-Request-Signature: sha256=$SIG" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d "$BODY"
```

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

const pos = new PosClient({
  clientId: 'YOUR_POS_CLIENT_ID',
  clientSecret: 'YOUR_POS_CLIENT_SECRET',
  apiKey: 'YOUR_POS_API_KEY',
  signingSecret: 'YOUR_POS_SIGNING_SECRET',
  environment: 'sandbox',
  baseUrl: 'https://sandbox-api.tappay.mn',
});
const result = await pos.sandbox.simulateTerminalRequest({ id: 'REQUEST_ID', body: { action: 'QR_PAY' } });
console.log(JSON.stringify(result));
```

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

use TapPay\Pos\PosClient;

$pos = new PosClient([
    'clientId' => 'YOUR_POS_CLIENT_ID',
    'clientSecret' => 'YOUR_POS_CLIENT_SECRET',
    'apiKey' => 'YOUR_POS_API_KEY',
    'signingSecret' => 'YOUR_POS_SIGNING_SECRET',
    'environment' => 'sandbox',
    'baseUrl' => 'https://sandbox-api.tappay.mn',
]);
$result = $pos->sandbox->simulateTerminalRequest(['id' => 'REQUEST_ID', 'body' => ['action' => 'QR_PAY']]);
echo json_encode($result);
```

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

pos = tappay.PosClient(
    client_id="YOUR_POS_CLIENT_ID",
    client_secret="YOUR_POS_CLIENT_SECRET",
    api_key="YOUR_POS_API_KEY",
    signing_secret="YOUR_POS_SIGNING_SECRET",
    environment="sandbox",
    base_url="https://sandbox-api.tappay.mn",
)
result = pos.sandbox.simulate_terminal_request({"id": "REQUEST_ID", "body": {"action": "QR_PAY"}})
print(json.dumps(result))
```

```json title="Response"
{
  "id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f0b",
  "tid": "TID00001",
  "amount": 18000,
  "currency": "MNT",
  "description": "Order A-1001",
  "narrative": "Sandbox Cafe TP7K2M9Q",
  "emvco_payload": "000201010212...6304ABCD",
  "status": "PAID",
  "expires_at": "2026-10-03T08:30:00.000Z",
  "updated_at": "2026-10-03T08:20:00.000Z",
  "paid_method": "QR",
  "card": null,
  "merchant": {
    "name": "Sandbox Cafe",
    "register_no": "5123456"
  }
}
```

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