Skip to content

Create orders from your own system

View as Markdown

Overview

Your website or app can create an order in the merchant’s name. TapPay creates the payment, returns an order_page_url that shows the payment and the progress to the customer, and keeps the status of the order. You create the order with one request and then follow it with GET or the order.updated event.

Before you begin

Your key needs the commerce:write scope and must cover all terminals. Choose “All terminals” when you connect your system, or create the key in Developers › API keys & webhooks. Use your secret key, shown below as sk_test_YOUR_SECRET_KEY, and a sandbox key while you build. The example also pays the order in the sandbox, so the key needs payments:write too. You need the location_id of a branch that has an order terminal. Set it in the shell as LOCATION_ID.

Steps

Create the order

Send location_id, a unique external_ref from your own system, the lines (name, quantity, unit_price), the fulfillment mode (PICKUP, AT_MERCHANT, DIGITAL or DELIVERY) and the customer. DELIVERY also needs fulfillment.address. The response has the order_id, the order_page_url to open for the customer and the intent_id of the payment. Send the same external_ref only once.

curl -sS -X POST "https://api.tappay.mn/api/v1/commerce/orders" \
  -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 '{"location_id":"'"$LOCATION_ID"'","external_ref":"web-'"$(uuidgen)"'","lines":[{"name":"Coffee","quantity":2,"unit_price":4000},{"name":"Cake","quantity":1,"unit_price":6000}],"fulfillment":{"mode":"PICKUP"},"customer":{"name":"Bat","phone":"+97699000000"}}'
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const order = await tappay.commerce.create({
  body: {
    location_id: process.env.LOCATION_ID,
    external_ref: `web-${crypto.randomUUID()}`,
    lines: [
      { name: 'Coffee', quantity: 2, unit_price: 4000 },
      { name: 'Cake', quantity: 1, unit_price: 6000 },
    ],
    fulfillment: { mode: 'PICKUP' },
    customer: { name: 'Bat', phone: '+97699000000' },
  },
});
console.log(JSON.stringify(order));
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$order = $tappay->commerce->create([
    'body' => [
        'location_id' => getenv('LOCATION_ID'),
        'external_ref' => 'web-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)),
        'lines' => [
            ['name' => 'Coffee', 'quantity' => 2, 'unit_price' => 4000],
            ['name' => 'Cake', 'quantity' => 1, 'unit_price' => 6000],
        ],
        'fulfillment' => ['mode' => 'PICKUP'],
        'customer' => ['name' => 'Bat', 'phone' => '+97699000000'],
    ],
]);
echo json_encode($order);
import json
import os
import uuid
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
order = client.commerce.create({
    "body": {
        "location_id": os.environ["LOCATION_ID"],
        "external_ref": "web-" + str(uuid.uuid4()),
        "lines": [
            {"name": "Coffee", "quantity": 2, "unit_price": 4000},
            {"name": "Cake", "quantity": 1, "unit_price": 6000},
        ],
        "fulfillment": {"mode": "PICKUP"},
        "customer": {"name": "Bat", "phone": "+97699000000"},
    },
})
print(json.dumps(order))

Pay in the sandbox

The simulator pays the payment instead of the customer. It works only with a sandbox key. Use the intent_id from the previous response.

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 order with GET. After the payment it has the status CONFIRMED. Before the payment it is AWAITING_PAYMENT.

curl -sS "https://api.tappay.mn/api/v1/commerce/orders/ORDER_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 order = await tappay.commerce.retrieve({ order_id: 'ORDER_ID' });
console.log(JSON.stringify(order));
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$order = $tappay->commerce->retrieve(['order_id' => 'ORDER_ID']);
echo json_encode($order);
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
order = client.commerce.retrieve({"order_id": "ORDER_ID"})
print(json.dumps(order))

Verify

TapPay sends the order.updated event to your webhook endpoint each time the order status changes. Handle it as described in the webhooks guide and read the order to get the new status.

Common mistakes

  • Sending the same external_ref twice. TapPay answers 409 ORD-019, so create the order once and read it afterwards.
  • Sending no lines or a total of zero. TapPay answers 422 ORD-020. A delivery that the dispatcher handles is also not supported here and gives the same error.
  • Sending DELIVERY without fulfillment.address. TapPay answers 400 VAL-001.
  • Using the id of a branch that does not exist (CAT-008) or a branch that is not accepting orders (ORD-007). Use the id of a branch that takes orders.
  • Using a key that is limited to one terminal. The key must cover all terminals.
  • Sending tracking for a delivery that you handle yourself without address.location. TapPay answers DLV-004, so send the coordinates when you create the order.

Next steps

Show order_page_url to the customer. Send delivery progress as described in the fulfillment guide and read how orders work in the orders guide. Look up each field in the API reference.