This guide will help you configure Stripe payment processing for your Mirhal RV & Camper Marketplace booking system.
- A Stripe account (sign up at https://stripe.com)
- Node.js and npm installed
- MongoDB running locally or remotely
- Log in to your Stripe Dashboard at https://dashboard.stripe.com
- Navigate to Developers > API keys
- You'll need two keys:
- Publishable key (starts with
pk_test_for test mode) - Secret key (starts with
sk_test_for test mode)
- Publishable key (starts with
Create or update /server/.env file:
# MongoDB
MONGODB_URI=mongodb://localhost:27017/mirhal
# Auth0
AUTH0_AUDIENCE=your-auth0-audience
AUTH0_ISSUER_BASE_URL=https://your-domain.auth0.com
# Stripe Keys
STRIPE_SECRET_KEY=sk_test_your_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
# Email Configuration (optional)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_SECURE=false
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=Mirhal <noreply@mirhal.com>
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173Create or update /.env file:
# API URL
VITE_API_URL=http://localhost:5000/api
# Stripe Publishable Key
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_here
# Auth0 Configuration
VITE_AUTH0_DOMAIN=your-domain.auth0.com
VITE_AUTH0_CLIENT_ID=your-auth0-client-id
VITE_AUTH0_AUDIENCE=your-auth0-audienceWebhooks allow Stripe to notify your server about payment events in real-time.
-
Install Stripe CLI:
# macOS brew install stripe/stripe-cli/stripe # Windows (with Scoop) scoop install stripe # Linux # Download from: https://github.com/stripe/stripe-cli/releases
-
Login to Stripe:
stripe login
-
Forward webhook events to your local server:
stripe listen --forward-to http://localhost:5000/api/webhooks/stripe
-
Copy the webhook signing secret from the output (starts with
whsec_) and add it to your/server/.envfile asSTRIPE_WEBHOOK_SECRET.
- Go to Stripe Dashboard > Developers > Webhooks
- Click Add endpoint
- Set the endpoint URL to:
https://your-domain.com/api/webhooks/stripe - Select the following events to listen to:
payment_intent.succeededpayment_intent.payment_failedpayment_intent.canceledcharge.refunded
- Copy the Signing secret and add it to your production environment variables
Stripe provides test card numbers for different scenarios:
| Card Number | Scenario |
|---|---|
4242 4242 4242 4242 |
Successful payment |
4000 0025 0000 3155 |
Requires authentication (3D Secure) |
4000 0000 0000 9995 |
Payment declined |
4000 0000 0000 0341 |
Attaching fails |
For all test cards:
- Use any future expiration date (e.g., 12/34)
- Use any 3-digit CVC (e.g., 123)
- Use any ZIP code (e.g., 12345)
-
Start your servers:
# Terminal 1: Start backend cd server npm run dev # Terminal 2: Start frontend cd .. npm run dev # Terminal 3: Start Stripe webhook listener (development only) stripe listen --forward-to http://localhost:5000/api/webhooks/stripe
-
Make a test booking:
- Navigate to a vehicle detail page
- Click "Reserve Now"
- Select dates
- Fill in guest details
- Use test card
4242 4242 4242 4242for payment - Complete the booking
-
Verify the booking:
- Check the MongoDB database for the new booking
- Check Stripe Dashboard for the payment
- Check console for email notifications
- Check host dashboard for the booking request
Here's how the payment system works:
1. Guest selects dates and fills in details
↓
2. Frontend calls POST /api/payments/create-payment-intent
↓
3. Backend creates Stripe PaymentIntent (amount is authorized but not captured)
↓
4. Frontend displays Stripe payment form
↓
5. Guest enters card details
↓
6. Stripe processes payment (funds are held, not yet charged)
↓
7. Frontend calls POST /api/payments/confirm-payment
↓
8. Backend creates booking in database with status "pending"
↓
9. Stripe webhook confirms payment success
↓
10. Backend updates booking status to "paid"
↓
11. Email notifications sent to guest and host
↓
12. Host approves or declines booking
↓
13. If approved: booking becomes active
If declined: refund can be processed
Refunds can be triggered through the API:
POST /api/payments/:bookingId/refund
Authorization: Bearer {token}- Go to Stripe Dashboard > Payments
- Find the payment
- Click "Refund"
- Enter the refund amount
- The webhook will automatically update the booking status
- Check that Stripe CLI is running (
stripe listen) - Verify the webhook secret in
.envmatches the CLI output - Check server logs for webhook errors
- Ensure the webhook route is accessible
- Verify
VITE_STRIPE_PUBLISHABLE_KEYin frontend.env - Check that frontend and backend are communicating
- Verify Auth0 token is being sent correctly
- Ensure
VITE_STRIPE_PUBLISHABLE_KEYis set - Restart the frontend development server
- Clear browser cache
- Check that webhook is configured and receiving events
- Verify webhook secret is correct
- Check server logs for webhook processing errors
-
Never commit API keys to version control
- Add
.envfiles to.gitignore - Use environment variables in production
- Add
-
Use webhook signing secrets
- Always verify webhook signatures
- This prevents fake webhook events
-
Validate amounts on the backend
- Never trust amounts sent from the frontend
- Always recalculate prices on the server
-
Use HTTPS in production
- Webhooks require HTTPS endpoints
- Stripe rejects insecure connections
-
Handle errors gracefully
- Show user-friendly error messages
- Log detailed errors for debugging
When you're ready to accept real payments:
- Activate your Stripe account (complete business verification)
- Switch to live API keys in your environment variables
- Set up production webhooks (see Step 3)
- Update frontend environment with live publishable key
- Test with real card (use a small amount first)
- Monitor Stripe Dashboard for real transactions
If you encounter any issues:
- Check the Stripe Dashboard logs
- Review your server logs for errors
- Test with Stripe CLI webhook forwarding
- Contact Stripe Support for payment-specific issues
Note: This integration is configured for immediate payment authorization. The payment is held when the booking is created and requires host approval. For alternative flows (pay later, deposits, etc.), the payment controller logic will need to be modified.