# Sandbox терминалын хүсэлт үүсгэх

> Sandbox-д мерчант илгээсэн мэт терминалын төлбөрийн хүсэлт үүсгэнэ.

Эх: https://docs.tappay.mn/mn/reference/pos/sandbox/create-terminal-request/

[Sandbox](https://docs.tappay.mn/mn/glossary.md#sandbox)-д мерчант таны банкны [терминал](https://docs.tappay.mn/mn/glossary.md#terminal) руу илгээсэн мэт [төлбөрийн](https://docs.tappay.mn/mn/glossary.md#payment) хүсэлт үүсгэнэ. Эхлээд терминалыг `PUT /bank-terminals`-ээр синк хийнэ.

`POST /api/pos/v1/sandbox/terminal-requests`

### Нэвтрэлт

Secret key (Bearer)

### Header

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `X-TapPay-Request-Timestamp` | string | тийм | | |
| `X-TapPay-Request-Signature` | string | тийм | | |
| `Idempotency-Key` | string | тийм | | |

### Хүсэлтийн бие

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `tid` | string | тийм | | |
| `amount` | number | тийм | | |
| `description` | string | үгүй | | |

### Хариу 201

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `id` | string | тийм | | |
| `tid` | string | тийм | | |
| `amount` | number | тийм | | |
| `currency` | string | тийм | | |
| `description` | string \| null | тийм | | Text the bank sent for the terminal display (request \`description\`) |
| `narrative` | string \| null | тийм | | Statement narrative TapPay builds: \<terminal narrative_name> \<token> (max 50); null when the intent has no token |
| `emvco_payload` | string \| null | тийм | | |
| `status` | string | тийм | `OPEN`, `DISPLAYED`, `PAID`, `CANCELLED`, `FAILED` | |
| `expires_at` | string | тийм | | |
| `updated_at` | string | тийм | | |
| `paid_method` | string \| null | тийм | `QR`, `CARD`, `null` | |
| `card` | object \| null | тийм | | |
| `merchant` | object | тийм | | |
| `merchant.name` | string | тийм | | |
| `merchant.register_no` | string \| null | тийм | | |

### Алдаа

| Код | Status | Мессеж |
| - | - | - |
| [`POS-002`](https://docs.tappay.mn/mn/errors.md#POS-002) | 401 | POS access token байхгүй, буруу эсвэл хугацаа нь дууссан байна. |
| [`POS-003`](https://docs.tappay.mn/mn/errors.md#POS-003) | 401 | POS API key буруу эсвэл хүчингүй болгосон байна. |
| [`POS-004`](https://docs.tappay.mn/mn/errors.md#POS-004) | 401 | Хүсэлтийн цагийн тэмдэг зөвшөөрөгдсөн хугацааны цонхоос гадуур байна. |
| [`POS-005`](https://docs.tappay.mn/mn/errors.md#POS-005) | 401 | Хүсэлтийн гарын үсэг буруу байна. |
| [`POS-006`](https://docs.tappay.mn/mn/errors.md#POS-006) | 401 | Энэ хүсэлтийн гарын үсэг өмнө нь ашиглагдсан байна. |
| [`AUTH-055`](https://docs.tappay.mn/mn/errors.md#AUTH-055) | 403 | Дуудагчийн хүрээ (scope) энэ үйлдлийг зөвшөөрөхгүй байна. |
| [`POS-007`](https://docs.tappay.mn/mn/errors.md#POS-007) | 401 | Энэ хүсэлтэд клиентийн сертификат шаардлагатай. |
| [`VAL-002`](https://docs.tappay.mn/mn/errors.md#VAL-002) | 400 | Заавал байх талбар эсвэл header дутуу байна. |
| [`VAL-010`](https://docs.tappay.mn/mn/errors.md#VAL-010) | 409 | Энэ Idempotency-Key өөр хүсэлтийн биетэй өмнө нь ашиглагдсан байна. |
| [`VAL-013`](https://docs.tappay.mn/mn/errors.md#VAL-013) | 409 | Энэ Idempotency-Key-тэй хүсэлт боловсруулагдаж байна. |
| [`EVT-201`](https://docs.tappay.mn/mn/errors.md#EVT-201) | 403 | Энэ үйлдэл key-ийн орчинд боломжгүй: sandbox-ийн үйлдэлд sandbox key, бусад үйлдэлд production key хэрэгтэй. |
| [`POS-091`](https://docs.tappay.mn/mn/errors.md#POS-091) | 403 | Энэ POS client-д терминал push урсгал асаагүй байна. |
| [`POS-080`](https://docs.tappay.mn/mn/errors.md#POS-080) | 404 | Банкны терминал олдсонгүй. |
| [`POS-081`](https://docs.tappay.mn/mn/errors.md#POS-081) | 422 | Банкны терминалын холболт идэвхгүй байна. |
| [`POS-082`](https://docs.tappay.mn/mn/errors.md#POS-082) | 409 | Терминал дээр нээлттэй төлбөрийн хүсэлт байна. |
| [`POS-093`](https://docs.tappay.mn/mn/errors.md#POS-093) | 422 | POS машиныг холбох терминал эсвэл касс олдсонгүй, эсвэл идэвхгүй байна. Идэвхтэй терминал сонгоно уу. |

```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='{"tid":"TID00001","amount":18000,"description":"Order A-1001"}'
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' "$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" \
  -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.createTerminalRequest({ body: { tid: 'TID00001', amount: 18000, description: 'Order A-1001' } });
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->createTerminalRequest(['body' => ['tid' => 'TID00001', 'amount' => 18000, 'description' => 'Order A-1001']]);
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.create_terminal_request({"body": {"tid": "TID00001", "amount": 18000, "description": "Order A-1001"}})
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": "OPEN",
  "expires_at": "2026-10-03T08:30:00.000Z",
  "updated_at": "2026-10-03T08:15:00.000Z",
  "paid_method": null,
  "card": null,
  "merchant": {
    "name": "Sandbox Cafe",
    "register_no": "5123456"
  }
}
```

Бүтэн урсгалыг [POS-ын гарын авлагаас](https://docs.tappay.mn/mn/guides/pos-terminal.md) үзнэ үү.
