Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce199cc
Protect committed bookings from refunds
stefan-burke Jul 11, 2026
6848c5c
Keep orphaned payment replays handled
stefan-burke Jul 11, 2026
ee33cd8
Recover tickets after committed booking errors
stefan-burke Jul 11, 2026
2fd68ed
Complete recovered paid bookings
stefan-burke Jul 12, 2026
bf49d48
Strengthen payment recovery tests
stefan-burke Jul 12, 2026
d4640c3
Cover pruned balance replay
stefan-burke Jul 12, 2026
6ccf91c
Keep payment recovery terminal
stefan-burke Jul 12, 2026
bd5c2f5
Finalize with attendee ticket token
stefan-burke Jul 12, 2026
1b4edd4
Require scoped payment ticket token
stefan-burke Jul 12, 2026
de20ef4
Protect committed bookings from refunds
stefan-burke Jul 11, 2026
047c11c
Keep orphaned payment replays handled
stefan-burke Jul 11, 2026
2ec493d
Recover tickets after committed booking errors
stefan-burke Jul 11, 2026
5345be9
Complete recovered paid bookings
stefan-burke Jul 12, 2026
40ca897
Strengthen payment recovery tests
stefan-burke Jul 12, 2026
0d5e41b
Cover pruned balance replay
stefan-burke Jul 12, 2026
5a70440
Keep payment recovery terminal
stefan-burke Jul 12, 2026
95dece8
Finalize with attendee ticket token
stefan-burke Jul 12, 2026
d10db72
Require scoped payment ticket token
stefan-burke Jul 12, 2026
af47a14
Merge remote-tracking branch 'origin/fix/committed-booking-refunds' i…
stefan-burke Jul 12, 2026
3eaebc6
Restore recovered contact history
stefan-burke Jul 12, 2026
93ca61a
Recover after ticket redirect race
stefan-burke Jul 12, 2026
df56d4b
Merge branch 'main' into fix/committed-booking-refunds
stefan-burke Jul 12, 2026
10dc882
Merge remote-tracking branch 'origin/fix/committed-booking-refunds' i…
stefan-burke Jul 12, 2026
1aac4e0
Update recovered ticket copy assertion
stefan-burke Jul 12, 2026
a1d8563
Make payment recovery writes idempotent
stefan-burke Jul 12, 2026
653191b
Merge remote-tracking branch 'origin/main' into fix/committed-booking…
stefan-burke Jul 12, 2026
a3284cc
Use shared listing question links
stefan-burke Jul 12, 2026
b02e9f1
Stage paid bookings before checkout
stefan-burke Jul 12, 2026
4236e09
Harden checkout cleanup and servicing edits
stefan-burke Jul 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,14 @@ existing ticket?) and likely adding payment-intent uniqueness — out of scope f
a test-only file split. Starting point: `src/features/api/payment-processing.ts`
(the `/payment/success` finalize path) and `#shared/db/processed-payments.ts`.

## Payment-processing review follow-ups (from PR #1692)
## Payment-processing review follow-up (from PR #1692)

Both items describe behaviour that predates the payment-processing split (the
code was moved verbatim from the old `payment-processing.ts` monolith). They are
This item describes behaviour that predates the payment-processing split (the
code was moved verbatim from the old `payment-processing.ts` monolith). It is
recorded here because the split PR was a pure reorganisation — changing this
behaviour there would be out of scope — and CodeRabbit flagged them as worth a
look.

- **Refund after a committed booking** (`src/features/api/payment-processing/index.ts`,
the `try { honoured = await createAttendeeForSession(...) } catch` in
`processReservedSession`). `createAttendeeForSession` commits the attendee +
bookings atomically, then runs `ensureAllBookings` (a post-commit read). If
that post-write step *threw*, the `catch` would route to `storeRefundedBooking`
— refunding a booking that actually persisted. Today `ensureAllBookings`
returns a structured `{ ok: false }` rather than throwing on the capacity path,
so the window is theoretical, but it isn't guarded structurally. Fix direction:
narrow the `try` to the pre-commit call only, or guarantee the post-commit
cleanup path is non-throwing, so a persisted booking can never be refunded.
Add a regression test that makes the post-commit step throw and asserts no
refund is issued.
behaviour there would have been out of scope — and CodeRabbit flagged it as
worth a look.

- **Per-item DB reads not batched** (`src/features/api/payment-processing/items.ts`
`validateAllItems`, and `package-pricing.ts` `loadPackagePricingByGroup`).
`validateAllItems` calls `getListingWithCount` once per item in a loop, and
Expand Down
44 changes: 44 additions & 0 deletions src/features/api/payment-processing/completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
type CreatedEntry,
logPromoCodeModifiers,
saveSessionAnswers,
sessionSuccess,
} from "#routes/api/payment-processing/create.ts";
import type {
BookingIntent,
PaymentResult,
} from "#routes/api/webhook-types.ts";
import type { ModifierApplication } from "#shared/checkout-pricing.ts";
import type { ModifierSpec } from "#shared/payments.ts";
import { logAndNotifyRegistration } from "#shared/webhook.ts";

/** Finish the work that follows an atomically committed paid booking. Shared by
* the normal create result and recovery after the database committed but the
* client lost that result. */
export const completePaidBooking = async (
createdEntries: CreatedEntry[],
intent: BookingIntent,
codeSpecs: ModifierSpec[],
modifierApplications: ModifierApplication[],
ticketTokens: string[],
): Promise<PaymentResult> => {
await saveSessionAnswers(createdEntries, intent);
const firstEntry = createdEntries[0]!;

if (codeSpecs.length > 0) {
await logPromoCodeModifiers(
codeSpecs,
modifierApplications,
firstEntry.listing,
firstEntry.attendee.id,
);
}

await logAndNotifyRegistration(createdEntries, intent.siteTokenIndex);

return sessionSuccess(
firstEntry.attendee.id,
firstEntry.listing.id,
ticketTokens,
);
};
Loading