Payment System
Overview
The NextAI starter kit includes a complete payment system powered by Stripe, allowing you to monetize your AI application through subscriptions or a credit-based system. The implementation is beginner-friendly and requires minimal configuration.
Features
- Stripe integration for secure payment processing
- Credit-based system for pay-as-you-go usage
- Customizable subscription plans
- Automatic webhook handling
- User-friendly checkout process
Setup
Environment Variables
Configure your Stripe credentials in the .env
file:
# Stripe Configuration
STRIPE_PUBLISHABLE_KEY=your_publishable_key
STRIPE_SECRET_KEY=your_secret_key
STRIPE_WEBHOOK_SECRET=your_webhook_secret
NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL_LINK=your_customer_portal_link
# Credit System Configuration (Optional)
CREDIT_PRICE_USD=0.10
You can obtain these keys from your Stripe Dashboard (opens in a new tab).
Testing
Test Cards
Use these test card numbers during development:
- Success:
4242 4242 4242 4242
- Decline:
4000 0000 0000 0002
Local Testing
- Install the Stripe CLI (opens in a new tab)
- Forward webhooks to your local environment:
stripe listen --forward-to localhost:3000/api/stripe/webhook
Troubleshooting
Common Issues
-
Webhook Errors
- Verify webhook secret is correct
- Check webhook endpoint is accessible
- Ensure proper event handling
-
Payment Failures
- Validate payment amount
- Check customer information
- Review Stripe logs
-
Credit System Issues
- Verify credit price configuration
- Check database connections
- Review transaction logs
For more detailed information about Stripe integration, visit the Stripe Documentation (opens in a new tab).
Last updated on