Skip to main content

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

  1. 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 grandTotal in a POST /cardpayment form must be the order's own total (the server's figure is what is charged).
  2. Treat the return URL as a hint. Confirm on the channel's server before showing "paid".
  3. Handle three endings: success, failure, and the customer who never returns.
  4. Send callback as a base only: https://host or scheme://path.
  5. Run the callback tests after any change under functions/callback or functions/cardtoken.

Never

  1. Never mark an order paid from a browser parameter.
  2. Never log a card token, a gateway body, a key, a link token or a signing secret.
  3. Never use bypass_order on production without a person's approval.
  4. Never route Visa, Mastercard or Thai QR through Stripe. Stripe is Apple Pay only.
  5. Never deploy, merge to master, create or change a secret, or change a gateway's configuration. Ask a person. Merging to master deploys production.
  6. 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​

ConcernFile
Card charge, stores callbackfunctions/cardtoken/app.py
Browser return after 3-D Securefunctions/callback/callback.py
Return address rulesfunctions/callback/src/payment_redirect.py and its copy in functions/cardtoken/src/
Builds the return URLfunctions/callback/src/credit_card_callback_processor.py
K Bank server notifyfunctions/callback/notify.py, delayednotify.py
Thai QRfunctions/kbankcreateorder/createorder.py, functions/callback/qrcallback.py, qrnotify.py
Amexfunctions/callback/amexcallback.py, src/callback_signature.py
Apple Payfunctions/stripe/confirm.py, webhook.py, src/stripe_client.py
Hosted checkoutfunctions/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 overfunctions/callback/src/checkout_bridge.py
Marks an order paid, oncefunctions/processPaidOrder/
Routes and permissionstemplate.yaml

Add a channel: the checklist​

  1. Name it. A short id (kiosk), its return base, and where its orders live. For the hosted checkout, check them with python3 channel-kit/channel.py validate (Launch a shop).
  2. Pick the path with the tree above.
  3. Build the pay step from the Quickstart.
  4. Build the return screen: parse the query, show "confirming", ask the channel's server.
  5. Build the server check: read the order's paid state (or the checkout status, or the signed callback).
  6. Test with Testing a channel: success, failure, never returned.
  7. Write it down: add the channel to the table in Build a sales channel and to docs/static/channels/channel-contract.json.
  8. 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_order card 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