fix(payments): close the double-refund path and price in the core #13
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!13
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "fix/refund-idempotency"
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?
Six issues, each written test-first with the red run observed before the fix.
Tracked in the other private repo, so these cannot be closed by keyword from here and must be closed by
hand when this merges: gitborg/gitborg-internal#53, #54, #50, #46, #49, #52.
#53 — refund could double-charge
All three defects the issue names:
paymentRefunds.create, deriveddeterministically by
refundIdempotencyKey. It is a digest rather than a composed string,because the provider caps the key at 40 characters and a silently truncated key stops deduping —
which is the failure this fix exists to prevent.
refundtable withidempotency_key UNIQUEand a uniqueprovider_refund_ref.pending | succeeded | failedwithproviderRefundRef, andgetRefundStatusis added. Unknown provider states map topending,never to a confirmed outcome — the old code reported
failedforqueued,pendingandprocessing, which is how a refund that is actually in flight gets retried.#54 —
provider_eventswallowed refund webhooksPremise confirmed, and #53 did change the shape of the fix: with a local refund row keyed to a provider
refund ref, keying events off the refund object — the issue's preferred option — composes cleanly.
parseCallbacknow returnsProviderEvent[], with refunds and chargebacks emitted as their own eventskeyed
re_1:refunded/chb_1:open|reversed. Sub-resources are only listed when the payment actuallycarries the field, so an ordinary webhook still costs one API call.
Chargebacks were adjacent rather than in scope ("likely the same shape"), and are included: they are
silently dropped for exactly the same reason.
#50, #46, #49, #52
cannot leave an orphan;
last4was storing the full number and is now sliced.startCheckoutresolves VAT and price in the core and hands the adapter a bareamountMinor. The adapter'sPLANSimport,amountMinorForand theorg_seatthrow are gone, whichis what closed the VAT gap. Seat cases are covered: SE B2B 3 seats, DE B2B validated at 0% reverse
charge (explicitly not Swedish VAT), DE B2C under OSS, NO VOEC. A test asserts no VAT context
crosses the adapter boundary and that pricing fails closed before any provider call.
(
String(amountMinor / 100)in place oftoFixed): 1 test failed before the new tests, 10 after.Adds the öre→decimal table on both paths, the full subscription lifecycle including the
customerId:subscriptionIdround trip and its malformed-ref refusals, everygetStatusbranch, andpins the inclusive-plan-at-0%-VAT commercial consequence.
vat_rate→vat_rate_bps.money.tsnow refuses negative and non-integer amounts and documentsroundHalfUp's exact range;add-on names are validated before they can become group names.
Migration SQL, reviewed rather than trusted
drizzle/0002_parched_zzzax.sqlis twoRENAME COLUMNs, sixCREATE INDEX, and the partial uniqueindex with
WHERE "seat_assignment"."released_at" is null. No drops and no data movement. Therenamed columns were already
integerholding basis points — the unit was previously only in a comment,so this moves it into the name where it travels with the value. Generated by driving drizzle-kit's rename
prompt (it needs a TTY); "rename" was chosen, not create/drop.
Verified
pnpm test166 passed / 11 files ·pnpm -r typecheckclean ·pnpm eslintclean ·pnpm format:checkclean ·pnpm drizzle-kit check"Everything's fine" ·pnpm -r buildclean.Coverage 96.17% statements, 100% branch. Each commit also passes its own suite in isolation
(84 / 90 / 93 / 102 / 144 / 166).
Three things to know before this is relied on
refund.idempotency_key UNIQUEandrefundIdempotencyKeyhave no non-test caller until the refund/webhook handler is built. Therequired order is documented in both
refunds.tsandschema.ts: insert the local row first, andcall the provider only if that insert succeeded. Getting that order wrong reopens #53 with the
table in place.
ent_*, excludingtier_*andidm_*so an add-on string can nevergrant a tier or an admin group. That mirrors ADR 0016's naming; if the real add-on group names
differ, relax the pattern.
parseCallbackemits chargeback events but there is nochargebacktable or handler yet —filed separately.
Left out deliberately
#50's
Containerfileitems (the issue folds them into deploy-role work) and theminimumReleaseAgeExcludeguard (supply-chain config, not correctness); #52'spayment_method.statusenum (needs Mollie's real mandate vocabulary — documented as text for now),gapless invoice numbering (needs a design), and the retention /
ON DELETEADR, which belongs inthe public docs repo. The
ON DELETEdecision is documented inschema.tsand guarded by a test.The design document needs updating for the interface changes here; that is a separate docs change.