Bookings & Payments
Bookings are created by travellers, held for 30 minutes, paid via Stripe Checkout, and confirmed idempotently by the webhook or by polling the checkout session.
Flow
- Reserve —
POST /stripe/create-checkout-session(user auth) callsreserveBooking. For a departure it atomically decrementsDeparture.availableSpotswith a guard (gte groupSize). For a date-based booking it checks availability, capacity andunavailableDates. ABookingis created withstatus = PENDING_PAYMENTandPaymentwithstatus = PENDING. - Checkout — Stripe Checkout Session is created with
expires_at= now + 30 minutes,client_reference_id= booking id, and metadatabookingId. The API returns{ url: session.url }. - Pay — The user pays on Stripe. If they abandon,
cancel-pendingor webhook expiry will release spots and mark the bookingFAILED. - Fulfil — Stripe posts to
POST /stripe/webhook(raw body, signature verified). Eventscheckout.session.completedandcheckout.session.async_payment_succeededcallfulfillCheckout, which updatesBookingtoCONFIRMED, setsPaymenttoSUCCESSwithstripePaymentIntentId, incrementsActivity.bookingsCountand fires confirmation emails. The fulfilment transaction usesupdateManywith thePENDING_PAYMENTpredicate so only the first request wins. - Confirm — The frontend can also poll
GET /stripe/checkout-session/:sessionIdto trigger fulfilment if the webhook is delayed.
Endpoints
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| POST | /stripe/create-checkout-session | User | Reserve booking and create Stripe session |
| GET | /stripe/checkout-session/:sessionId | User | Poll payment status and trigger fulfilment |
| POST | /stripe/cancel-pending/:bookingId | User | Cancel a pending checkout and release spots |
| POST | /stripe/webhook | Stripe signature | Webhook handler |
| GET | /bookings/my-bookings | User | Traveller's bookings |
Stripe routes are mounted at /api/v1/stripe/... via stripeRoute.
Booking rules
- Public activity required — only published + approved activities can be booked.
- Price — must be > 0.
- Departures — if the activity has future departures, the request must pick a departure. Departure bookings use
departure.startDate/endDate, computedaysfrom them, settotalPrice = departure.price * groupSize, and reserve spots. - Date-based — if no departures exist,
startDateis required, must be in the future, must respectActivity.guestCapacity, and must not intersectAvailability.unavailableDates.dayscomes fromparseDurationDays(activity.duration). - Hold — Stripe session expires after 30 minutes. On expiry or async payment failure the webhook calls
releasePendingBooking, which sets the booking toFAILED, fails the payment and incrementsavailableSpotsback if a departure was used. - Atomic fulfilment — only
PENDING_PAYMENTbookings are moved toCONFIRMED. Duplicate webhook deliveries are a no-op after the first write. - Emails — on first confirmation, the API emails the traveller and the supplier (reply goes to the traveller). Emails are skipped if
NODE_ENV !== "production"or ifFRONTEND_BASE_URLis missing.
Payment model
prisma
model Payment {
id String
bookingId String @unique
amount Decimal
currency CURRENCY @default(USD)
status PaymentStatus @default(PENDING)
transactionId String? @unique // Stripe Checkout Session ID
provider PaymentProvider @default(STRIPE)
stripePaymentIntentId String?
}Only STRIPE is implemented. currency is USD or NPR.
Testing
bash
stripe listen --forward-to localhost:3000/api/v1/stripe/webhookUse Stripe test cards (e.g. 4242 4242 4242 4242). The API stores the session id in Payment.transactionId and uses it to reconcile status.
Supplier booking views
Suppliers see bookings via GET /supplier/bookings (supplier auth). The admin can inspect bookings through admin endpoints.