Overview
Crave handles payment processing through Stripe, but you’ll need to integrate Stripe’s client-side components in your storefront. This guide shows you how to add secure payment processing to your storefront.Prerequisites
- Stripe publishable key (get this from your merchant)
- Working storefront with cart functionality
- SSL certificate for production
Setup
1. Environment Variables
Add your Stripe publishable key to.env.local
:
2. Install Stripe Dependencies
Payment Flow
The payment process works like this:- Customer adds items to cart (your storefront handles this)
- Customer clicks checkout (your storefront initiates payment)
- Create payment intent (Crave API creates this)
- Customer enters payment info (Stripe handles this securely)
- Payment is processed (Stripe & Crave handle this)
- Order is created (Crave creates the order automatically)
Implementation
1. Create Payment Intent
Create an API route to get payment intent from Crave:2. Create Checkout Component
Createcomponents/Checkout.js
:
3. Add to Your Main Component
Update your main page to include checkout:4. Add Checkout Styling
Add to yourstyles/globals.css
:
Testing
1. Use Test Cards
For testing, use these Stripe test card numbers:2. Test the Flow
- Add items to cart
- Click “Proceed to Checkout”
- Enter test card
4242424242424242
- Use any future expiry date and any CVC
- Complete payment
- Verify success message
Error Handling
Common payment errors and how to handle them:Security Notes
- Never include your secret key in client-side code
- Always use HTTPS in production
- Payment processing is handled securely by Stripe
- Crave automatically creates orders when payments succeed
What Happens Next
After successful payment:- Stripe processes the payment securely
- Crave receives the payment confirmation via webhook
- Order is automatically created in the merchant’s system
- Customer receives confirmation (handled by merchant)
- Order appears in merchant dashboard for fulfillment