Repository navigation
Billing: checkout idempotency, packs paid later, refunds and disputes, narrower problem clearing, plan change email (sc-9146) - #215
Merged
Conversation
…y by what caused them, plan change email with the change (sc-9146) - Team Checkout sends an idempotency key per organization and half hour, with the session's expiry fixed to the window, so two tabs get one session instead of two subscriptions. - checkout.session.async_payment_succeeded credits a pack paid by a method that settles later; before, it was never credited. - invoice.paid clears only the problem that invoice caused (its own failed payment; a subscription invoice also the failed or unpaid renewal), and turning automatic packs on clears only a declined pack or failed invoice, not a second subscription or a project that left the open source pool. - The plan change email is recorded in the transaction that changes the plan (notify::queue_in): queued after the commit, a failure lost it for good, since Stripe's retry found the plan already changed.
…t (sc-9146) terms.md promises it; nothing did it. charge.refunded takes back the refunded share of the pack's credits, charge.dispute.created all of them, and a dispute won gives back what it took beyond any refund's share. A charge is traced to its pack through Stripe (its Checkout session, or its automatic pack's invoice). credit_reversals records each charge's refunded share and open dispute, so every retry and later event takes only the difference, and credits already spent are forgiven once instead of taken from a pack bought later.
…matic pack (sc-9146) The API's and MCP's finalize ran stop_if_out_of_credits, whose CreditsRanOut listener buys an automatic pack: up to 15 Stripe calls inside the request. Finalizing now fails the build at once only when no automatic pack could help; when one could, the build stays processing and its job, which checks again before comparing anything, buys it.
ndbroadbent
force-pushed
the
billing-should-fix
branch
from
December 4, 2026 17:31
1f2503c to
a517c4e
Compare
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.
Part of the sc-9146 should-fix list.
Idempotency-Key: visualci-team-checkout-<org>-<half hour>and anexpires_atat the end of the next half hour, so every call in a window is the same request. Two tabs or a double click get one session, not two subscriptions. The webhook's two-subscriptions notice stays as the backstop. One edge case: someone who cancels Team and resubscribes within the same half hour gets the finished session back, and can retry 30 minutes later.notify::queue_in). Before, it was queued after the commit, and if queueing failed the email was lost for good, because Stripe's retry found the plan already changed.Stripe setup: the webhook endpoint must also subscribe to
checkout.session.async_payment_succeeded(docs/deploy.md updated). Until it does, nothing changes for card payments.Tests (app/tests/billing.rs): three of the new tests fail on main (pack paid later, the invoice settling only its own problem, auto packs clearing only their own). The email test guards the dedupe on a replayed event; a failed queue can't be simulated. The checkout tests check that the key and the body are the same across two calls.
charge.refundedtakes back the refunded share of the pack's credits,charge.dispute.createdall of them, and a won dispute gives back whatever it took beyond a refund's share. A charge is traced to its pack through Stripe (the Checkout session for its payment intent, or the automatic pack's invoice). A new table,credit_reversals, records each charge's refunded share and whether a dispute is open, so retries take nothing and a partial refund takes only its part. The balance never goes below zero: credits already spent are forgiven, once, rather than taken from a pack bought later. The Stripe key needs read access to Charges, Checkout Sessions and Invoices; a lookup that fails answers 500, and Stripe retries.Tests for refunds: a refund taken once, never more than is left, traced to automatic packs, subscriptions skipped, a dispute won and lost, a refund during a dispute.
The Stripe events are on Nathan's Tasks (sc-9384).
Still to do in sc-9146: the allowance per billing period (a product question, with the coordinator).
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.