Skip to main content

Apple Pay (Stripe)

Apple Pay is the only payment Villa takes through Stripe. Every other card still goes through K Bank. Status as of 2 Dec 2026.

What is live​

Shop (shop.villamarket.com)Site with its own orders (site.villamarket.ai)
Apple Pay offeredLive since 2 Dec 2026. The Apple Pay button fix is pendingAPI enabled on current dev with test keys (PR #259). Production is off (PR #258)
Who prices the ordervillaPayment3, from the Villa orderThe site (same trust model as bypass_order cards)
How the order becomes paidStripe webhook, then villaPayment3 marks the Villa order paidSigned server callback to the site (Signed server callback)
Stripe modeLive, THBTest only, THB

The first live Apple Pay payment on the shop was 12 THB on 2 Dec 2026, about 08:19 Bangkok time. It was charged, recorded by the webhook, and the order was marked paid about 5 seconds later.

Rules every client must follow​

  1. 10 baht minimum. Stripe refuses a THB payment under 1000 satang: the Apple Pay button never loads. Hide Apple Pay, or say "Apple Pay needs an order of at least 10 baht", below that amount.
  2. Card-only Elements. Create Stripe Elements with { mode: "payment", amount, currency: "thb", paymentMethodTypes: ["card"] }. Apple Pay is a card wallet, and the server creates the PaymentIntent with payment_method_types: ["card"]. (The server also accepts a token collected in automatic mode, so a page built before this rule still works.)
  3. Only Apple Pay. The Express Checkout element shows Apple Pay only (applePay: "always", every other wallet "never"). The server refuses any token that is not an Apple Pay card.
  4. The order read back is the only proof. A 200 from the confirm call is not proof of payment. After Apple Pay closes, read the order every 2 seconds for up to about 60 seconds and continue to the thank-you page as soon as it reads paid. Never tell the shopper to pay again while the outcome is unknown.
  5. Browsers. Safari on iPhone, iPad and Mac pays directly. Chrome or another browser on a computer can pay too: Stripe shows a QR code to finish on an iPhone. Android cannot use Apple Pay.

Shop flow​

browser                          villaPayment3 (/stripe/applepay, Cognito)          Stripe
| POST {orderId} | |
|------------------------------------->| prices the Villa order |
|<-------------- {publishableKey, amount, currency} |
| Elements + Apple Pay sheet ------------------------------------------------------>| confirmation token
| POST {orderId, confirmationTokenId, expectedAmount} |
|------------------------------------->| claim order, check Apple Pay, create+confirm PaymentIntent
| |------------------------------------------>|
| |<---------- webhook payment_intent.succeeded
| | mark the Villa order paid |
| read the order until paid, then /thankyou |

Codes the confirm call can answer: 200 (submitted: still read the order), 402 card_declined, 402 action_unsupported, 409 price_changed (get a new quote), 409 payment_attempt_exists or order_already_paid (read the order), 400 not_apple_pay, 400 token_invalid, 502 payment_outcome_unknown (read the order, do not pay again), 503 apple_pay_unavailable.

Sites with their own orders​

Use POST /stripe/applepay/site if your site owns its orders. This route does not use Villa sign-in. Your server authorizes the order and signs the request details. The browser only forwards the ticket.

EnvironmentBase URL and availability
Current devhttps://rj1mf23lu0.execute-api.ap-southeast-1.amazonaws.com/Prod. Uses Stripe test keys. /Prod is the API stage name, not the payment mode.
ProductionNot yet enabled. End-to-end testing and an approved live change window are still required.

Use your exact configured HTTPS origin with no trailing slash. If the browser sends an Origin header, it must equal callbackOrigin. CORS allows configured origins only. Request bodies are limited to 4096 bytes.

Quote​

Send the order ID, the total in integer satang (1000–99999999), lowercase thb, your origin and the issued siteTicket. Do not send a token yet.

{
"orderId": "ORDER-1234",
"amountSatang": 7400,
"currency": "thb",
"callbackOrigin": "https://staging.site.villamarket.ai",
"siteTicket": "<site-signed ticket>"
}

A successful quote returns {"publishableKey":"pk_test_...","amount":7400,"currency":"thb"}. Use it to initialize Stripe Elements. The quote does not create a PaymentIntent or read a Villa order.

Confirm​

Post the same fields to the same endpoint with the Stripe ConfirmationToken from Apple Pay. Do not send expectedAmount or expect a client secret.

{
"orderId": "ORDER-1234",
"amountSatang": 7400,
"currency": "thb",
"callbackOrigin": "https://staging.site.villamarket.ai",
"siteTicket": "<site-signed ticket>",
"confirmationTokenId": "ctoken_..."
}

A successful submission returns {"status":"succeeded","paymentIntentId":"pi_...","orderId":"ORDER-1234"}. It can also return "status":"processing". Neither status marks the site's order paid. Stripe's only redirect target is <callbackOrigin>/thankyou?orderId=<URL-encoded id>. Read payment state from your own order API. Your server receives the verified result through the signed server callback.

Sign the pay ticket​

Authorize the order on your server. Read its ID and total from your persisted order. Sign with the shared callback hmacSecret for that exact configured origin. Do not send the secret to the browser. Both quote and confirm require a ticket. There is no legacy mode without one.

  1. Make compact UTF-8 JSON with exactly seven keys. v is the integer 1. amountSatang and exp are integers. orderId, currency, origin and attempt are strings. Use uppercase THB in the ticket, even though the POST body uses lowercase thb. The order ID, amount and origin must match the POST.
  2. Set exp in Unix seconds. Issue tickets within now < exp <= now + 3600. With clock skew, the verifier accepts now - 60 < exp <= now + 3660.
  3. Encode the JSON as unpadded base64url B. Compute S as lowercase hex HMAC-SHA256 with the UTF-8 secret as the key and "site-pay-ticket.v1." + B as the message. Send B + "." + S as siteTicket (at most 1024 characters).

attempt is for audit only. The Stripe claim is keyed by branch, origin and order ID. A new ticket does not bypass an active or paid claim. An earlier Stripe intent can be replaced only after zero-capture cancellation is proven. This claim does not lock payments on other providers.

Test vector with the dummy key test-secret-do-not-use and verifier time 1700000000. Encode this exact payload without a trailing newline:

{"v":1,"orderId":"ORDER-1","amountSatang":7400,"currency":"THB","origin":"https://site.example.com","attempt":"attempt-1","exp":1700000300}

Expected siteTicket:

eyJ2IjoxLCJvcmRlcklkIjoiT1JERVItMSIsImFtb3VudFNhdGFuZyI6NzQwMCwiY3VycmVuY3kiOiJUSEIiLCJvcmlnaW4iOiJodHRwczovL3NpdGUuZXhhbXBsZS5jb20iLCJhdHRlbXB0IjoiYXR0ZW1wdC0xIiwiZXhwIjoxNzAwMDAwMzAwfQ.1e194eedc46d71b380897327cdc9edbe2e25df90aeb5ae30803c03f0285b1bf1

Site endpoint errors​

HTTPCodeWhat to do
400invalid_requestCheck the JSON and fields.
400amount_below_minimumDo not offer Apple Pay under THB 10.
400not_apple_pay, token_invalidCollect a valid Apple Pay token.
402card_declined, action_unsupported, attempt_not_sentThe response has status: declined. A fresh ticket, quote and token are allowed.
403site_ticket_invalidThe ticket is missing, invalid or for an unconfigured origin. The response is only {"code":"site_ticket_invalid"}. No Stripe call or claim access happens.
403origin_not_configuredCheck the configured origin and the browser Origin header.
405method_not_allowedUse POST.
409payment_attempt_existsAn attempt is active or already paid. Read the order and wait for the callback or ask staff to reconcile.
413request_too_largeKeep the body to 4096 bytes or less.
502payment_outcome_unknown, payment_service_unavailableRead the order and wait for the callback or ask staff to reconcile.
503apple_pay_unavailable, claim_unavailableApple Pay setup or the claim store is unavailable.

After any 409 payment_attempt_exists or any 502, do not start another attempt, even with a different payment method. Never ask the shopper to pay again while the outcome is unknown.