feat(billing): keep chargeback evidence for every payment #107

Sammanfogat
supernaut sammanfogade 6 incheckningar från feat/chargeback-evidence in i main 2026-10-07 14:15:27 +00:00
Ägare

Refs #101

What

Keeps the evidence needed to answer a card chargeback, per payment.

  • charge: consent text version, time shown and page language (checkout charges), then paid_at, mandate_ref and card_security (Mollie details.cardSecurity, so the first payment's 3-D Secure result) once paid. Renewals record paid time and mandate too.
  • cancellation (new): each cancel and each withdrawal, with requested and effective time.
  • chargebackEvidence(db, paymentRef) returns consent, renewal choice, interval, first payment, cancellations and charge history for one payment.
  • Contract: optional consent on startCheckout (text, shownAt, language sv or en). Contract 0.8.0, service 0.7.0. Migration 0009 is additive.
  • README: new evidence list, and the note that renewals are merchant-initiated, run without 3-D Secure and carry no liability shift (accepted risk).

Not done

  • bitborg-web must send consent. Until it does, new charges have no consent and the issue stays open.
  • No retention rule beyond the existing seven-year record keeping.

Tests

Unit tests cover consent at checkout, cancel and withdrawal rows, renewal charge fields, the Mollie adapter fields and the assembled evidence for a renewal chargeback. Full suite runs against Postgres 17.

Follow-up commit

  • Tests: a replayed paid webhook leaves paid_at, mandate_ref and card_security unchanged; a repeated withdraw adds no row; cancel then withdraw gives two rows; the refund path without a reusable method records evidence.
  • README: the operator reads the evidence from the chargeback row (see below). Charges paid before migration 0009 have no evidence fields and are not backfilled. Evidence is kept 7 years with the invoice records.

Follow-up commits

  • Contract: consent.textVersion becomes consent.text (1 to 2000 characters), with language and shownAt unchanged. The contract stays at 0.8.0.
  • The service hashes the text (sha256, hex) and stores each distinct text once in consent_text. charge.consent_text_hash points at it, and chargebackEvidence returns the full text.
  • Migration 0009 is regenerated, not followed by a 0010, because it is still only on this branch.

Snapshot the evidence on each chargeback

  • When a chargeback is first recorded, chargebackEvidence for the payment is stored in the new chargeback.evidence column (jsonb), in the same transaction. This also covers a reversal that arrives first.
  • A replay or reversal does not overwrite it.
  • If building it fails, the row is saved with null evidence and an evidence not stored review. The chargeback is still applied.
  • The needs manual review line says when the evidence is on the row.
  • README: read it with SELECT evidence FROM chargeback WHERE provider_ref = '<id>';. Evidence is kept seven years with the invoice records.
  • The new column is in the regenerated 0009.
Refs #101 ## What Keeps the evidence needed to answer a card chargeback, per payment. - `charge`: consent text version, time shown and page language (checkout charges), then `paid_at`, `mandate_ref` and `card_security` (Mollie `details.cardSecurity`, so the first payment's 3-D Secure result) once paid. Renewals record paid time and mandate too. - `cancellation` (new): each cancel and each withdrawal, with requested and effective time. - `chargebackEvidence(db, paymentRef)` returns consent, renewal choice, interval, first payment, cancellations and charge history for one payment. - Contract: optional `consent` on `startCheckout` (`text`, `shownAt`, `language` sv or en). Contract 0.8.0, service 0.7.0. Migration 0009 is additive. - README: new evidence list, and the note that renewals are merchant-initiated, run without 3-D Secure and carry no liability shift (accepted risk). ## Not done - bitborg-web must send `consent`. Until it does, new charges have no consent and the issue stays open. - No retention rule beyond the existing seven-year record keeping. ## Tests Unit tests cover consent at checkout, cancel and withdrawal rows, renewal charge fields, the Mollie adapter fields and the assembled evidence for a renewal chargeback. Full suite runs against Postgres 17. ## Follow-up commit - Tests: a replayed paid webhook leaves `paid_at`, `mandate_ref` and `card_security` unchanged; a repeated withdraw adds no row; cancel then withdraw gives two rows; the refund path without a reusable method records evidence. - README: the operator reads the evidence from the chargeback row (see below). Charges paid before migration 0009 have no evidence fields and are not backfilled. Evidence is kept 7 years with the invoice records. ## Follow-up commits ### Store the consent text as shown, keyed by its hash - Contract: `consent.textVersion` becomes `consent.text` (1 to 2000 characters), with `language` and `shownAt` unchanged. The contract stays at 0.8.0. - The service hashes the text (sha256, hex) and stores each distinct text once in `consent_text`. `charge.consent_text_hash` points at it, and `chargebackEvidence` returns the full text. - Migration 0009 is regenerated, not followed by a 0010, because it is still only on this branch. ### Snapshot the evidence on each chargeback - When a chargeback is first recorded, `chargebackEvidence` for the payment is stored in the new `chargeback.evidence` column (jsonb), in the same transaction. This also covers a reversal that arrives first. - A replay or reversal does not overwrite it. - If building it fails, the row is saved with null evidence and an `evidence not stored` review. The chargeback is still applied. - The `needs manual review` line says when the evidence is on the row. - README: read it with `SELECT evidence FROM chargeback WHERE provider_ref = '<id>';`. Evidence is kept seven years with the invoice records. - The new column is in the regenerated 0009.
supernaut lade till 1 incheckning 2026-10-07 08:07:45 +00:00
feat(billing): keep chargeback evidence for every payment
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m51s
c4499d10a8
Record the consent shown at checkout, paid time, mandate and card
security result per charge, and each cancel or withdrawal with its
effective time. chargebackEvidence assembles the answer for one payment.

The consent input is optional, so existing callers keep working.

Refs #101
supernaut lade till 4 incheckningar 2026-10-07 09:10:07 +00:00
supernaut lade till 1 incheckning 2026-10-07 14:06:32 +00:00
Merge remote-tracking branch 'origin/main' into feat/chargeback-evidence
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m15s
28e3546c03
supernaut sammanfogade incheckning ec54bf4ac0 till main 2026-10-07 14:15:27 +00:00
supernaut tog bort grenen feat/chargeback-evidence 2026-10-07 14:15:28 +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!107
Ingen beskrivning angiven.