Prototypes Prototype docsP11 · Docs and assistant
Ordering for a café (P17)
DocsPage 20 of 30

Ordering for a café (P17)

Havnekaffe is a café where a guest orders from the table. A code on the table opens the menu on the guest's phone, the kitchen's screen shows the order when the server has stored it, and the guest pays at the table with Stripe.

The menu and the order

The menu comes from the server with each item's options, its allergens and whether it is sold out. The guest chooses the options in a sheet, and the order stays on the phone until it is placed. The phone sends the items, the options and a key it made for this order. The server looks up each price in its own menu, so a price changed in the page has no effect. The same key sent again returns the order that is already stored, so a double tap or a retry after a lost answer makes one order.

The kitchen's screen

The kitchen's screen and the guest's phone keep a WebSocket to the café's server, a Durable Object that sleeps while nothing happens. The server sends a new order to the kitchen and to the table when it is stored, and it sends each change of status the same way. An order moves from new to in the making, ready and served, and a step back is refused. An item the kitchen switches off is shown as sold out on every open menu, and the server refuses new orders for it.

A screen that loses its connection tries again after a pause that doubles up to 8 seconds. When it is back it reads every open order, so it shows the orders placed while it was away.

Payment

The Pay button opens Stripe Checkout with the server's prices when STRIPE_SECRET_KEY is set. Only Stripe's webhook marks an order paid. The server checks its HMAC-SHA256 signature with the endpoint's secret, refuses a signature older than 5 minutes, and checks that the amount matches the order. An event sent twice changes nothing. Without a key the page says that Checkout is not set up, and a signed test event marks an order paid.

The codes for the tables

The Table codes page draws a QR code for each of the 12 tables with the address of the menu for that table. The codes are made on the page from its own address, so the codes printed from the deployed site open the deployed menu.

Not built

Anyone behind the portfolio's login can open the kitchen's screen. A café would sign the screen in with a passkey, as the club in P15 does.

Previous: Portfolio site (P16). Next: Stock scanner (P18).

How Prototype docs is built

The pages are written in Markdown and built into these pages and an index of 154 sections. The assistant answers from the index, and every answer names the sections it was taken from.