Webhooks

Shops with their own POS or accounting software add an endpoint under Webhooks in the owner portal (www.thaiqrorder.com/owner). Whenever a chosen event happens, ThaiQROrder sends a JSON HTTP POST to it.

Events

typeWhen
order.createdA new order for the kitchen (website/kiosk orders: once paid, or at once when paid at the counter)
order.paidAn order was paid (online, or the shop marked it paid)
order.status_changedAn order's status changed (cooking, served, …)
order.cancelledAn order was cancelled
bill.settledA table bill was settled and the table cleared
bill.reopenedA settled bill was reopened (back on its table)
bill.refundedA settled bill was cancelled or some dishes refunded
payment.succeededA guest paid online (Stripe)
payment.refundedA refund went through
reservation.createdA new reservation request
reservation.updatedA reservation changed (confirmed, declined, cancelled, …)
waiting.createdA waiting-list ticket was issued
pingThe "Send test" button in the portal

Payload

Every event has the same envelope: id (unique — use it to ignore duplicates), type, created_at, store, and data holding order, bill, payment, reservation or waiting by type. Amounts are in baht.

{
    "id": "evt_8f0c2c1e-2a7b-4c1e-9a52-1f2d3c4b5a69",
    "type": "order.created",
    "created_at": "2026-10-07T12:34:56+07:00",
    "store": {
        "id": 62,
        "name": "Baan Daniel Kitchen",
        "slug": "daniel"
    },
    "data": {
        "order": {
            "id": 12345,
            "status": "pending",
            "fulfillment": "dine_in",
            "origin": "guest",
            "total": 185,
            "delivery_fee": null,
            "note": "ไม่เผ็ด",
            "customer_name": null,
            "customer_phone": null,
            "table": {
                "id": 528,
                "number": 5,
                "label": "ริมน้ำ"
            },
            "table_session_id": 27310,
            "pickup_at": null,
            "delivery_address": null,
            "paid_at": null,
            "paid_via": null,
            "pay_at_pickup": false,
            "items": [
                {
                    "id": 90001,
                    "menu_item_id": 14677,
                    "name": "กะเพราหมูสับ",
                    "quantity": 2,
                    "voided_quantity": 0,
                    "price": 60,
                    "note": null
                },
                {
                    "id": 90002,
                    "menu_item_id": 14680,
                    "name": "ชาไทยเย็น",
                    "quantity": 1,
                    "voided_quantity": 0,
                    "price": 65,
                    "note": null
                }
            ],
            "created_at": "2026-10-07T12:34:55+07:00"
        }
    }
}

Headers

  • X-ThaiQROrder-Event: the event type
  • X-ThaiQROrder-Delivery: the delivery number (a resend gets a new one; the event id stays the same)
  • X-ThaiQROrder-Signature: t=<unix>,v1=<hex>

Verify the signature

v1 is the hex HMAC-SHA256 of "<t>.<raw request body>" keyed with the endpoint secret (whsec_tqo_…). Compare in constant time and reject a t older than 5 minutes.

PHP

$body = file_get_contents('php://input');
[$t, $v1] = [null, null];
foreach (explode(',', $_SERVER['HTTP_X_THAIQRORDER_SIGNATURE'] ?? '') as $part) {
    [$k, $v] = array_pad(explode('=', $part, 2), 2, null);
    if ($k === 't') $t = $v; elseif ($k === 'v1') $v1 = $v;
}
$expected = hash_hmac('sha256', $t . '.' . $body, getenv('TQO_WEBHOOK_SECRET'));
if (!$v1 || !hash_equals($expected, $v1) || abs(time() - (int) $t) > 300) {
    http_response_code(400); exit;
}
$event = json_decode($body, true);  // reply 2xx quickly; do slow work later

Node.js

import crypto from 'node:crypto';
// express.raw({ type: 'application/json' }) so req.body is the raw Buffer
app.post('/hooks/thaiqrorder', express.raw({ type: 'application/json' }), (req, res) => {
  const sig = Object.fromEntries(String(req.get('X-ThaiQROrder-Signature')).split(',').map(p => p.split('=')));
  const expected = crypto.createHmac('sha256', process.env.TQO_WEBHOOK_SECRET).update(`${sig.t}.${req.body}`).digest('hex');
  const ok = sig.v1 && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig.v1)) && Math.abs(Date.now() / 1000 - sig.t) < 300;
  if (!ok) return res.sendStatus(400);
  const event = JSON.parse(req.body);
  res.sendStatus(200);
});

Python

import hmac, hashlib, time, json
def verify(raw_body: bytes, header: str, secret: str) -> dict:
    parts = dict(p.split('=', 1) for p in header.split(','))
    expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + raw_body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, parts.get('v1', '')) or abs(time.time() - int(parts['t'])) > 300:
        raise ValueError('bad signature')
    return json.loads(raw_body)

Retries and switching off

  • A 2xx answer within 10 seconds counts as delivered; redirects are not followed.
  • Otherwise it is retried after 1 min, 5 min, 30 min, 2 h and 6 h (6 attempts in all).
  • Events can arrive twice or out of order — rely on the id and the state inside data.
  • An endpoint with 15 failed deliveries in a row is switched off; turn it back on in the portal.
  • Endpoints must be public addresses (no localhost or private networks).