Accept ABA KHQR Payments in Cambodia
Accept QR payments in Cambodia with a simple REST API, real-time WebSockets, Webhook notifications, and automated PayWay checkout handling. Create an order, present the KHQR code, and receive instant confirmation the moment the customer scans and pays.
Overview
The API is organized around a clean, predictable resource โ the Payment. All requests communicate over HTTPS/WSS, authenticate via API Key Bearer token, and exchange JSON data.
Authentication
Authenticate your requests by including your secret API key in the Authorization header as a Bearer token, or alternatively in the x-api-key header.
Authorization: Bearer dev_secret_key_12345
# Or via custom header:
x-api-key: dev_secret_key_12345
401 Unauthorized.
Quickstart
Create a payment order for $2.50 with a single API call. The system automatically launches a Playwright session and returns your KHQR code image & real-time WebSocket connection.
curl -X POST https://kcutpay-production.up.railway.app/api/v1/payments \
-H "Authorization: Bearer dev_secret_key_12345" \
-H "Content-Type: application/json" \
-d '{
"amount": 2.50,
"referenceId": "ORDER_1001",
"currency": "USD"
}'
Create a Payment
Creates a new payment session, opens your merchant ABA PayWay link in the background, inputs the exact amount, generates the KHQR code, and returns the real-time order record.
| Parameter | Type | Description |
|---|---|---|
amountrequired |
number | Amount to charge in USD or KHR. Normalized to 2 decimal places ($0.01 โ $10,000.00). |
referenceIdrequired |
string | Your unique internal order / cart ID (1 - 128 characters). |
currency |
string | USD (default) or KHR. |
merchantUrl |
string | Optional custom PayWay link. Defaults to MERCHANT_PAYWAY_URL in .env. |
callbackUrl |
string | Optional Webhook URL to receive a POST notification when payment reaches PAID. |
metadata |
object | Optional JSON key-value pairs stored with the payment. |
{
"paymentId": "pay_9a2f7c00e625a1b3",
"referenceId": "ORDER_1001",
"status": "QR_READY",
"amount": 2.50,
"currency": "USD",
"qrImage": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA...",
"qrPayload": "00020101021229330016kcut_demo@bkrt...",
"createdAt": "2026-09-13T05:30:00.000Z",
"expiresAt": "2026-09-13T05:40:00.000Z",
"paidAt": null,
"retryCount": 0
}
Retrieve a Payment
Fetch the up-to-date state of a single payment order.
curl -X GET https://kcutpay-production.up.railway.app/api/v1/payments/pay_9a2f7c00e625a1b3 \
-H "Authorization: Bearer dev_secret_key_12345"
Cancel a Payment
Aborts active monitoring and closes the background Playwright browser context. If the payment was already PAID, it cannot be cancelled.
Realtime WebSocket Stream
Connect your frontend UI directly to the WebSocket stream to receive live payment state transitions without polling!
const ws = new WebSocket(`wss://kcutpay-production.up.railway.app/ws/payments/${paymentId}`);
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Live State Update:", data.status);
if (data.status === "PAID") {
// Show success confetti & redirect
alert("Payment Received!");
} else if (data.status === "SESSION_EXPIRED") {
// Show expired state / refresh
}
};
The Payment Object
| Field | Type | Description |
|---|---|---|
paymentId |
string | Unique payment identifier (e.g. pay_9a2f7c00e625a1b3). |
status |
enum | Current lifecycle state (CREATED, OPENING_PAGE, QR_READY, WAITING_FOR_PAYMENT, PAID, SESSION_EXPIRED, FAILED, CANCELLED). |
amount |
number | Amount in USD (e.g. 2.50). |
currency |
string | USD or KHR. |
qrImage |
string | null | Base64 data URL of the captured QR code image. |
qrPayload |
string | null | Raw EMVCo KHQR payload string for custom SVG rendering. |
approvedAt / paidAt |
string | null | ISO-8601 timestamp when payment was confirmed. |
expiresAt |
string | null | ISO-8601 timestamp (~10 minutes after generation). |
Payment Lifecycle State Machine
Every payment follows a strict deterministic state machine:
| Status | Terminal | Meaning |
|---|---|---|
CREATED |
No | Payment order record created in database. |
OPENING_PAGE |
No | Playwright browser context navigating to merchant PayWay link. |
AMOUNT_ENTERED |
No | Normalized amount typed into PayWay input with Vue reactivity triggers. |
QR_READY |
No | KHQR code rendered and captured as Base64 image. |
WAITING_FOR_PAYMENT |
No | Active observer loop checking for completion via Network API & DOM. |
PAID |
Yes | Payment confirmed! Fires webhook & broadcasts WebSocket event. |
SESSION_EXPIRED |
Yes (or Auto-Retried) | Session expired. Auto-recovery triggers up to 3 times. |
FAILED |
Yes | Automation error or navigation failure. |
CANCELLED |
Yes | User or merchant cancelled the payment order. |
Build Your Own ABA KHQR Stand Ticket Card
Render the exact iconic ABA / Bakong KHQR stand ticket in your custom UI. Customers instantly recognise this card layout with the red header and Bakong center emblem:
- Error Correction Level H: Ensures the Bakong emblem in the center (~7% area) does not break scanning.
- Keep White Background: Scanners require high contrast; never invert QR colors.
- Live Countdown: Display minutes & seconds countdown to reduce user anxiety.
- Dynamic State Swap: Instantly replace QR with green checkmark when
PAID.
Webhooks & HMAC Verification
When a payment is marked PAID, the service sends a POST request with an HMAC-SHA256 signature header X-Signature to your specified callbackUrl.
{
"event": "payment.paid",
"timestamp": "2026-09-13T05:32:15.000Z",
"data": {
"paymentId": "pay_9a2f7c00e625a1b3",
"referenceId": "ORDER_1001",
"status": "PAID",
"amount": 2.50,
"currency": "USD",
"paidAt": "2026-09-13T05:32:14.000Z"
}
}
import crypto from "crypto";
app.post("/webhooks/payment", (req, res) => {
const signature = req.headers["x-signature"];
const secret = process.env.PAYMENT_WEBHOOK_SECRET;
const expected = crypto
.createHmac("sha256", secret)
.update(JSON.stringify(req.body))
.digest("hex");
if (signature !== expected) {
return res.status(400).send("Invalid signature");
}
const { event, data } = req.body;
if (event === "payment.paid") {
console.log(`โ
Order ${data.referenceId} confirmed paid for $${data.amount}!`);
// Fulfill customer order in your database
}
res.sendStatus(200);
});
Errors & HTTP Status Codes
| HTTP Code | Error Reason | Description |
|---|---|---|
400 Bad Request |
Invalid amount |
Amount must be a positive number with max 2 decimal places. |
401 Unauthorized |
Missing / Invalid API Key |
Missing or incorrect Authorization: Bearer header. |
404 Not Found |
Payment not found |
No payment record matches the given paymentId. |
429 Too Many Requests |
Rate limit exceeded |
Exceeded allowed requests per minute. Back off and retry. |
500 Server Error |
Automation failure |
PayWay page failed to load or worker encountered unrecoverable issue. |
Concurrency & Performance Limits
The service handles up to 10 concurrent browser sessions per Chromium instance using an async Semaphore lock, achieving an average QR generation time of ~2.4 seconds and peak memory footprint of under 150 MB.