Skip to main content

Quickstart

Two paths. Path A works on production today and returns the customer to your channel. Path B gives you every payment method with one call, and is on the dev branch only.

Before either: your channel has created the order, and you know its orderId.

Path A: direct card with callback​

K Bank renders the card form inside your page. The form posts to villaPayment3, which charges the card, takes the customer through 3-D Secure, and sends them to your return address.

1. Choose your return address​

Give only the base. villaPayment3 appends /thankyou and the result.

ChannelcallbackCustomer comes back to
Web shop(leave it out)https://shop.villamarket.com/thankyou?orderId=…
Your web channelhttps://kiosk.example.comhttps://kiosk.example.com/thankyou?orderId=…
iOS or Android app, own schemeyourapp://paymentsyourapp://payments/thankyou?orderId=…
App with Universal Links or App Linkshttps://app.example.comhttps://app.example.com/thankyou?orderId=…

The full rules, and what is refused, are in The return contract.

2. Render the form​

<form id="pay" method="POST"
action="https://shop.villamarket.com/api/payment3api/cardpayment">
<input type="hidden" name="orderId" value="482500007436">
<input type="hidden" name="userId" value="cust_test_xxx">
<input type="hidden" name="customerId" value="cust_test_xxx">
<input type="hidden" name="basketId" value="basket_456">
<input type="hidden" name="grandTotal" value="1500.00">
<input type="hidden" name="mid" value="MERCHANT_ID">
<!-- The line that makes this YOUR channel: -->
<input type="hidden" name="callback" value="https://kiosk.example.com">

<script type="text/javascript"
src="https://kpaymentgateway.kasikornbank.com/ui/v2/kpayment.min.js"
data-apikey="YOUR_KBANK_PUBLIC_KEY"
data-amount="1500.00" data-currency="THB"
data-payment-methods="card" data-name="Villa Market"
data-mid="MERCHANT_ID" data-customer-id="cust_test_xxx"></script>
</form>

Use K Bank's dev script (https://dev-kpaymentgateway.kasikornbank.com/ui/v2/kpayment.min.js) and the payment3devapi base while you test. K Bank's script adds the card token itself: never add it.

The server's total is what is charged

For a Villa order villaPayment3 prices the order again with calculate-cost and charges that. The grandTotal you post is compared with it and the result is recorded on the payment; a difference does not refuse the request. Show the customer the server's total, never one you computed.

3. Build the screen the customer returns to​

The customer arrives at:

{callback}/thankyou?orderId=482500007436&status=success&amount=1500.0&chargeId=chrg_prod_…&token=tokn_prod_…

status is success or failure. Show "confirming…", then ask your own server whether the order is paid. Anyone can type that URL. What to check is in The return contract.

4. Test it​

Set bypass_order=1 on the dev stack to try the redirect without a real order, or use the channel demo to see the exact URL your callback produces. Then follow Testing a channel.

Path B: hosted checkout​

One call gives you a payment page with card, Thai QR, American Express and Apple Pay. villaPayment3 owns the page, the gateways and the result page. Dev branch only: the production stack does not have it yet.

caution

On 1 Dec 2026 the villa.kitchen address in the examples reaches an older dev stack that has no hosted checkout (/checkout/... answers 403 there). Use the current dev stack's MainApi address in its place: see Base URLs.

1. Create a session​

curl -X POST https://villa.kitchen/api/payment3devapi/checkout/sessions \
-H "Authorization: $COGNITO_ID_TOKEN" \
-H "Content-Type: application/json" \
-d '{"orderIds": ["002500000301"], "source": "app"}'

Every order must belong to the token's sub. source is web or app (anything else is stored as web); where the channel registry is off (production and the older dev stack) it is a label for staff, not a routing key. Where the channel registry is on (the current dev stack, since 1 Dec 2026) a registered channel id in source also decides where the result page returns the customer. The session lives 2 hours.

201 Created:

{
"sessionId": "CHKQ2M4K7X3ZPAB",
"url": "https://villa.kitchen/api/payment3devapi/checkout/pay/Fn0b…32 characters…",
"expiresAt": 1793664000,
"amount": 20050, "amountDisplay": "200.50", "currency": "THB",
"orders": [{"orderId": "002500000301", "amount": 20050}],
"methods": ["card", "thai_qr", "amex", "apple_pay"]
}

Amounts are integers in satang. Keep sessionId (CHK and 12 characters of A-Z, 2-7); it is not a secret. The id above is only an example: use the one you were given.

2. Open url​

In a browser tab or a web view. The customer picks a method and pays.

3. Know when it is done​

A payment that leaves the payment page comes back to /checkout/return/{sessionId}, villaPayment3's result page ("Confirming your payment…", then "Payment received"). A declined Apple Pay, a failed extra Apple Pay step and an unpaid QR never get there: the customer stays on the payment page. It sends the customer on to your channel only when your channel is registered in the channel registry, which is on on the current dev stack since 1 Dec 2026 (Gaps). For a session without a registered channel:

  • In a web view: watch for a navigation whose path contains /checkout/return/, then poll the status below and close the web view yourself when it is final.
  • Anywhere: poll GET /checkout/status/{sessionId}.
curl https://villa.kitchen/api/payment3devapi/checkout/status/CHKQ2M4K7X3ZPAB
# {"sessionId": "CHKQ2M4K7X3ZPAB", "state": "paid", "method": "card", "attempt": "..."}

attempt is the state of the latest try (started, processing, declined, failed, refused, …); route on state.

stateShow the customer
openNo confirmed payment yet. The customer can try again on the payment page (url). Neither open nor attempt (the latest try only) proves that nothing was charged: an earlier attempt can still be unresolved, and the payment page does not stop a new one. Never tell the customer "nothing was charged" from these fields. Staff see every attempt with GET /checkout/links/{sessionId}
processing"Confirming your payment…" Keep polling (at most every 4 seconds)
paidYour confirmation screen
expired, cancelledThe link is over. Create a new session
needs_attentionMoney arrived that does not fit. Tell the customer staff will contact them

Full reference: Checkout API.

Checklist before you ask for production​

  • The customer returns to your channel on success and on failure, and your flow copes with an error instead of a return: POST /cardpayment answers 500 with JSON when it refuses a request.
  • Your confirmation screen asks your server, and your server reads the order's paid state.
  • A customer who paid and never returned (closed the tab after 3-D Secure) is still found: K Bank's server notify normally marks the order paid, so your order screen must refresh from the server. It is a recovery path, not a guarantee: if the order is still unpaid after a few minutes, raise it. Never ask the customer to pay again.
  • status=failure is shown as "payment not completed". It means not confirmed: K Bank declined, or could not be asked. Read the order from your server before you offer another try.
  • No card number, token, key or gateway answer in your logs.
  • You ran the steps in Testing a channel on the dev stack.