Create orders with line items
Overview
An order is an invoice with order lines, such as items in a basket. You decide whether a customer pays the whole order, any amount or chosen lines. TapPay tracks what is paid and what is still open.
Before you begin
Your key needs the orders:write scope, and you use your secret key, shown below as sk_test_YOUR_SECRET_KEY. Use a sandbox key while you build, because sandbox payments move no money. A key with payments:write or checkout:write can also create invoices.
Steps
Create the order
Send lines, each with a name, quantity, unitPrice and totalAmount, and make the line totals add up to the amount. Set partialMode to NONE, AMOUNT or LINES to choose how customers may pay. The ebarimt object sets who issues the tax receipt for this order: NODE, MERCHANT or NONE. With LINES or AMOUNT no intent exists yet, so intentId is null.
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":10000,"description":"Order 1","orderId":"order-'"$(uuidgen)"'","partialMode":"LINES","lines":[{"name":"Coffee","quantity":"2","unitPrice":"3000","totalAmount":"6000"},{"name":"Cake","quantity":"1","unitPrice":"4000","totalAmount":"4000"}],"ebarimt":{"issuer":"NONE"}}'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: 10000,
description: 'Order 1',
orderId: `order-${crypto.randomUUID()}`,
partialMode: 'LINES',
lines: [
{
name: 'Coffee',
quantity: '2',
unitPrice: '3000',
totalAmount: '6000',
},
{
name: 'Cake',
quantity: '1',
unitPrice: '4000',
totalAmount: '4000',
},
],
ebarimt: {
issuer: 'NONE',
},
},
});
console.log(JSON.stringify(invoice));<?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' => 10000,
'description' => 'Order 1',
'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
'partialMode' => 'LINES',
'lines' => [
[
'name' => 'Coffee',
'quantity' => '2',
'unitPrice' => '3000',
'totalAmount' => '6000',
],
[
'name' => 'Cake',
'quantity' => '1',
'unitPrice' => '4000',
'totalAmount' => '4000',
],
],
'ebarimt' => [
'issuer' => 'NONE',
],
],
]);
echo json_encode($invoice);import json
import uuid
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.create({
"body": {
"terminalId": "YOUR_TERMINAL_ID",
"amount": 10000,
"description": "Order 1",
"orderId": "order-" + str(uuid.uuid4()) + "",
"partialMode": "LINES",
"lines": [
{
"name": "Coffee",
"quantity": "2",
"unitPrice": "3000",
"totalAmount": "6000",
},
{
"name": "Cake",
"quantity": "1",
"unitPrice": "4000",
"totalAmount": "4000",
},
],
"ebarimt": {
"issuer": "NONE",
},
},
})
print(json.dumps(invoice))Create a payment intent for lines
A payment intent is one share of the invoice that a customer pays on a channel, such as a QR code. In LINES mode, send the invoiceLineId and the quantity to pay. The invoiceLineId is the line number, starting at 1, and TapPay works out the amount. In AMOUNT mode, send an amount instead.
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices/INVOICE_ID/intents" \
-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 '{"lines":[{"invoiceLineId":1,"quantity":"2"}]}'import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.createIntent({ id: 'INVOICE_ID', body: { lines: [{ invoiceLineId: 1, quantity: '2' }] } });
console.log(JSON.stringify(invoice));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->createIntent(['id' => 'INVOICE_ID', 'body' => ['lines' => [['invoiceLineId' => 1, 'quantity' => '2']]]]);
echo json_encode($invoice);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.create_intent({"id": "INVOICE_ID", "body": {"lines": [{"invoiceLineId": 1, "quantity": "2"}]}})
print(json.dumps(invoice))Pay in the sandbox
Let the simulator pay the intent for the customer. It works only with a sandbox key. Use the intentId of the intent that you just created, not the invoice id.
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"}'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
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);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))Read the order
Read the invoice to see what is paid. The status is PARTIALLY_PAID, amountPaid shows the paid amount, and each line has quantityPaid and quantityReserved. The invoice becomes PAID when every line is paid.
curl -sS "https://api.tappay.mn/api/v1/invoices/INVOICE_ID" \
-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 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_SECRET_KEY']);
$invoice = $tappay->invoices->retrieve(['id' => 'INVOICE_ID']);
echo json_encode($invoice);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.retrieve({"id": "INVOICE_ID"})
print(json.dumps(invoice))To cancel an invoice that nobody has paid, call Cancel an invoice. It also cancels the open intents. A paid, expired or cancelled invoice cannot be cancelled.
Verify
TapPay sends the invoice.partially_paid event when part of the invoice is paid. It sends invoice.paid when the last part is paid and invoice.expired when the invoice runs out of time. Handle them as described in the webhooks guide, then read the invoice with the request above.
Common mistakes
- Using
partialModeLINESon an invoice withoutlines. TapPay rejects it with422, because there are no lines to choose from. - Sending line totals that do not add up to the
amount. TapPay rejects the invoice with422. - Mixing
AMOUNTandLINESintents on one invoice. The two modes cannot be combined, and TapPay returns422. - Reusing an
orderIdon the same terminal. The pair ofterminalIdandorderIdis unique, so the second invoice is rejected as a duplicate. - Expecting open intents to stay reserved forever. An unpaid intent that expires gives its amount or lines back to the invoice.
- Expecting a new intent after the invoice expires. Paid parts stay paid and are not refunded, and you decide what to do with the rest.
Next steps
Show the intent to the customer with the QR payments guide or the channels guide. Listen for payments with the webhooks guide. See every field in Create an invoice, Create a payment intent and Retrieve an invoice.