# Accept QR payments

> Create an invoice, show a QR code to your customer, and confirm the payment from your server.

Source: https://docs.tappay.mn/guides/qr-payments/

## Overview {#overview}

A QR [payment](https://docs.tappay.mn/glossary.md#payment) lets your [customer](https://docs.tappay.mn/glossary.md#customer) scan a code with a wallet or banking app. You create an [invoice](https://docs.tappay.mn/glossary.md#invoice) for the amount and show its QR code. TapPay tells you when the [payment](https://docs.tappay.mn/glossary.md#payment) succeeds.

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

Your key needs the `payments:write` [scope](https://docs.tappay.mn/glossary.md#scope), and you use your [secret key](https://docs.tappay.mn/glossary.md#secret-key), shown below as `sk_test_YOUR_SECRET_KEY`. Use a [sandbox](https://docs.tappay.mn/glossary.md#sandbox) key while you build, because sandbox payments move no money. You send no line items, so TapPay adds one line for the whole amount.

## Steps {#steps}

### Create the invoice {#create-the-invoice}

Send the `amount`, a `description` and your own `orderId`. With a merchant-level key the `terminalId` is required; with a [terminal](https://docs.tappay.mn/glossary.md#terminal)-level key it is not. The response has the `invoiceId`, the `intentId` of the first [payment intent](https://docs.tappay.mn/glossary.md#payment-intent) and a stable `deeplink` for the customer.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"terminalId":"YOUR_TERMINAL_ID","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_SECRET_KEY' });
const invoice = await tappay.invoices.create({
  body: {
    terminalId: 'YOUR_TERMINAL_ID',
    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_SECRET_KEY']);
$invoice = $tappay->invoices->create([
    'body' => [
        'terminalId' => 'YOUR_TERMINAL_ID',
        '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_SECRET_KEY")
invoice = client.invoices.create({
    "body": {
        "terminalId": "YOUR_TERMINAL_ID",
        "amount": 1000,
        "description": "Order 1",
        "orderId": "order-" + str(uuid.uuid4()) + "",
    },
})
print(json.dumps(invoice))
```

### Show the QR code {#show-the-qr-code}

Present the intent on the `NODE_QR` [channel](https://docs.tappay.mn/glossary.md#channel). The response has a `qrText` value, which you draw as a QR code on your screen or on paper. Use `QPAY` instead of `NODE_QR` to get a QPay QR code and bank app links.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/intents/INTENT_ID/present" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"channel":"NODE_QR"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const intent = await tappay.intents.present({ id: 'INTENT_ID', body: { channel: 'NODE_QR' } });
console.log(JSON.stringify(intent));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$intent = $tappay->intents->present(['id' => 'INTENT_ID', 'body' => ['channel' => 'NODE_QR']]);
echo json_encode($intent);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
intent = client.intents.present({"id": "INTENT_ID", "body": {"channel": "NODE_QR"}})
print(json.dumps(intent))
```

A [dynamic QR](https://docs.tappay.mn/glossary.md#dynamic-qr) code carries the amount and works for one payment. A [static QR](https://docs.tappay.mn/glossary.md#static-qr) code is printed, has no amount, and TapPay creates a new invoice each time a customer scans it.

### Pay in the sandbox {#pay-in-the-sandbox}

Let the [simulator](https://docs.tappay.mn/glossary.md#simulator) act as the customer who scans the code. It works only with a sandbox key. The `outcome` can be `SUCCEEDED`, `DECLINED` or `TIMEOUT`, and the response has the payment `id`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/sandbox/intents/INTENT_ID/simulate" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"channel":"QR","outcome":"SUCCEEDED"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.sandbox.simulateIntent({ id: 'INTENT_ID', body: { channel: 'QR', outcome: 'SUCCEEDED' } });
console.log(JSON.stringify(result));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->sandbox->simulateIntent(['id' => 'INTENT_ID', 'body' => ['channel' => 'QR', 'outcome' => 'SUCCEEDED']]);
echo json_encode($result);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.sandbox.simulate_intent({"id": "INTENT_ID", "body": {"channel": "QR", "outcome": "SUCCEEDED"}})
print(json.dumps(result))
```

### Confirm the payment {#confirm-the-payment}

Read the payment from your server and check that its `status` is `SUCCEEDED`. Mark the order as paid only after that, and never because the customer says the QR code was scanned.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/payments/PAYMENT_ID" \
  -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 payment = await tappay.payments.retrieve({ id: 'PAYMENT_ID' });
console.log(JSON.stringify(payment));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$payment = $tappay->payments->retrieve(['id' => 'PAYMENT_ID']);
echo json_encode($payment);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
payment = client.payments.retrieve({"id": "PAYMENT_ID"})
print(json.dumps(payment))
```

## Verify {#verify}

When the payment succeeds, TapPay sends the `payment.succeeded` [event](https://docs.tappay.mn/glossary.md#event) to your [webhook endpoint](https://docs.tappay.mn/glossary.md#webhook-endpoint). Handle it as described in the [webhooks guide](https://docs.tappay.mn/guides/webhooks.md#create-the-endpoint), then read the payment with the request above. The invoice `status` becomes `PAID`, and TapPay also sends `invoice.paid`.

## Common mistakes {#common-mistakes}

- Letting two customers pay the same dynamic QR code. The second payment gets the `OVERPAID` status, and TapPay [refunds](https://docs.tappay.mn/glossary.md#refund) it automatically, without a fee.
- Reusing a dynamic QR code. It is single use: after a payment its `qrStatus` is `USED`, so create a new intent for the next payment.
- Treating a static QR code like a dynamic one. Its code starts with `SQR`, has no amount, and each scan makes a new invoice.
- Marking an order as paid while the `status` is `PROCESSING`. Wait for `SUCCEEDED` or the `payment.succeeded` event.
- Sending the same `orderId` twice for one terminal. TapPay rejects the second invoice as a duplicate, even with a new `Idempotency-Key`.

## Next steps {#next-steps}

Listen for payments with the [webhooks guide](https://docs.tappay.mn/guides/webhooks.md). Break an order into lines with the [orders guide](https://docs.tappay.mn/guides/orders.md), and offer more ways to pay with the [channels guide](https://docs.tappay.mn/guides/channels.md). To show the amount on the [sticker](https://docs.tappay.mn/glossary.md#sticker) at your till, see the [stickers guide](https://docs.tappay.mn/guides/stickers.md). To accept QR payments without code, see [QR payments in the portal](https://docs.tappay.mn/no-code/qr.md). See every field in [Create an invoice](https://docs.tappay.mn/reference/invoices/create.md), [Present a payment intent](https://docs.tappay.mn/reference/intents/present.md) and [Retrieve a payment](https://docs.tappay.mn/reference/payments/get.md).
