Skip to content

fix(shop): a late payment no longer eats another shopper's stock hold - #225

Merged
thunpisit merged 3 commits into
mainfrom
fix/reservation-order-link
Oct 25, 2026
Merged

thunpisit merged 3 commits into
mainfrom
fix/reservation-order-link

Conversation

@thunpisit

Copy link
Copy Markdown
Contributor

Phase 2.4. Closes #217 (server-side CART_EMPTY guard).

Bug

Holds expire after 15 min; a Beam QR is payable for 30 and a payment link for 60. A payment after the hold lapsed still committed by decrementing reserved, which had already been released, so it consumed another shopper's hold and left the counts low. Orders had no link to their holds, so markPaid couldn't tell.

Fix

Tests

4 integration tests (real migrations, SQLite): holds linked to the order; paid while held → 100/1 → 99/0; paid after lapse with another shopper holding 2 → 99/2 (was 99/1); extension survives the 20-min sweep and never shortens.
Gate: lint 0 errors · check 0 · 1165/1165 · build · contract-guard · css-inventory. 0035 applied cleanly with wrangler d1 migrations apply --local.

Rollout

Additive nullable column, safe to apply before deploying. bactrack's fork-local 0033_bactrack_order_methods doesn't conflict.

🤖 Generated with Claude Code

thunpisit and others added 3 commits October 25, 2026 19:25
Stock holds expire after 15 minutes, but a Beam QR is payable for 30
and a payment link for 60. When a customer paid after their hold had
lapsed, markPaid committed the sale by decrementing `reserved` anyway
— reserved that had already been given back, so it consumed another
shopper's hold and left the books low. Orders weren't linked to their
holds, so markPaid couldn't tell.

- Migration 0035: shop_inventory_reservations.order_id (+ index).
  checkout/start links the holds it took to the order.
- markPaid commits a linked hold that is still live as before (on_hand
  and reserved), and a lapsed one from on_hand only. Orders from before
  the migration keep the old path.
- checkout/pay extends the order's live holds to the charge's payment
  window (QR 30 min, link 60), so stock stays held while the customer
  can still pay. Never shortens a hold or revives a lapsed one.
- checkout/start refuses an empty cart up front with CART_EMPTY (#217)
  instead of failing later as INVALID_SHIPPING_METHOD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-link

# Conflicts:
#	src/plugins/shop/cart-service.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thunpisit
thunpisit merged commit 343f36c into main Oct 25, 2026
2 checks passed
@thunpisit thunpisit mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkout: retrying after a failed payment re-runs checkout/start against an empty cart

1 participant