Overview
Connect World uses Stripe for secure credit and debit card payment processing. The integration handles payment intent creation, validation, and includes built-in rate limiting and security measures.Prerequisites
- Stripe account (sign up here)
- API keys from the Stripe Dashboard
- Next.js application with API routes
Environment Configuration
Get your Stripe API keys
Navigate to the Stripe Dashboard and copy your keys:
- Publishable key - Used on the client-side
- Secret key - Used on the server-side
Server-Side Implementation
Payment Intent Creation
The payment intent API route handles secure payment creation with validation and rate limiting. File:src/app/api/stripe/route.ts
Security Features:
- Rate limiting (10 attempts per 15 minutes per IP)
- Input sanitization for all user data
- Server-side price validation to prevent tampering
- Plan and duration validation against allowed values
Client-Side Implementation
Initialize Stripe
Load Stripe.js and wrap your payment form with the Elements provider.CheckoutModal.tsx
Payment Form Implementation
CheckoutForm.tsx
Payment Flow
Client requests payment intent
The client sends plan details (planId, months, amount) to
/api/stripeServer validates and creates intent
The server:
- Validates the plan exists
- Verifies price matches expected amount
- Creates a Stripe PaymentIntent
- Returns the
clientSecret
Client confirms payment
Using the
clientSecret, the client calls stripe.confirmCardPayment() with card detailsTesting
Test Card Numbers
Use these test cards in development:| Card Number | Description |
|---|---|
4242 4242 4242 4242 | Successful payment |
4000 0000 0000 9995 | Declined payment |
4000 0025 0000 3155 | Requires authentication |
Use any future expiration date, any 3-digit CVC, and any postal code.
Best Practices
Secure API Keys
Never expose your secret key. Use environment variables and keep them server-side only.
Validate on Server
Always validate prices and plan details server-side to prevent price manipulation.
Handle Errors Gracefully
Provide clear error messages to users and log detailed errors for debugging.
Implement Rate Limiting
Protect your payment endpoints from abuse with rate limiting.
Additional Resources
Troubleshooting
Common Issues
“No API key provided”- Ensure
STRIPE_SECRET_KEYis set in your environment variables - Verify the key starts with
sk_test_(test) orsk_live_(production)
- Stripe requires a minimum charge amount
- Verify your amount is in the correct format (dollars, not cents)
- The IP has made too many payment attempts
- Wait 15 minutes or adjust rate limit settings in
src/app/api/stripe/route.ts:14
