withdrawal: make a double submit record one request and send one receipt #325

Stängd
öppnade 2026-10-08 21:12:38 +00:00 av supernaut · 0 kommentarer
Ägare

What

processWithdrawal checks for an open request, then inserts one. Two concurrent requests both insert.

Why

The right of withdrawal is a consumer-law flow. Two rows mean two billing calls and two receipts. The audit trail is ambiguous.

Failing case

Send two concurrent POSTs to /api/withdraw for one account with one paid purchase. Two withdrawal_requests rows exist and two receipt mails go out.

Fix

  • Add a partial unique index on withdrawal_requests(sub) WHERE withdrawn_at IS NULL AND rejection IS NULL.
  • On a unique violation, re-read and reuse the open row.
  • Send the receipt only when receipt_sent_at is null.
  • Check what billing does with a repeated withdraw call and note it in the PR.

Done when

  • A DB-backed test with two parallel calls ends with one row, one billing call and one receipt.
  • pnpm drizzle-kit check passes.
  • A retry click on an open request does not re-send an already sent receipt.
## What `processWithdrawal` checks for an open request, then inserts one. Two concurrent requests both insert. ## Why The right of withdrawal is a consumer-law flow. Two rows mean two billing calls and two receipts. The audit trail is ambiguous. ## Failing case Send two concurrent POSTs to `/api/withdraw` for one account with one paid purchase. Two `withdrawal_requests` rows exist and two receipt mails go out. ## Fix - Add a partial unique index on `withdrawal_requests(sub) WHERE withdrawn_at IS NULL AND rejection IS NULL`. - On a unique violation, re-read and reuse the open row. - Send the receipt only when `receipt_sent_at` is null. - Check what billing does with a repeated `withdraw` call and note it in the PR. ## Done when - [ ] A DB-backed test with two parallel calls ends with one row, one billing call and one receipt. - [ ] `pnpm drizzle-kit check` passes. - [ ] A retry click on an open request does not re-send an already sent receipt.
supernaut lade till detta till projektet Bitborg Web 2026-10-08 21:14:48 +00:00
Logga in för att delta i denna konversation.
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-web#325
Ingen beskrivning angiven.