feat: reconcile paid mollie payments that left no local charge #65

Sammanfogat
supernaut sammanfogade 2 incheckningar från feat/mollie-reconcile in i main 2026-10-01 19:51:23 +00:00
Ägare

What

Reconcile Mollie payments that left no settled local charge.

  • After each 10-minute sweep, reconcile() lists Mollie payments from the last 14 days and replays each paid one with no settled local charge through handleWebhook. Dedupe, row locks and the duplicate-checkout guard apply unchanged. No new refund, cancel or grant logic.
  • Grant failed past Mollie's retries: repaired by the replay. The first period starts at the payment's paidAt, so periods and the withdrawal deadline match Mollie's schedule.
  • Mollie accepted the payment, local write failed: checkout now writes the pending charge before calling Mollie and sets metadata.subscriptionId. The webhook claims the charge by that reference only for a first payment with an exactly matching SEK amount. Any mismatch is flagged.
  • Orphan renewal: flagged only.
  • Anything not repaired logs [reconcile] <id> is paid at the provider with no settled local charge; needs manual review once per payment id.

Review fixes (00d3d20):

  • A refunded duplicate checkout now cancels its own Mollie subscription before the refund claim commits.
  • A payment refunded or charged back at Mollie is never adopted. Unreadable amounts fail closed.
  • A stale checkout is refunded when the customer has any newer non-incomplete subscription.
  • README: on a manual refund, also cancel the Mollie subscription.

Verification

  • Postgres 17: 258/258. Every new test fails with its fix removed.
  • Independent adversarial review twice. Second pass found no double charge, wrong refund or lost grant. Probed: cancel lands, then commit fails; the next pass ends with 1 refund, 1 cancel, 1 live subscription.
  • Merge #64 first so the DB tests run in CI on this PR.

Not done

  • No alert rule yet on the [reconcile] line.
  • The [webhook] ... left unprocessed lines still repeat on every pass.
  • A payment stuck past 14 days drops out silently.
  • Mollie subscriptions are not listed.

Refs #62

## What Reconcile Mollie payments that left no settled local charge. - After each 10-minute sweep, `reconcile()` lists Mollie payments from the last 14 days and replays each paid one with no settled local charge through `handleWebhook`. Dedupe, row locks and the duplicate-checkout guard apply unchanged. No new refund, cancel or grant logic. - **Grant failed past Mollie's retries:** repaired by the replay. The first period starts at the payment's `paidAt`, so periods and the withdrawal deadline match Mollie's schedule. - **Mollie accepted the payment, local write failed:** checkout now writes the pending charge before calling Mollie and sets `metadata.subscriptionId`. The webhook claims the charge by that reference only for a first payment with an exactly matching SEK amount. Any mismatch is flagged. - **Orphan renewal:** flagged only. - Anything not repaired logs `[reconcile] <id> is paid at the provider with no settled local charge; needs manual review` once per payment id. Review fixes (`00d3d20`): - A refunded duplicate checkout now cancels its own Mollie subscription before the refund claim commits. - A payment refunded or charged back at Mollie is never adopted. Unreadable amounts fail closed. - A stale checkout is refunded when the customer has any newer non-`incomplete` subscription. - README: on a manual refund, also cancel the Mollie subscription. ## Verification - Postgres 17: 258/258. Every new test fails with its fix removed. - Independent adversarial review twice. Second pass found no double charge, wrong refund or lost grant. Probed: cancel lands, then commit fails; the next pass ends with 1 refund, 1 cancel, 1 live subscription. - Merge #64 first so the DB tests run in CI on this PR. ## Not done - No alert rule yet on the `[reconcile]` line. - The `[webhook] ... left unprocessed` lines still repeat on every pass. - A payment stuck past 14 days drops out silently. - Mollie subscriptions are not listed. Refs #62
supernaut lade till 2 incheckningar 2026-10-01 18:31:12 +00:00
After each sweep, list Mollie payments from the last 14 days and replay
every paid one without a settled local charge through the webhook path.

- A first payment whose tier_pro grant failed past Mollie's retries is
  adopted on the next pass, and its renewals after it. The period is
  dated from the payment, not the replay.
- The checkout charge is written before Mollie is called, and the
  payment carries our subscription id. A lost providerRef write is
  claimed by that reference when the amount matches.
- Anything still unmatched is logged as needing manual review. No new
  automatic refund, cancel or grant.

Refs #62
fix: cancel a refunded duplicate's renewal and never adopt returned money
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m39s
00d3d201f8
- A replayed checkout that is refunded as a duplicate now cancels the
  provider subscription carrying its reference, so a renewal created by
  an earlier failed attempt cannot keep charging.
- A checkout is also refunded when the customer has any subscription
  started after it, not only a live one.
- A payment refunded or charged back at the provider before it was
  applied is left for review instead of granting and renewing.
- Each unmatched payment is logged for review once per process.
- Reconcile no longer depends on the provider's listing order.

Refs #62
supernaut tvångsskickade feat/mollie-reconcile från 00d3d201f8
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m39s
till d7b4376df8
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m58s
2026-10-01 19:48:56 +00:00
Jämför
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-01 19:49:06 +00:00
supernaut sammanfogade incheckning 46b331cb2e till main 2026-10-01 19:51:23 +00:00
supernaut tog bort grenen feat/mollie-reconcile 2026-10-01 19:51:23 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-01 21:26:09 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-01 21:45:03 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-02 17:57:02 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-payment!65
Ingen beskrivning angiven.