For coding agents
You are an agent asked to add or change a sales channel. This page is written for you. A machine-readable copy of
the contract is at /channels/channel-contract.json; read it before
you write code.
Rules
Always
- Send the fields the route requires and invent nothing. For a Villa order the server prices it: the hosted checkout
takes order ids only, and the
grandTotalin aPOST /cardpaymentform must be the order's own total (the server's figure is what is charged). - Treat the return URL as a hint. Confirm on the channel's server before showing "paid".
- Handle three endings: success, failure, and the customer who never returns.
- Send
callbackas a base only:https://hostorscheme://path. - Run the callback tests after any change under
functions/callbackorfunctions/cardtoken.
Never
- Never mark an order paid from a browser parameter.
- Never log a card token, a gateway body, a key, a link token or a signing secret.
- Never use
bypass_orderon production without a person's approval. - Never route Visa, Mastercard or Thai QR through Stripe. Stripe is Apple Pay only.
- Never deploy, merge to
master, create or change a secret, or change a gateway's configuration. Ask a person. Merging tomasterdeploys production. - Never edit one copy of
payment_redirect.py. It exists twice, byte-identical, and a test compares them.
Decide the path
Does the channel keep its own orders (not in Villa's order table)?
├─ yes → direct card: POST /cardpayment, bypass_order, callback=<channel origin>
│ plus the signed server callback (on dev: on for one test origin; not on production). Card only.
└─ no → does it need more than card, or bulk payments?
├─ yes → hosted checkout: POST /checkout/sessions (dev branch only)
│ to bring the customer back: register the channel and send its id as source
│ (channel registry: on on the current dev stack since 1 Dec 2026; not on production)
└─ no → direct card: POST /cardpayment with callback=<channel base> ← live on production
File map
| Concern | File |
|---|---|
Card charge, stores callback | functions/cardtoken/app.py |
| Browser return after 3-D Secure | functions/callback/callback.py |
| Return address rules | functions/callback/src/payment_redirect.py and its copy in functions/cardtoken/src/ |
| Builds the return URL | functions/callback/src/credit_card_callback_processor.py |
| K Bank server notify | functions/callback/notify.py, delayednotify.py |
| Thai QR | functions/kbankcreateorder/createorder.py, functions/callback/qrcallback.py, qrnotify.py |
| Amex | functions/callback/amexcallback.py, src/callback_signature.py |
| Apple Pay | functions/stripe/confirm.py, webhook.py, src/stripe_client.py |
| Hosted checkout | functions/checkout/app.py, src/service.py, src/pages.py, src/config.py |
Channel registry and the return URL (merged to dev) | functions/checkout/src/channels.py, functions/checkout/static/channel-return.js (static/checkout.js beside it is unchanged) |
Register, check and launch a channel (merged to dev) | channel-kit/channel.py, channel-kit/thankyou/, channel-kit/shop-stack.yaml |
| Gateway handlers hand checkout payments over | functions/callback/src/checkout_bridge.py |
| Marks an order paid, once | functions/processPaidOrder/ |
| Routes and permissions | template.yaml |
Add a channel: the checklist
- Name it. A short id (
kiosk), its return base, and where its orders live. For the hosted checkout, check them withpython3 channel-kit/channel.py validate(Launch a shop). - Pick the path with the tree above.
- Build the pay step from the Quickstart.
- Build the return screen: parse the query, show "confirming", ask the channel's server.
- Build the server check: read the order's paid state (or the checkout status, or the signed callback).
- Test with Testing a channel: success, failure, never returned.
- Write it down: add the channel to the table in Build a sales channel and to
docs/static/channels/channel-contract.json. - Stop and ask before anything reaches a deployed stack.
What is not possible today
Do not promise these; they are listed in Gaps:
- A hosted-checkout payment returning the customer to the channel on production. On the current dev stack it has worked since 1 Dec 2026 with one manual step (Return to the channel): two test channels were paid through, but after 3-D Secure the return page had to be opened by hand, and that stack has no public address; production has neither the hosted checkout nor the registry, and only a person puts them there.
- A partner starting a hosted checkout with its own credential.
- Thai QR (direct) returning anywhere but the shop.
- Apple Pay's redirect fallback returning to a non-Villa origin.
- A server callback for anything other than
bypass_ordercard charges. - Hosted checkout or Apple Pay on production.
Useful commands
bd ready # work that is ready (this repository tracks tasks in beads)
cd functions/callback && python -m pytest tests --noconftest --ignore=tests/test_query_index.py
cd functions/checkout && python -m pytest tests
cd docs && npm ci && npm run build # this documentation