# Take payments at a POS terminal

> Use a terminal key to show a QR code, scan a customer code, and manage the invoices of one terminal.

Source: https://docs.tappay.mn/guides/pos-terminal/

## Overview {#overview}

A [terminal](https://docs.tappay.mn/glossary.md#terminal) is a till or a device in one of your shops. It takes a [payment](https://docs.tappay.mn/glossary.md#payment) in two ways. In [MPM](https://docs.tappay.mn/glossary.md#mpm) the shop shows a QR code, and in [CPM](https://docs.tappay.mn/glossary.md#cpm) the shop scans the code on the phone of the [customer](https://docs.tappay.mn/glossary.md#customer).

## Before you begin {#before-you-begin}

Your key needs the `payments:write` [scope](https://docs.tappay.mn/glossary.md#scope). The best key for a till is a [terminal key](https://docs.tappay.mn/glossary.md#terminal-key), shown below as `sk_test_YOUR_TERMINAL_KEY`. It works for one terminal only, so you never send a `terminalId`. With your merchant [secret key](https://docs.tappay.mn/glossary.md#secret-key), `sk_test_YOUR_SECRET_KEY`, you send the `terminalId` yourself. Use [sandbox](https://docs.tappay.mn/glossary.md#sandbox) keys while you build.

## Steps {#steps}

### Create an invoice for the QR code {#create-an-invoice}

For MPM, create an [invoice](https://docs.tappay.mn/glossary.md#invoice) with the terminal key and show its QR code on the screen, as in the [QR payments guide](https://docs.tappay.mn/guides/qr-payments.md). The terminal comes from the key. Every call that creates something needs an `Idempotency-Key`. If your till retries after a timeout, send the same key again.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices" \
  -H "Authorization: Bearer sk_test_YOUR_TERMINAL_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"amount":1000,"description":"Order 1","orderId":"order-'"$(uuidgen)"'"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_TERMINAL_KEY' });
const invoice = await tappay.invoices.create({ body: { amount: 1000, description: 'Order 1', orderId: `order-${crypto.randomUUID()}` } });
console.log(JSON.stringify(invoice));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_TERMINAL_KEY']);
$invoice = $tappay->invoices->create([
    'body' => [
        'amount' => 1000,
        'description' => 'Order 1',
        'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
    ],
]);
echo json_encode($invoice);
```

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

client = tappay.TapPay("sk_test_YOUR_TERMINAL_KEY")
invoice = client.invoices.create({"body": {"amount": 1000, "description": "Order 1", "orderId": "order-" + str(uuid.uuid4()) + ""}})
print(json.dumps(invoice))
```

### Scan the code of the customer {#accept-customer-code}

For CPM, the customer opens the wallet app and shows a code. Your till reads it and sends it as `payload` with the `amount` and your `orderId`. TapPay answers with `202` and the status `ACCEPTED`, and the payment result follows. In the sandbox the payload decides the result. Use one of the test payloads below.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/cpm" \
  -H "Authorization: Bearer sk_test_YOUR_TERMINAL_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"payload":"hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SDU=","amount":1000,"description":"Order 2","orderId":"order-'"$(uuidgen)"'"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_TERMINAL_KEY' });
const result = await tappay.cpm.create({
  body: {
    payload: 'hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SDU=',
    amount: 1000,
    description: 'Order 2',
    orderId: `order-${crypto.randomUUID()}`,
  },
});
console.log(JSON.stringify(result));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_TERMINAL_KEY']);
$result = $tappay->cpm->create([
    'body' => [
        'payload' => 'hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SDU=',
        'amount' => 1000,
        'description' => 'Order 2',
        'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
    ],
]);
echo json_encode($result);
```

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

client = tappay.TapPay("sk_test_YOUR_TERMINAL_KEY")
result = client.cpm.create({
    "body": {
        "payload": "hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SDU=",
        "amount": 1000,
        "description": "Order 2",
        "orderId": "order-" + str(uuid.uuid4()) + "",
    },
})
print(json.dumps(result))
```

| Outcome | Payload |
| - | - |
| Payment succeeds | `hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SDU=` |
| Payment fails (payment.failed) | `hQVDUFYwMWEjTwfwVEFQUEFZUAZUQVBQQVljEN8BDU5LMDAwMDJUOVI2SjY=` |

> **Note:** **Test payloads**
>
> [Production](https://docs.tappay.mn/glossary.md#production) does not accept these payloads. A real customer code can be used only once, so do not retry a scan with the same code after it has been accepted.

### List the invoices of the terminal {#list-terminal-invoices}

List the invoices of the terminal, newest first, with `limit` and, if you need them, `status`, `merchantOrderId`, `from` and `to`. Continue with `cursor` while `hasMore` is true. A terminal key lists only its own terminal. A merchant-level key without a terminal limit passes `terminalId` as a query parameter, as below.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/invoices?terminalId=YOUR_TERMINAL_ID&limit=10" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27"
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const page = await tappay.invoices.list({ query: { terminalId: 'YOUR_TERMINAL_ID', limit: '10' } }).firstPage();
console.log(JSON.stringify(page));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$page = $tappay->invoices->list(['query' => ['terminalId' => 'YOUR_TERMINAL_ID', 'limit' => '10']])->firstPage();
echo json_encode(['data' => $page->data, 'hasMore' => $page->hasMore, 'nextCursor' => $page->nextCursor]);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
page = client.invoices.list({"terminalId": "YOUR_TERMINAL_ID", "limit": "10"}).first_page()
print(json.dumps({"data": page.data, "has_more": page.has_more, "next_cursor": page.next_cursor}))
```

### Read one invoice {#get-terminal-invoice}

Read an invoice to see its `status`, the `amountPaid` and its intents. Add `expand[]=payments` to include each payment with its `feeAmount` and `merchantNet`.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/invoices/INVOICE_ID" \
  -H "Authorization: Bearer sk_test_YOUR_TERMINAL_KEY" \
  -H "TapPay-Version: 2026-09-27"
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_TERMINAL_KEY' });
const invoice = await tappay.invoices.retrieve({ 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_TERMINAL_KEY']);
$invoice = $tappay->invoices->retrieve(['id' => 'INVOICE_ID']);
echo json_encode($invoice);
```

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

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

### Cancel an unpaid invoice {#cancel-terminal-invoice}

When the customer leaves, cancel the invoice. Its status becomes `CANCELLED`. A paid, expired or cancelled invoice cannot be cancelled, so make a [refund](https://docs.tappay.mn/glossary.md#refund) for a paid invoice, as in the [refunds guide](https://docs.tappay.mn/guides/refunds.md).

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices/INVOICE_ID/cancel" \
  -H "Authorization: Bearer sk_test_YOUR_TERMINAL_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_TERMINAL_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_TERMINAL_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_TERMINAL_KEY")
invoice = client.invoices.cancel({"id": "INVOICE_ID"})
print(json.dumps(invoice))
```

### Call the POS API {#call-the-pos-api}

The steps above use your merchant key on the [terminal](https://docs.tappay.mn/glossary.md#terminal). A POS partner calls the POS API with its own credential instead. In the SDK this is `PosClient`: it gets the token, signs each request and sends the `Idempotency-Key`. Do not trust the callback, and read the payment with `payments.retrieve`. See the [POS API reference](https://docs.tappay.mn/reference/pos/auth/token.md).

`narrative` becomes the bank statement text. Bank transfer descriptions are length-limited (Khan Bank: 35 characters) and start with the TapPay token. So only the first **21** characters are guaranteed to appear at every bank, and the rest is cut off. Send a short, unique text (for example `SB-1001 Counter 3`).

```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='{"pos_reference":"pos-'"$(uuidgen)"'","narrative":"Order #1001","amount":1000,"currency":"MNT","card_terminal":{"terminal_code":"T-SANDBOX-POS","merchant_code":"M-SANDBOX-POS"}}'
TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)
SIG=$(printf '%s\n%s\n%s\n%s' 'POST' '/api/pos/v1/qr' "$TS" "$BODY" | openssl dgst -sha256 -hmac 'YOUR_POS_SIGNING_SECRET' | sed 's/^.* //')
curl -sS -X POST "https://sandbox-api.tappay.mn/api/pos/v1/qr" \
  -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 payment = await pos.payments.createQr({
  body: {
    pos_reference: `pos-${crypto.randomUUID()}`,
    narrative: 'Order #1001',
    amount: 1000,
    currency: 'MNT',
    card_terminal: {
      terminal_code: 'T-SANDBOX-POS',
      merchant_code: 'M-SANDBOX-POS',
    },
  },
});
console.log(JSON.stringify(payment));
```

```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',
]);
$payment = $pos->payments->createQr([
    'body' => [
        'pos_reference' => 'pos-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
        'narrative' => 'Order #1001',
        'amount' => 1000,
        'currency' => 'MNT',
        'card_terminal' => [
            'terminal_code' => 'T-SANDBOX-POS',
            'merchant_code' => 'M-SANDBOX-POS',
        ],
    ],
]);
echo json_encode($payment);
```

```python title="Python"
import json
import uuid
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",
)
payment = pos.payments.create_qr({
    "body": {
        "pos_reference": "pos-" + str(uuid.uuid4()) + "",
        "narrative": "Order #1001",
        "amount": 1000,
        "currency": "MNT",
        "card_terminal": {
            "terminal_code": "T-SANDBOX-POS",
            "merchant_code": "M-SANDBOX-POS",
        },
    },
})
print(json.dumps(payment))
```

## Verify {#verify}

Read the invoice and check that the `status` is `PAID`, or handle the `payment.succeeded` [event](https://docs.tappay.mn/glossary.md#event) as in the [webhooks guide](https://docs.tappay.mn/guides/webhooks.md). An MPM invoice and a CPM scan both end in the same payment. A declined test payload sends `payment.failed`, and the invoice stays open for a new scan.

## Common mistakes {#common-mistakes}

- Using a merchant-level key without a `terminalId`. TapPay cannot tell which terminal takes the payment, so send it in the body or the query.
- Using the key of one terminal for another terminal. A terminal key sees only its own terminal, and TapPay rejects other terminals.
- Sending a new `Idempotency-Key` on every retry. Repeat the same request with the same key, so that the payment is created once.
- Sending the same `orderId` twice for one terminal. TapPay rejects the second invoice as a duplicate, even with a new `Idempotency-Key`.
- Sending a sandbox test payload in production, or a real customer code in the sandbox. Each environment has its own codes.
- Keeping a terminal key in a shared place. Store it on the till or on your server, and revoke it in the portal if it leaks.

## Next steps {#next-steps}

Show the QR code with the [QR payments guide](https://docs.tappay.mn/guides/qr-payments.md), and see each [channel](https://docs.tappay.mn/glossary.md#channel) in the [channels guide](https://docs.tappay.mn/guides/channels.md). Track [fulfillment](https://docs.tappay.mn/glossary.md#fulfillment) with the [fulfillment guide](https://docs.tappay.mn/guides/fulfillment.md). See every field in [Charge a customer-presented code](https://docs.tappay.mn/reference/cpm/create.md), [List invoices](https://docs.tappay.mn/reference/invoices/list.md), [Retrieve an invoice](https://docs.tappay.mn/reference/invoices/get.md) and [Cancel an invoice](https://docs.tappay.mn/reference/invoices/cancel.md).
