Stripe Integration
Complete guide to set up and configure Stripe payments in NEXTDEVKIT
🚀 Stripe Setup
Follow these steps to integrate Stripe with NEXTDEVKIT:
1. Create Stripe Account
- Create a Stripe account at stripe.com
- Go to the Stripe Dashboard
2. Get API Keys
- Go to Developers → API keys
- Copy your Secret key (starts with
sk_test_for test mode)
Add to your .env file:
STRIPE_SECRET_KEY="sk_test_your_secret_key"3. Set up Webhooks
-
Go to Developers → Webhooks
-
Click "Add endpoint"
-
Enter your webhook URL:
https://your-domain.com/api/webhooks/stripe -
Select these events:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deleted
-
Copy the Webhook Signing Secret (starts with
whsec_)
Add to your .env file:
STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"4. Create Products and Prices
Pro Subscription Product
- Go to Products → Add product
- Name: "Pro Plan"
- Add Monthly price:
- Price: your monthly price
- Billing period: Monthly
- Recurring: Yes
- Copy the Price ID (starts with
price_)
- Add Yearly price:
- Price: your yearly price
- Billing period: Yearly
- Recurring: Yes
- Copy the Price ID (starts with
price_)
Lifetime Product
- Go to Products → Add product
- Name: "Lifetime Plan"
- Add One-time price:
- Price: your lifetime price
- Billing period: One-time
- Recurring: No
- Copy the Price ID (starts with
price_)
5. Configure Environment Variables
# Stripe Configuration
STRIPE_SECRET_KEY="sk_test_your_secret_key"
STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"
# Price IDs
NEXT_PUBLIC_PRICE_ID_PRO_MONTHLY="price_your_monthly_price_id"
NEXT_PUBLIC_PRICE_ID_PRO_YEARLY="price_your_yearly_price_id"
NEXT_PUBLIC_PRICE_ID_LIFETIME="price_your_lifetime_price_id"6. Update Payment Provider Configuration
In src/config/index.ts, set the provider to Stripe:
payment: {
provider: "stripe",
currency: "USD",
// ... rest of your configuration
plans: {
pro: {
prices: [
{
amount: 9.99, // your monthly price
interval: PlanInterval.MONTH,
trialPeriodDays: 7, // your trial period days
},
{
amount: 99, // your yearly price
interval: PlanInterval.YEAR,
trialPeriodDays: 30, // your trial period days
},
],
},
},
}🧪 Testing with Stripe
Test Credit Cards
Use these test cards with Stripe:
| Card Number | Description |
|---|---|
4242 4242 4242 4242 | Successful payment |
4000 0000 0000 3220 | 3D Secure authentication |
4000 0000 0000 9995 | Insufficient funds |
4000 0000 0000 0069 | Expired card |
Local Development
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Login to Stripe
stripe login
# Forward events to local server
stripe listen --forward-to localhost:3000/api/webhooks/stripe
# Test webhooks
stripe trigger checkout.session.completed
stripe trigger customer.subscription.createdUsing ngrok for Webhook Testing
You can also use ngrok to create a tunnel to your local machine:
ngrok http 3000Then use the ngrok URL in your Stripe webhook configuration.
🔧 Stripe Features
Customer Portal
Stripe provides a hosted customer portal where customers can:
- Update payment methods
- View billing history
- Cancel subscriptions
- Download invoices
Advanced Features
- Tax calculation: Automatic tax calculation for global customers
- Fraud detection: Built-in fraud prevention
- Subscription management: Flexible subscription handling
- Multi-currency: Support for 135+ currencies
- Payment methods: Credit cards, digital wallets, bank transfers
🔧 Troubleshooting
Common Issues
Webhook Not Receiving Events:
- Check webhook URL is correct
- Verify webhook signing secret
- Ensure HTTPS in production
- Check selected events
Payment Failures:
- Verify API keys are correct
- Check card details format
- Ensure proper error handling
- Test with different cards
Customer Portal Issues:
- Check customer ID is valid
- Verify return URL is correct
- Ensure customer has payment methods
Subscription Problems:
- Check subscription status
- Verify webhook processing
- Review billing cycle settings
📊 Stripe Dashboard
The Stripe Dashboard provides:
- Real-time analytics: Revenue, customer metrics
- Payment tracking: Transaction history and status
- Customer management: Customer profiles and data
- Subscription monitoring: Active subscriptions and churn
- Tax reporting: Automated tax calculations
🔗 Stripe Resources
🎯 Next Steps
Now that Stripe is configured: