This guide explains how to set up and test the Stripe Checkout payment integration with webhooks.
The payment system uses Stripe Checkout (hosted payment page) instead of embedded card elements. When a user clicks "Pay Now", they are redirected to Stripe's secure checkout page. After payment, Stripe sends a webhook to update the booking status automatically.
- User clicks "Pay Now" → Frontend calls
/payments/create-checkout-session - Backend creates Stripe Checkout Session → Returns session URL
- User redirects to Stripe → Completes payment on Stripe's hosted page
- Stripe sends webhook → Backend receives
checkout.session.completedevent - Backend updates database → Booking status changes to "In Review"
- User redirects back →
- Success: Redirects to
/payment-successpage with payment details - Cancel: Redirects to
/payment-cancelpage with retry option
- Success: Redirects to
Add these variables to your server/.env file:
# Existing variables
PORT=5000
NODE_ENV=development
CLIENT_URL=http://localhost:5173
DB_USER=your_mongodb_username
DB_PASS=your_mongodb_password
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...CLIENT_URL is set correctly! The payment system uses this to redirect users after payment. If not set, it defaults to http://localhost:5173.
The frontend no longer needs the Stripe publishable key for this implementation, but you can keep it for future use:
VITE_API_URL=http://localhost:5000
VITE_Payment_Key=pk_test_... # Optional, not used in current implementation- Go to Stripe Dashboard
- Navigate to Developers → API keys
- Copy the Secret key (starts with
sk_test_for test mode) - Add to
server/.envasSTRIPE_SECRET_KEY
You have two options for webhook setup:
-
Install Stripe CLI:
# Windows (using Scoop) scoop install stripe # macOS brew install stripe/stripe-cli/stripe # Linux wget https://github.com/stripe/stripe-cli/releases/download/v1.19.4/stripe_1.19.4_linux_x86_64.tar.gz tar -xvf stripe_1.19.4_linux_x86_64.tar.gz sudo mv stripe /usr/local/bin
-
Login to Stripe:
stripe login
-
Forward webhooks to your local server:
stripe listen --forward-to localhost:5000/payments/webhook
-
Copy the webhook signing secret from the output (starts with
whsec_) -
Add it to
server/.envasSTRIPE_WEBHOOK_SECRET
- Go to Stripe Dashboard
- Navigate to Developers → Webhooks
- Click Add endpoint
- Enter your endpoint URL:
https://yourdomain.com/payments/webhook - Select events to listen to:
checkout.session.completedpayment_intent.succeeded(optional)payment_intent.payment_failed(optional)
- Click Add endpoint
- Copy the Signing secret (starts with
whsec_) - Add to
server/.envasSTRIPE_WEBHOOK_SECRET
Terminal 1 - Backend:
cd server
npm run devTerminal 2 - Frontend:
cd client
npm run devTerminal 3 - Stripe CLI (for local testing):
stripe listen --forward-to localhost:5000/payments/webhook- Navigate to the trips page
- Select a package
- Fill in the booking form
- Submit the booking (status will be "Pending")
-
Go to Dashboard → My Bookings
-
Find the pending booking
-
Click Pay Now
-
You'll be redirected to Stripe Checkout
-
Use Stripe test card numbers:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Requires Authentication:
4000 0025 0000 3155 - Use any future expiry date (e.g., 12/34)
- Use any 3-digit CVC (e.g., 123)
- Use any ZIP code (e.g., 12345)
- Success:
-
Complete the payment
-
You'll be redirected to the Payment Success page
-
Click "View My Bookings" to see your confirmed booking
-
The booking status should now be "In Review"
To test cancellation:
- Click "Pay Now" on a pending booking
- On the Stripe checkout page, click the back arrow or close the window
- You'll be redirected to the Payment Cancel page
- You can retry the payment or go back to bookings
Check your Stripe CLI terminal (Terminal 3). You should see:
✔ Received event: checkout.session.completed
Check your backend logs for:
Payment saved: { bookingId: '...', sessionId: '...', ... }
Booking updated: { acknowledged: true, modifiedCount: 1, ... }