Skip to content

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 ​

  1. Reserve — POST /stripe/create-checkout-session (user auth) calls reserveBooking. For a departure it atomically decrements Departure.availableSpots with a guard (gte groupSize). For a date-based booking it checks availability, capacity and unavailableDates. A Booking is created with status = PENDING_PAYMENT and Payment with status = PENDING.
  2. Checkout — Stripe Checkout Session is created with expires_at = now + 30 minutes, client_reference_id = booking id, and metadata bookingId. The API returns { url: session.url }.
  3. Pay — The user pays on Stripe. If they abandon, cancel-pending or webhook expiry will release spots and mark the booking FAILED.
  4. Fulfil — Stripe posts to POST /stripe/webhook (raw body, signature verified). Events checkout.session.completed and checkout.session.async_payment_succeeded call fulfillCheckout, which updates Booking to CONFIRMED, sets Payment to SUCCESS with stripePaymentIntentId, increments Activity.bookingsCount and fires confirmation emails. The fulfilment transaction uses updateMany with the PENDING_PAYMENT predicate so only the first request wins.
  5. Confirm — The frontend can also poll GET /stripe/checkout-session/:sessionId to trigger fulfilment if the webhook is delayed.

Endpoints ​

MethodEndpointAuthPurpose
POST/stripe/create-checkout-sessionUserReserve booking and create Stripe session
GET/stripe/checkout-session/:sessionIdUserPoll payment status and trigger fulfilment
POST/stripe/cancel-pending/:bookingIdUserCancel a pending checkout and release spots
POST/stripe/webhookStripe signatureWebhook handler
GET/bookings/my-bookingsUserTraveller'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, compute days from them, set totalPrice = departure.price * groupSize, and reserve spots.
  • Date-based — if no departures exist, startDate is required, must be in the future, must respect Activity.guestCapacity, and must not intersect Availability.unavailableDates. days comes from parseDurationDays(activity.duration).
  • Hold — Stripe session expires after 30 minutes. On expiry or async payment failure the webhook calls releasePendingBooking, which sets the booking to FAILED, fails the payment and increments availableSpots back if a departure was used.
  • Atomic fulfilment — only PENDING_PAYMENT bookings are moved to CONFIRMED. 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 if FRONTEND_BASE_URL is 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/webhook

Use 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.

Built with VitePress