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:
2026-11-15 11:38:37 +02:00
co-authored by Claude Opus 5.5
parent 2541a5782e
commit 5bdd19d9fb
13 changed files with 539 additions and 41 deletions
+12 -3
View File
@@ -71,12 +71,21 @@ def get_menu(site_slug: str, db: Session = Depends(get_db)):
@router.post("/sync", response_model=MenuSyncResponse)
def sync_menu(body: MenuSyncRequest, site: Site = Depends(_require_site), db: Session = Depends(get_db)):
"""Upsert the menu snapshot for this site. Called by local_backend on each sync."""
snapshot = db.query(MenuSnapshot).filter(MenuSnapshot.site_id == body.site_id).first()
"""Upsert the menu snapshot for this site. Called by local_backend on each sync. Only the
authenticated site's own (before S.2 the body's site_id was trusted: one site could
overwrite another's menu)."""
if body.site_id != site.id:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Not this site's menu")
import json
try:
json.loads(body.snapshot_json)
except ValueError:
raise HTTPException(status_code=422, detail="snapshot_json is not JSON")
snapshot = db.query(MenuSnapshot).filter(MenuSnapshot.site_id == site.id).first()
if snapshot:
snapshot.snapshot_json = body.snapshot_json
else:
snapshot = MenuSnapshot(site_id=body.site_id, snapshot_json=body.snapshot_json)
snapshot = MenuSnapshot(site_id=site.id, snapshot_json=body.snapshot_json)
db.add(snapshot)
db.commit()
return MenuSyncResponse(ok=True)