Skip to main content

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}
ParameterValueNotes
orderIdThe order you sentFrom villaPayment3's card record, not from the browser
statussuccess or failureAfter 3-D Secure it is what K Bank's charge inquiry said
amountThe order's grand total in baht, for example 1500.0
chargeIdK Bank's charge id, chrg_…Missing when no charge was made
tokenK Bank's card token idMay 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:// or http:// 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

RefusedExample
A scheme a browser would run or read locallyjavascript:, data:, vbscript:, file:, blob:, about:, filesystem:, view-source:
No ://yourapp:payments
http(s):// without a hosthttps://
Whitespace inside the value (blanks around it are trimmed first), a control character, a quote, <, >, a backslash or a backtickhttps://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).

Production runs an older check

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 inConfirm with
Villa's order tableYour 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 sessionGET /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=success and your server says paid: show the confirmation.
  • status=success and 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 fromThe callback field of each requestThe registry entry of the channel; never from a request
IdentifiesThe order: orderIdThe session: sessionId. No order id
statussuccess, failuresuccess, pending, failure
Also carriesamount, chargeId, tokenstate
A base that breaks the rulesThe customer goes to https://shop.villamarket.comThe entry is not used: the result page stays
Confirm withYour server reading the orderGET /checkout/status/{sessionId}

Both are hints. Neither proves a payment.

PlatformcallbackRegister
iOS, custom schemeyourapp://paymentsCFBundleURLSchemes
Android, custom schemeyourapp://paymentsAn intent filter for the scheme
iOS Universal Links, Android App Linkshttps://app.example.comThe 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.