fix(billing): cancel a pending provider refund when a chargeback lands #153

Sammanfogat
supernaut sammanfogade 2 incheckningar från fix/141-cancel-pending-refund in i main 2026-10-12 14:44:17 +00:00
Ägare

fix(billing): cancel a pending provider refund when a chargeback lands

A withdrawal refund created at Mollie is held for about two hours. A chargeback in that window left the refund to execute, so the customer was paid twice.

applyChargeback now checks each sent refund on the charge. If the provider reports it as pending, it calls the new cancelRefund, marks the refund failed and adds it to cancelledRefundIds. If the status is failed (a replay after a rollback, when the provider already cancelled it), the refund is marked failed without a second cancel. If the status is succeeded, or the cancel throws, the existing "charged back after a refund" review flag stays as the fallback.

  • PaymentProvider.cancelRefund added, with the Mollie adapter (DELETE /v2/payments/{paymentId}/refunds/{refundId}) and the refuse stub.
  • The provider call runs inside the chargeback transaction, as cancelSubscription already does there.
  • Mollie processing maps to pending. The cancel is refused there, so it falls back to the review flag.
  • A failed cancel adds "cancel of refund failed" to the chargeback review.
  • A cancelled sent refund is not re-owed when the chargeback is reversed (the idempotency key would replay the cancelled refund). The reversal re-flags the chargeback as needing a manual re-issue, even if it was already reviewed.

Closes #141

fix(billing): cancel a pending provider refund when a chargeback lands A withdrawal refund created at Mollie is held for about two hours. A chargeback in that window left the refund to execute, so the customer was paid twice. `applyChargeback` now checks each sent refund on the charge. If the provider reports it as pending, it calls the new `cancelRefund`, marks the refund failed and adds it to `cancelledRefundIds`. If the status is `failed` (a replay after a rollback, when the provider already cancelled it), the refund is marked failed without a second cancel. If the status is `succeeded`, or the cancel throws, the existing "charged back after a refund" review flag stays as the fallback. - `PaymentProvider.cancelRefund` added, with the Mollie adapter (`DELETE /v2/payments/{paymentId}/refunds/{refundId}`) and the refuse stub. - The provider call runs inside the chargeback transaction, as `cancelSubscription` already does there. - Mollie `processing` maps to `pending`. The cancel is refused there, so it falls back to the review flag. - A failed cancel adds "cancel of refund <id> failed" to the chargeback review. - A cancelled sent refund is not re-owed when the chargeback is reversed (the idempotency key would replay the cancelled refund). The reversal re-flags the chargeback as needing a manual re-issue, even if it was already reviewed. Closes #141
supernaut lade till 2 incheckningar 2026-10-12 14:11:48 +00:00
applyChargeback only cancelled refunds never sent to the provider. A
refund already created at Mollie but not yet executed was flagged for
review, so the customer could be paid twice.

Add cancelRefund to the provider interface and the Mollie adapter. A
sent refund the provider reports as pending is cancelled and marked
failed. Any other status, or a failed cancel, keeps the review flag.

Closes #141
fix(billing): make the refund cancel on chargeback replay-safe
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m4s
37a7ac22f6
A rollback after the provider cancelled left the refund pending, and the
replay read the cancelled refund as failed and skipped it. Cancel only
when the status is pending, then mark any non-succeeded refund failed.
Record a failed cancel in the review. Re-flag a reversal that cannot
re-owe a provider-cancelled refund.

Refs #141
supernaut tvångsskickade fix/141-cancel-pending-refund från 37a7ac22f6
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m4s
till 5241d39329
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m8s
2026-10-12 14:41:31 +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:41:34 +00:00
supernaut sammanfogade incheckning 393050d00e till main 2026-10-12 14:44:17 +00:00
supernaut tog bort grenen fix/141-cancel-pending-refund 2026-10-12 14:44:17 +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!153
Ingen beskrivning angiven.