GuidesCheck payment status
How to check if a KHQR payment is paid
With Dalo there are two ways to know a KHQR payment is paid, and most apps use both: a signed webhook (payment.completed) that tells your server to fulfil the order, and polling GET /v1/payments/{id} every 2 to 3 seconds to update the screen the customer is looking at. A payment is paid only when its status is paid and livemode is true.
The statuses
| status | Meaning | What to do |
|---|---|---|
pending | QR created, waiting for the customer | Show the QR or the checkout page |
scanned | Scanned; the customer still has to confirm in their app | Not proof of payment. Keep waiting |
paid | The money arrived, for the expected amount | Fulfil the order (only on this status) |
expired | The QR window passed | Offer a new QR (new Idempotency-Key) |
failed | The paid page did not match the expected merchant, amount or currency | Do not fulfil |
cancelled | Cancelled by you or by the customer | Treat as not paid |
paid, expired, failed and cancelled are final. A payment can go straight from pending to paid. The QR stays open 5 minutes by default (1 to 30 minutes in store settings, or expires_in per payment).
1. The webhook: for fulfilment
Add an HTTPS endpoint in the dashboard. Dalo sends a POST every time a payment changes status, signed with HMAC-SHA256 in the X-KHQR-Signature header, and retries failed deliveries after 5 s, 30 s, 2 min, 10 min and 1 h. This is where you mark the order paid, send the receipt and start shipping, because it arrives even when the customer closed the page.
POST /webhooks/dalo
X-KHQR-Event: payment.completed
X-KHQR-Delivery: del_7KcZ2qa1
X-KHQR-Livemode: true
X-KHQR-Signature: t=1762924212,v1=5d2c…(64 hex characters)
{"id":"evt_3m9Qx1Zb","type":"payment.completed","livemode":true,
"data":{"payment":{"id":"pay_8Qm2kV3xLp9c","status":"paid","amount":"4.50","reference_id":"order_1024", …}}}
Verify the signature on the raw body before you trust it. Copy-paste versions: Node.js, Laravel, Python, Web Crypto (edge runtimes).
2. Polling: for the screen
If you send customers to Dalo's hosted checkout_url, you do not need to poll: the page updates itself and redirects to your success URL. If you show the QR inside your own page, poll from your server (the API key never goes to the browser):
// Poll from your server while the customer has the QR open, never from the browser (the API key stays on the server).
const DALO = "https://dalodesk.com";
const FINAL = new Set(["paid", "expired", "failed", "cancelled"]);
export async function getPayment(id) {
const response = await fetch(`${DALO}/v1/payments/${id}`, {
headers: { Authorization: `Bearer ${process.env.DALO_API_KEY}` },
signal: AbortSignal.timeout(10000),
});
if (!response.ok) throw new Error(`Dalo ${response.status}`);
return response.json();
}
// Waits until the payment is paid, expired, failed or cancelled. 2-3 seconds between checks is fine.
export async function waitForPayment(id, { everyMs = 2500, timeoutMs = 31 * 60 * 1000 } = {}) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const payment = await getPayment(id);
if (FINAL.has(payment.status)) return payment;
await new Promise(resolve => setTimeout(resolve, everyMs));
}
throw new Error("payment still open");
}
// Express: the page polls this route; the route asks Dalo. Only answer for payments of the signed-in customer's own orders.
app.get("/api/orders/:orderId/payment-status", async (req, res) => {
const order = await findOrderForCustomer(req.params.orderId, req.user); // your code
if (!order?.paymentId) return res.sendStatus(404);
const payment = await getPayment(order.paymentId);
res.json({ status: payment.status });
});
<!-- pay.html: show the QR and poll your own server -->
<img id="qr" alt="KHQR code, $4.50" width="280" height="280">
<p id="state">Scan with any KHQR banking app</p>
<script>
const orderId = "1024", qrImageUrl = "…"; // from your server: payment.qr_image_url
document.getElementById("qr").src = qrImageUrl;
const timer = setInterval(async () => {
const { status } = await (await fetch(`/api/orders/${orderId}/payment-status`)).json();
if (status === "paid") { clearInterval(timer); location.href = "/thanks"; }
else if (["expired", "failed", "cancelled"].includes(status)) {
clearInterval(timer);
document.getElementById("state").textContent = "This QR has ended. Tap to get a new one.";
}
}, 2500);
</script>
Polling every 2 to 3 seconds while a checkout is open is fine. For anything that runs in the background, use the webhook.
What not to trust
scanned: the customer has not confirmed yet.- The redirect query string (
?status=paid): anyone can type it. Check with the webhook result or aGETfrom your server. - Events with
livemode: false: test payments. Use them to test your handler, never to ship goods. - The amount alone: every payment has its own QR, so match by
reference_idor paymentid, then check the amount.
Questions
How fast does Dalo know a KHQR payment is paid?
Within seconds of the customer confirming in their banking app. The webhook is sent at the same moment, and GET /v1/payments/{id} shows status paid.
Should I use the webhook or polling?
Both, for different jobs: the webhook to fulfil the order on your server, polling only to update a page the customer is watching. If you use the hosted checkout page, the webhook alone is enough.
What if my webhook endpoint is down?
Dalo retries after 5 s, 30 s, 2 min, 10 min and 1 h, then keeps the delivery so you can resend it from the dashboard. Retries reuse the same X-KHQR-Delivery id, so make your handler safe to run twice.
Can I check the status from the browser?
Not with your API key. Have the browser call your own server, and your server call Dalo.
Get a test key in two minutes.
Sign in with your email, create a store in test mode and copy a dk_test_ key. No merchant application, no paperwork. Free up to 50 sales a month.
More guidesKHQR payment APILaravelNode.jsNext.jsDjangoTelegram botTest modeFlask and FastAPIStatic websiteChoosing an API