Files
253466097c billing: a refund of a quoted payment takes back the dollars credited, and a top-up intent is replayed only while it can be paid (#52)
Quoted clawback. A top-up paid in euros against a quote of 500 usd is credited 500 usd, but the
refund Stripe reports is in euros (462 eur), and clawback read that figure as dollars: a full refund
took 462 of the 500, leaving $0.38 of refunded money spendable. The payment's record now keeps the
quote (paidCents, paidCurrency, creditCents) when the settlement credits it, and a refund or a dispute
stated in the buyer's currency is converted to its proportional share of the credit: credit * refunded /
paid, rounded to the nearest cent, a full refund exactly the whole credit, never more than the credit
less what earlier ones took (read from the payment's own clawbacks), and a redelivery posts what was
recorded for its ref. A payment with no quote is untouched. A refund after a credit still posts one
reversal and never a second credit; replaying the event posts nothing more.

Finished-intent replay. POST /v1/billing/topup/intent without an idempotency key derived one from
(subject, amount, currency, country) per 15 minutes, so a second top-up of the same amount returned the
first intent after it had succeeded, and the browser's confirm failed with 400. A derived key now replays
an intent that can still be paid and only that: the buyer's unpaid intent for that amount comes back on a
double click; once it was paid, cancelled or is processing, a new intent is opened under a key numbered by
the intents already opened for that amount in the window.

Testing: quotedShare unit table; TestLiveStripe_AQuotedPaymentIsRefundedForTheDollarsItCredited (EUR quote,
card pay, full refund takes exactly 500, two half refunds sum to 500, replays post nothing) and
TestLiveStripe_AnIntentIsReplayedOnlyWhileItCanStillBePaid, both against Stripe test mode. Before the fix they
fail: the full refund took back 459 (the euro figure) of 500, and the repeat returned the finished intent.
Full api/billing, api/checkout, payment/... pass with Stripe test keys.
Risk: medium (billing). Only payments settled after this carry a recorded quote; an earlier euro payment
refunded after this release is still taken back at the euro figure.
How to revert: git revert this commit.

Co-authored-by: Hanzo Dev <[email protected]>
2026-11-13 19:06:42 -08:00
..