Prompt
How do I integrate appointment scheduling with Stripe?
Latest observation
To integrate appointment scheduling with Stripe, you usually combine:
- A booking system to choose a time slot
- Stripe Checkout / Payment Intents to collect payment
- A webhook flow to confirm the booking only after payment succeeds
Here’s a practical approach.
1) Decide your booking flow
Common patterns:
A. Pay first, then confirm booking
- User selects an appointment time
- You create a Stripe payment session
- After payment succeeds, you finalize the booking
Best when you want to avoid unpaid reservations.
B. Reserve first, then pay
- User selects a time
- You temporarily hold the slot
- They pay within a short window
- If payment fails or expires, release the slot
Best when you want to reduce double-booking, but it adds complexity.
2) Use Stripe Checkout for simplest payment handling
Stripe Checkout is the easiest way to accept payments.
Basic flow
- User picks a date/time
- Your backend creates a booking draft
- Backend creates a Stripe Checkout Session with:
- amount
- currency
- metadata for appointment details
- success/cancel URLs
- User pays on Stripe-hosted page
- Stripe sends a webhook like
checkout.session.completed - Your backend marks the appointment as confirmed
3) Store appointment data in your database
Create a table like:
appointmentsidcustomer_namecustomer_emailstart_timeend_timestatus(pending,confirmed,cancelled)stripe_checkout_session_idstripe_payment_intent_idcreated_at
You should also store availability/slot data to prevent double booking.
4) Example backend flow
Step 1: Create a booking draft
When the user picks a slot:
- verify the slot is available
- create an appointment record with status
pending
Step 2: Create Stripe Checkout Session
Include appointment details in metadata so you can reconcile later.
Example (Node.js):
const session = await stripe.checkout.sessions.create({
mode: 'payment',
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Appointment Booking',
},
unit_amount: 5000, // $50.00
},
quantity: 1,
},
],
success_url: `${YOUR_DOMAIN}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${YOUR_DOMAIN}/cancel`,
metadata: {
appointmentId: appointment.id,
customerEmail: appointment.customer_email,
startTime: appointment.start_time,
},
});
5) Confirm payment with a webhook
Do not rely only on the success page. Always use Stripe webhooks.
Listen for:
checkout.session.completed- optionally
payment_intent.succeeded
Example logic:
- verify webhook signature
- get
appointmentIdfrom metadata - confirm the appointment in your DB
- mark slot as occupied
Pseudo-flow:
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
const appointmentId = session.metadata.appointmentId;
// update appointment to confirmed
await db.appointments.update(appointmentId, {
status: 'confirmed',
stripe_checkout_session_id: session.id,
stripe_payment_intent_id: session.payment_intent,
});
}
6) Handle cancellations, expirations, and refunds
You should plan for edge cases:
If payment fails or user abandons checkout
- keep appointment as
pending - automatically expire or release after a timeout
If user cancels
- mark appointment as
cancelled - free the slot
If you need to refund
- use Stripe Refunds API
- update booking status accordingly
7) Prevent double bookings
This is critical.
Use one or more of:
- database transactions
- unique constraint on
(start_time, provider_id)or(slot_id) - “lock” the slot when creating the pending appointment
- short expiration window for pending reservations
A common strategy:
- mark slot
reserved - create Checkout Session
- if payment succeeds, mark it
confirmed - if not paid within 15 minutes, release it
8) If you need recurring or advanced scheduling
If your business has more complex needs, consider:
- integrating a scheduler like Cal.com, Acuity, or Calendly
- or building your own calendar availability engine
- then connect payment with Stripe on booking confirmation
9) Recommended architecture
A clean setup is:
Frontend
- calendar UI
- time slot selection
- checkout redirect
Backend
- availability checks
- appointment creation
- Stripe session creation
- webhook handling
Database
- users/customers
- appointments
- provider availability
- payment status
10) Security best practices
- Never trust the client to determine price
- Create prices on the server
- Verify Stripe webhook signatures
- Use idempotency keys when creating sessions or bookings
- Don’t confirm bookings from the success page alone
Simple end-to-end flow
- User selects a time slot
- Backend validates availability
- Backend creates
pendingappointment - Backend creates Stripe Checkout Session
- User pays
- Stripe webhook confirms payment
- Backend marks appointment as
confirmed - Send confirmation email / calendar invite
If you want, I can also give you:
- a Node.js/Express example
- a Next.js example
- a Python/Django example
- or a database schema + webhook implementation