Repository navigation
fix(beam): confirm card payments, allow payment retries, stop cancelling on a failed charge - #222
Merged
Merged
Conversation
…ing on a failed charge Four Beam integration bugs, found on bactrack.in.th (#217–#219): - Card / hosted-page payments were never confirmed. createCharge read `paymentLinkId` but POST /payment-links returns `{id, url}`, so no link id was stored; and `payment_link.paid` ({status: "PAID", order: {referenceId, netAmount}}) normalized to "pending" and was ignored. Both fixed; the test fixture now uses Beam's real shape. - Any second payment link or QR for an order failed (#219). The key was fixed per order while the body carries a fresh expiry, so Beam answered 412 for the key's 12h retention — the order page's "complete payment" button could never work. ChargeInput.attempt scopes the key (`<orderId>:link:<attempt>`, `<orderId>:qr:<attempt>`); first tries keep their old keys. /checkout/pay validates and passes it; the order page sends a fresh one per press. - charge.failed cancelled the order. A declined card retried on the hosted page, or a new QR after the first expired, then paid an order that markPaid ignores once cancelled: customer charged, order cancelled, stock released. A failure is now logged only; unpaid orders are released by the reservation sweep. - Payment side effects are extracted into settleBeamPayment (shared with the upcoming status check, #218) behind checkSettlement, which refuses an amount or reference that doesn't match the order. The purchase analytics event is now winner-only like the receipt (it was recorded once per webhook redelivery). A payment landing on a cancelled/refunded order is logged as an error for manual action. Adds PaymentProvider.getChargeStatus (Beam: charge, falling back to payment link → its SUCCEEDED charge), used by the next PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2.2 of the bactrack.in.th Beam work. Closes #219; groundwork for #218.
Bugs fixed
createChargereadpaymentLinkId;POST /payment-linksreturns{id, url}(OpenAPICreatePaymentLinkResponse), so no link id was ever stored. The test fixture used the wrong shape too, which is why tests passed.payment_link.paid({paymentLinkId, status:"PAID", order:{netAmount, referenceId}}) normalized topendingand was ignored. It now normalizes tosucceededwith the nested reference/amount.ChargeInput.attemptscopes the key (<orderId>:link:<a>,<orderId>:qr:<a>; first tries unchanged)./checkout/payvalidates^[A-Za-z0-9-]{1,40}$; the order page sends a fresh attempt per press.charge.failedcancelled the order (found while porting, not in the issues). A declined card retried on Beam's page, or a new QR after the first expired, then landed on a cancelled order, whichmarkPaidignores: customer charged, order cancelled, stock released. Failure is now logged only; the reservation sweep releases unpaid orders.succeededblock moved verbatim intosettleBeamPayment(reused by the status check in the next PR), behindcheckSettlement(amount + reference must match). Thepurchaseanalytics event is now winner-only like the receipt; it used to be recorded once per redelivery. Payment on a cancelled/refunded order logs an error for manual refund/reinstate.Also adds
PaymentProvider.getChargeStatus(Beam:GET /charges/{id}, 404 →GET /payment-links/{id}, PAID →GET /charges?sourceId=for the real charge id). Never throws; an error isok:false, neverfailed.Tests
beam-v460.test.ts(12): keys with/without attempt, wire headers,payment_link.paidshape,charge.failed, getChargeStatus (charge / link PAID→charge / EXPIRED·DISABLED·VOIDED / ACTIVE / 500 / network / empty id), checkSettlement.payment_link.paidsettles; amount mismatch → 200settled:false, still pending; redelivered success → one purchase event.Not yet verified
Real Beam Playground: the
payment_link.paidpayload is from Beam's docs, not a captured delivery. The Playground smoke in the test plan covers it.🤖 Generated with Claude Code