The return contract
What your channel receives when the customer comes back from a K Bank card payment made with
POST /cardpayment, and what you may and may not conclude from it.
The URL
{callback}/thankyou?orderId={orderId}&status={status}&amount={amount}&chargeId={chargeId}&token={token}
| Parameter | Value | Notes |
|---|---|---|
orderId | The order you sent | From villaPayment3's card record, not from the browser |
status | success or failure | After 3-D Secure it is what K Bank's charge inquiry said |
amount | The order's grand total in baht, for example 1500.0 | |
chargeId | K Bank's charge id, chrg_… | Missing when no charge was made |
token | K Bank's card token id | May be empty |
Every value is percent-encoded. Decode the query string the usual way.
Rules for callback
You send the base only. /thankyou is appended unless your base already ends with it. Trailing slashes are dropped.
Accepted
https://orhttp://with a host:https://kiosk.example.com,https://app.example.com/pay- An app's own scheme followed by
://:yourapp://payments
Refused: the customer goes to https://shop.villamarket.com instead
| Refused | Example |
|---|---|
| A scheme a browser would run or read locally | javascript:, data:, vbscript:, file:, blob:, about:, filesystem:, view-source: |
No :// | yourapp:payments |
http(s):// without a host | https:// |
Whitespace inside the value (blanks around it are trimmed first), a control character, a quote, <, >, a backslash or a backtick | https://a.com/"x |
| Longer than 512 characters (counted after the trim) |
The rules are enforced on the server twice: when callback is stored and when the redirect is built
(functions/callback/src/payment_redirect.py, safe_callback_base). The
channel demo runs a JavaScript port of the rules on whatever you type (the
port is compared with the Python on a set of inputs; the server is the authority).
The strict rules above are on the dev branch. The production stack (commit cee8ff7) accepts callback and
appends /thankyou, without the refusals. Send a clean base and you get the same result on both.
Confirm before you celebrate
The return URL is a hint. Anyone can open yourapp://payments/thankyou?orderId=…&status=success.
| Your channel's orders live in | Confirm with |
|---|---|
| Villa's order table | Your server reads the order: it is paid when payment.isPaid is true. A payment header alone proves nothing: POST /cardpayment writes one with isPaid: false, status: PENDING before the charge |
| A hosted checkout session | GET /checkout/status/{sessionId} says paid |
| Your own database (site.villamarket.ai style) | The signed server callback, when it is switched on for your origin. Until then: a person checks |
Then:
status=successand your server says paid: show the confirmation.status=successand your server says not yet: show "Confirming your payment…" and ask again for up to a minute. K Bank's server notify may land a few seconds after the browser.status=failure: the payment was not confirmed: K Bank declined it, or could not be asked. Show "Payment not completed", read the order from your server, and offer another try only if it is still unpaid.- The customer never came back: K Bank's server notify normally marks the order paid, so your order screen must read it from the server. It is a recovery path, not a guarantee.
The hosted checkout's return URL
A different URL, for a different flow: a hosted checkout session made for a registered channel (on on the current dev stack since 1 Dec 2026; not on production).
{returnBase}/thankyou?sessionId={sessionId}&status={status}&state={state}
Direct card (callback) | Hosted checkout (channel registry) | |
|---|---|---|
| The base comes from | The callback field of each request | The registry entry of the channel; never from a request |
| Identifies | The order: orderId | The session: sessionId. No order id |
status | success, failure | success, pending, failure |
| Also carries | amount, chargeId, token | state |
| A base that breaks the rules | The customer goes to https://shop.villamarket.com | The entry is not used: the result page stays |
| Confirm with | Your server reading the order | GET /checkout/status/{sessionId} |
Both are hints. Neither proves a payment.
Deep links
| Platform | callback | Register |
|---|---|---|
| iOS, custom scheme | yourapp://payments | CFBundleURLSchemes |
| Android, custom scheme | yourapp://payments | An intent filter for the scheme |
| iOS Universal Links, Android App Links | https://app.example.com | The association files on that host, and a web page at /thankyou as the fallback |
3-D Secure runs in a web view. Catch the return in the web view's navigation callback rather than waiting for the operating system to hand over: see the snippets in the Quickstart.