feat(cloud): the cloud prices online orders itself; sites only touch their own data (platform-v2 3S, S.2)
- services/checkout.py: orders and quotes priced from the site's snapshot per sales point
(prices map; older snapshots: digital_price less discount); refused: unavailable or
not sold there, bad quantity/option/type, empty, order.price_changed when the browser's
unit price or total differs. Nothing the browser says about money is stored.
- POST /api/orders/{site}/quote; delivery needs phone + address.
- Fixes: pending orders, menu sync and stats snapshot acted on the site_id given, not the
authenticated site (a site could read another's orders or overwrite its menu/stats).
- Order refs are unique per site (a second site's first order failed); tracking by a
random token GET /api/orders/track/{token}; old /status/{ref} only while unambiguous.
- Alembic 0003: online_orders sales_point, table_label, tracking_token; table rebuilt.
- menu-app: tracking link uses the token, shows the order number; tells the customer when
the menu changed or the order failed.
- Tests: test_checkout.py (6), 0003 data migration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,15 @@ export async function submitOrder(siteSlug, body) {
|
||||
return data // { order_id, public_ref, status }
|
||||
}
|
||||
|
||||
export async function fetchOrderStatus(publicRef) {
|
||||
const { data } = await api.get(`/api/orders/status/${publicRef}`)
|
||||
return data // { public_ref, status, rejection_reason }
|
||||
// The tracking link carries the order's random token (phase 3S, S.2); links from before that
|
||||
// carry the public ref and use the old endpoint.
|
||||
export async function fetchOrderStatus(ref) {
|
||||
try {
|
||||
const { data } = await api.get(`/api/orders/track/${ref}`)
|
||||
return data // { public_ref, status, rejection_reason }
|
||||
} catch (err) {
|
||||
if (err?.response?.status !== 404 || !/^ORD-\d+$/.test(ref)) throw err
|
||||
const { data } = await api.get(`/api/orders/status/${ref}`)
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ const I18N = {
|
||||
yourOrder: 'Your order', emptyCart: 'Your cart is empty',
|
||||
emptyCartSub: 'Add a few dishes to get started.',
|
||||
continue: 'Continue', placeOrder: 'Place order', sending: 'Sending…',
|
||||
orderChanged: 'Something on the menu changed since you opened it. Please reload the page and check your order.',
|
||||
orderFailed: 'The order could not be sent. Please try again.',
|
||||
orderPlaced: 'Order placed!', orderPlacedSub: 'Your order has been sent to the kitchen.',
|
||||
newOrder: 'Back to menu', table: 'Table no.', name: 'Your name',
|
||||
namePh: 'e.g. Alex', tablePh: 'e.g. 12', orderSummary: 'Order summary',
|
||||
@@ -44,6 +46,8 @@ const I18N = {
|
||||
yourOrder: 'Η παραγγελία σου', emptyCart: 'Το καλάθι σου είναι άδειο',
|
||||
emptyCartSub: 'Πρόσθεσε μερικά πιάτα για να ξεκινήσεις.',
|
||||
continue: 'Συνέχεια', placeOrder: 'Αποστολή παραγγελίας', sending: 'Αποστολή…',
|
||||
orderChanged: 'Κάτι άλλαξε στο μενού από τότε που το άνοιξες. Ανανέωσε τη σελίδα και έλεγξε την παραγγελία σου.',
|
||||
orderFailed: 'Η παραγγελία δεν στάλθηκε. Δοκίμασε ξανά.',
|
||||
orderPlaced: 'Η παραγγελία στάλθηκε!', orderPlacedSub: 'Η παραγγελία σου εστάλη στην κουζίνα.',
|
||||
newOrder: 'Πίσω στο μενού', table: 'Τραπέζι', name: 'Το όνομά σου',
|
||||
namePh: 'π.χ. Αλέξης', tablePh: 'π.χ. 12', orderSummary: 'Σύνοψη παραγγελίας',
|
||||
@@ -572,6 +576,7 @@ function SearchOverlay({ open, onClose, categories, lang, t, onOpen, onAdd, cart
|
||||
function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenProduct, siteSlug, navigate }) {
|
||||
const [form, setForm] = useState({ name: '', table: '' })
|
||||
const [sending, setSending] = useState(false)
|
||||
const [sendError, setSendError] = useState('')
|
||||
|
||||
const allProducts = useMemo(() => categories.flatMap(c => c.products), [categories])
|
||||
|
||||
@@ -593,6 +598,7 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
||||
|
||||
const submit = async () => {
|
||||
setSending(true)
|
||||
setSendError('')
|
||||
try {
|
||||
const result = await submitOrder(siteSlug, {
|
||||
order_type: 'dine_in',
|
||||
@@ -612,8 +618,12 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
||||
setCart({})
|
||||
setForm({ name: '', table: '' })
|
||||
setStage(null)
|
||||
navigate(`/${siteSlug}/confirm/${result.public_ref}`)
|
||||
} catch {
|
||||
// the cloud prices the order itself (phase 3S, S.2); the tracking link is the order's token
|
||||
navigate(`/${siteSlug}/confirm/${result.tracking_token ?? result.public_ref}`)
|
||||
} catch (err) {
|
||||
const code = err?.response?.data?.detail?.code
|
||||
setSendError(code === 'order.price_changed' || code === 'order.item_unavailable' || code === 'order.option_unavailable'
|
||||
? t.orderChanged : t.orderFailed)
|
||||
setSending(false)
|
||||
}
|
||||
}
|
||||
@@ -740,6 +750,7 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
||||
<span className="text-[13px] font-medium text-[#7d7660]">{t.total}</span>
|
||||
<span className="font-display text-[24px] font-semibold tabular-nums text-[#2d3b2d]">{eur(total)}</span>
|
||||
</div>
|
||||
{sendError && <p role="alert" className="mb-2.5 text-[13px] text-[#c2602f]">{sendError}</p>}
|
||||
<button
|
||||
disabled={!valid || sending}
|
||||
onClick={submit}
|
||||
|
||||
@@ -20,6 +20,7 @@ export default function OrderConfirm() {
|
||||
const { ref } = useParams()
|
||||
const [orderStatus, setOrderStatus] = useState(null)
|
||||
const [rejectionReason, setRejectionReason] = useState(null)
|
||||
const [publicRef, setPublicRef] = useState(null) // the link carries a token (S.2); show the order number
|
||||
const [error, setError] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -29,6 +30,7 @@ export default function OrderConfirm() {
|
||||
try {
|
||||
const data = await fetchOrderStatus(ref)
|
||||
setOrderStatus(data.status)
|
||||
setPublicRef(data.public_ref)
|
||||
setRejectionReason(data.rejection_reason)
|
||||
if (!TERMINAL.has(data.status)) {
|
||||
timer = setTimeout(poll, POLL_MS)
|
||||
@@ -65,7 +67,7 @@ export default function OrderConfirm() {
|
||||
|
||||
{/* Ref number */}
|
||||
<p className="mt-5 font-sans text-[11px] font-semibold uppercase tracking-[0.22em] text-[#b3aa90]">
|
||||
{ref}
|
||||
{publicRef ?? ''}
|
||||
</p>
|
||||
|
||||
{/* Status label */}
|
||||
|
||||
Reference in New Issue
Block a user