Take payments at a POS terminal
Overview
A terminal is a till or a device in one of your shops. It takes a payment in two ways. In MPM the shop shows a QR code, and in CPM the shop scans the code on the phone of the customer.
Before you begin
Your key needs the payments:write scope. The best key for a till is a 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, sk_test_YOUR_SECRET_KEY, you send the terminalId yourself. Use sandbox keys while you build.
Steps
Create an invoice for the QR code
For MPM, create an invoice with the terminal key and show its QR code on the screen, as in the QR payments guide. 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.
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)"'"}'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
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);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
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.
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)"'"}'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
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);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= |
List the invoices of the terminal
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.
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"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
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]);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
Read an invoice to see its status, the amountPaid and its intents. Add expand[]=payments to include each payment with its feeAmount and merchantNet.
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"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
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);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
When the customer leaves, cancel the invoice. Its status becomes CANCELLED. A paid, expired or cancelled invoice cannot be cancelled, so make a refund for a paid invoice, as in the refunds guide.
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)"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
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);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
The steps above use your merchant key on the 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.
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).
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"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
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);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
Read the invoice and check that the status is PAID, or handle the payment.succeeded event as in the webhooks guide. 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
- 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-Keyon every retry. Repeat the same request with the same key, so that the payment is created once. - Sending the same
orderIdtwice for one terminal. TapPay rejects the second invoice as a duplicate, even with a newIdempotency-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
Show the QR code with the QR payments guide, and see each channel in the channels guide. Track fulfillment with the fulfillment guide. See every field in Charge a customer-presented code, List invoices, Retrieve an invoice and Cancel an invoice.