Skip to content

feat(beam): confirm payments by asking Beam; QR expiry/failure states; retry reuses the order - #223

Merged
thunpisit merged 2 commits into
mainfrom
fix/beam-reconcile
Oct 25, 2026
Merged

thunpisit merged 2 commits into
mainfrom
fix/beam-reconcile

Conversation

@thunpisit

Copy link
Copy Markdown
Contributor

Phase 2.3 of the bactrack.in.th Beam work. Closes #218 and #217 (client side). Stacked on #222: merge that first; this PR then retargets to main.

What changes

  • Status endpoint asks Beam while an order is pending (1 lookup / 10 s / order) and settles via settleBeamPayment. Gated on order access (placing browser's cookie, or the order email in x-order-email); anyone else gets the stored status and causes no outbound call. Response gains charge: pending|failed only.
  • Cron sweep reconciles pending Beam orders from the last 3 h (25/tick) before releasing reservations.
  • Checkout QR states: waiting / expired / failed; the last two hide the dead code and offer Create a new QR on the same order (fresh attempt).
  • Checkout: retrying after a failed payment re-runs checkout/start against an empty cart #217: checkout remembers the order from its first start; a retry goes straight to /checkout/pay.
  • Order page stops confirming as soon as Beam reports the charge failed.

Tests

  • Integration through the real status route and sweep (6): viewer poll settles with no webhook; stranger poll causes zero Beam calls; failed reported not cancelled; amount mismatch refuses; throttle; sweep lookback.
  • Unit (4).
  • Gate: lint 0 errors · check 0 · 1156/1156 · build · contract-guard · css-inventory +1.

End-to-end against a local fake Beam (BEAM_BASE_URL → node stub)

  • PromptPay: QR → FAILED → Create a new QR (<orderId>:qr:<attempt>, no 412) → SUCCEEDED → paid order page, no webhook sent.
  • Card: link id stored; retry without attempt → 412 (the old order-page behaviour), with attempt → new link; PAID link settles via sourceId charge and stores the real charge id.

Known gap (next PR)

Reservations expire at 15 min, while a QR is payable for 30 and a link for 60. A late payment decrements reserved that was already released. The fix needs a migration (orders aren't linked to reservations).

🤖 Generated with Claude Code

…; retry reuses the order

Payment confirmation depended entirely on Beam's webhook (#218). If it
was late, misconfigured or never registered, a paid order stayed
pending and the customer watched a spinner until a 2-minute cap — then
was offered to pay again.

- The order-status endpoint now asks Beam directly while an order is
  pending (throttled to once per 10s per order) and settles through
  settleBeamPayment. Only for a caller who may view the order — the
  placing browser's cookie, or the order email in `x-order-email` —
  so walking order numbers can't make the store call Beam. The
  response gains `charge: "pending" | "failed"`; nothing else.
- The cron sweep reconciles pending Beam orders from the last 3 hours
  (25 per tick) before releasing anything, for payments nobody is
  watching.
- Checkout QR has waiting / expired / failed states. Expired and failed
  hide the dead code and offer "Create a new QR" on the same order with
  a fresh `attempt` (#219). The "I've paid" button becomes a small
  fallback link, since polling moves on by itself.
- Checkout remembers the order from its first successful start; a retry
  after a payment failure goes straight to /checkout/pay (#217).
- The order page stops "confirming" as soon as Beam reports the charge
  failed, and offers the retry.

Verified against a local fake Beam: QR fail → new QR (`:qr:<attempt>`)
→ paid with no webhook; card link retried with and without `attempt`
(412 vs new link); a PAID link settles via the charge found by
sourceId, which replaces the stored link id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thunpisit
thunpisit changed the base branch from fix/beam-provider to main October 25, 2026 12:11
@thunpisit
thunpisit merged commit c6d1793 into main Oct 25, 2026
2 checks passed
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.

Payment confirmation depends solely on the Beam webhook — add a direct charge-status check

1 participant