feat: revoke tier_pro and stop renewal on a chargeback #75
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
priority
high
priority
low
priority
medium
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-payment!75
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "feat/16-chargeback-revoke"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
What
Handles a Mollie chargeback before live keys.
tier_pro(samerevokepath as withdrawal and the sweep), cancels the Mollie subscription and sets the subscription tocanceled. The provider subscription is not cancelled again whencancel()already stopped it. Only the charge's own subscription is touched.revokestill keeps the tier while another live subscription grants it.chargebacktable (migration 0006), one row per Mollie chargeback id. The UNIQUE ref makes a replay a no-op, even when theprovider_eventrow is missing.FOR NO KEY UPDATE, then the subscriptionFOR UPDATE, both before the refund check. That is the order a first payment uses. NO KEY UPDATE does not conflict with the key share a withdrawal's refund insert takes, so a concurrent withdrawal and chargeback serialise on the subscription and each sees the other's write. Both deadlocks found in review (vs withdrawal, vs first payment) have a test.failed) by the chargeback, andissueRefundnow sends only pending refunds, so the sweep cannot return the money twice. The chargeback row keeps the ids. Once every chargeback on the subscription is reversed, those still cancelled (failed, never sent) go back to pending and the sweep sends them. If the provider then fails one, the chargeback is flagged again.chargeback.reversed): once every chargeback on the subscription is reversed, and one of them ended it, the subscription goes back toactivewithcancelAtPeriodEndandtier_prois granted again, if the paid period still runs and no newer or live subscription exists. The sweep ends it at period end. Otherwise the reversal is flagged for review.\[reconcile\].*needs manual review): one per event, plus a summary each reconcile pass untilreviewed_atis set. README documents the operator step.charged_backreason. Contract bumped to 0.5.0 (main's dunning took 0.4.0).amountChargedBackas present only while non-zero, so a full reversal was invisible.listChargebacks(since). Reconcile replays each chargeback from the last 14 days that is not recorded locally (a lost webhook on a settled payment). A failed listing is logged and the unreviewed summary still prints.Why
Refs #16. A chargeback was stored in
provider_eventand dropped. The customer kepttier_proand Mollie kept renewing on a disputed mandate.How tested
Tests first. Each new one failed before its fix. The withdrawal race test hit a Postgres deadlock before the lock order change.
cancel().charged_back.amountChargedBack.listChargebackswindow.pnpm test --coverageagainst a throwaway Postgres 17: 16 files, 293 tests passed (4 runs). WithoutTEST_DATABASE_URL: 224 passed, 69 skipped.pnpm lint,pnpm -r --include-workspace-root typecheck,pnpm drizzle-kit check, build: clean.Merge note
Merged with main after dunning (#74):
contract/src/index.tsadds onlycharged_backon top of main, README "Absent" keeps both sides, contract 0.5.0. 311/311 tests pass against Postgres 17.Open questions