fix(billing): flag a refund that fails at the provider #154

Sammanfogat
supernaut sammanfogade 3 incheckningar från fix/140-refund-failed-flag in i main 2026-10-12 14:52:27 +00:00
Ägare

What

A refund that reaches failed at Mollie now logs
[reconcile] refund <id> failed at the provider; customer still owed; needs manual review.

Why

Nothing flagged it. The refund cannot be issued again: claimRefund keys on charge and amount, and the adapter returns the failed Mollie refund for that key. The customer stayed owed with no signal.

How

  • flagIfReowed becomes flagFailedRefund. It logs, then flags a re-owed chargeback as before.
  • Both paths that move a refund to failed call it: issueRefund and the sweep. Both move from pending, so it logs once per refund.
  • The line matches the BillingReconcileManualReview matcher (\[reconcile\].*needs manual review).
  • The sweep update is guarded with status = pending and logs only when a row moved. A refund another writer already moved does not log, and concurrent sweeps cannot log twice.
  • No line while a chargeback is open on the charge: the bank already returned the money.
  • The README documents the manual steps: check the payment's refunds in Mollie, else pay by bank transfer and note it on the Mollie payment.

Tests

Four new tests: failure on issue, failure seen by the sweep (logged once over two sweeps), a refund already moved by another writer, and an open chargeback. The last two fail without the guards.

Test harness

The test pool also gets an error listener. pg-pool re-emits an idle client's error on the pool, so the 57P01 from DROP DATABASE ... WITH (FORCE) could still fail a run after every test passed.

Closes #140

## What A refund that reaches `failed` at Mollie now logs `[reconcile] refund <id> failed at the provider; customer still owed; needs manual review`. ## Why Nothing flagged it. The refund cannot be issued again: `claimRefund` keys on charge and amount, and the adapter returns the failed Mollie refund for that key. The customer stayed owed with no signal. ## How - `flagIfReowed` becomes `flagFailedRefund`. It logs, then flags a re-owed chargeback as before. - Both paths that move a refund to `failed` call it: `issueRefund` and the sweep. Both move from `pending`, so it logs once per refund. - The line matches the `BillingReconcileManualReview` matcher (`\[reconcile\].*needs manual review`). - The sweep update is guarded with `status = pending` and logs only when a row moved. A refund another writer already moved does not log, and concurrent sweeps cannot log twice. - No line while a chargeback is open on the charge: the bank already returned the money. - The README documents the manual steps: check the payment's refunds in Mollie, else pay by bank transfer and note it on the Mollie payment. ## Tests Four new tests: failure on issue, failure seen by the sweep (logged once over two sweeps), a refund already moved by another writer, and an open chargeback. The last two fail without the guards. ## Test harness The test pool also gets an `error` listener. pg-pool re-emits an idle client's error on the pool, so the `57P01` from `DROP DATABASE ... WITH (FORCE)` could still fail a run after every test passed. Closes #140
supernaut lade till 2 incheckningar 2026-10-12 14:13:12 +00:00
A refund that reaches failed at Mollie was stored and nothing else
happened. It cannot be issued again, because the idempotency key finds
the failed refund. The customer stays owed.

Log a manual-review line on every move to failed, from both issueRefund
and the sweep. The existing BillingReconcileManualReview alert matches
it. Document the manual refund step in the README.

Closes #140
fix(billing): log a failed refund only on its own move from pending
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m3s
97b3100702
Guard the sweep update with status pending and log only when a row
moved. A refund another writer already moved no longer logs, and
concurrent sweeps cannot log twice.

Skip the customer-still-owed line while a chargeback is open on the
charge, since the bank already returned the money. Document the manual
payment steps in the README.

Closes #140
supernaut tvångsskickade fix/140-refund-failed-flag från 97b3100702
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m3s
till dbd0232a23
En del kontroller misslyckades
ci / ci (pull_request) Failing after 1m12s
2026-10-12 14:45:47 +00:00
Jämför
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-12 14:46:02 +00:00
supernaut lade till 1 incheckning 2026-10-12 14:49:42 +00:00
test: ignore the pool error when a test database is dropped
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m14s
17b283b751
pg-pool re-emits an idle client's error on the pool. The pool had no
error listener, so the 57P01 from DROP DATABASE WITH (FORCE) still
failed the run after every test passed.
supernaut sammanfogade incheckning 70235394f5 till main 2026-10-12 14:52:27 +00:00
supernaut tog bort grenen fix/140-refund-failed-flag 2026-10-12 14:52:27 +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!154
Ingen beskrivning angiven.