Stripe Payments¶
Top G & AI Velocity Feature
Stripe payments are available in Top G and AI Velocity tiers only.
See tier comparison
Complete Stripe integration with subscriptions, one-time purchases, webhook handling, and customer portal.
Quick Start¶
| Bash | |
|---|---|
What's Included¶
Subscription Payments¶
- Monthly/annual billing
- Multiple subscription tiers
- Trial periods
- Auto-renewal
- Plan upgrades/downgrades
- Proration handling
One-time Purchases¶
- Product purchases
- Lifetime access options
- Success/cancel handling
Webhook Processing¶
- Secure signature verification
- Event handling (checkout, subscription updates)
- Automatic user plan updates
- Payment confirmation emails
Customer Portal¶
- Self-service billing management
- Update payment methods
- View invoices
- Cancel subscriptions
Setup Guide¶
1. Create Stripe Account¶
- Go to stripe.com
- Create account
- Get API keys from dashboard
2. Configure Environment¶
Add to local.env:
| Text Only | |
|---|---|
3. Create Products¶
| Bash | |
|---|---|
4. Test Webhooks Locally¶
| Bash | |
|---|---|
Architecture¶
Backend Components¶
Payment Manager (app/services/payment_manager.py):
- Creates checkout sessions
- Manages subscriptions
- Handles customer portal
Webhook Handler (app/services/webhook_handler.py):
- Verifies webhook signatures
- Processes payment events
- Updates user plans
Payment Controller (app/controllers/payments.py):
- API endpoints
- Request/response handling
Frontend Components¶
Payment Hooks (frontend/src/hooks/api/usePayments.ts):
useCreateCheckout()- Create checkout sessionuseCustomerPortal()- Open billing portaluseCancelSubscription()- Cancel subscription
Pages:
/pricing- Pricing page with checkout/billing- Subscription management/payment/success- Success handler/payment/cancel- Cancel handler
Usage Examples¶
Create Checkout Session¶
Open Customer Portal¶
| TypeScript | |
|---|---|
Webhook Events¶
Handled automatically:
checkout.session.completed- Payment successfulcustomer.subscription.created- New subscriptioncustomer.subscription.updated- Subscription changedcustomer.subscription.deleted- Subscription cancelledinvoice.payment_succeeded- Invoice paidinvoice.payment_failed- Payment failed
Testing¶
Test Cards¶
- Success: 4242 4242 4242 4242
- Decline: 4000 0000 0000 0002
- 3D Secure: 4000 0027 6000 3184
Testing Workflow¶
- Start local webhook listener
- Trigger test purchase in UI
- Verify webhook received
- Check user plan updated
- Confirm email sent (if configured)
Common Issues¶
Problem: Webhook signature verification fails
Solution: Use correct webhook secret from Stripe CLI or Dashboard
Problem: Redirect after payment fails
Solution: Check success_url and cancel_url in config
Problem: User plan not updating after payment
Solution: Verify webhook handler calls update_user_plan()
Production Checklist¶
- Replace test keys with live keys
- Configure production webhook endpoint
- Add webhook endpoint to Stripe Dashboard
- Test with real card (refund immediately)
- Verify email notifications work
- Test customer portal
- Monitor webhook logs
Related Documentation¶
- Admin Panel - View payment analytics
- RBAC System - Plan-based permissions
- API Reference - Payment endpoints
- Deployment - Production setup
- Stripe Documentation
Files Reference¶
app/services/payment_manager.py- Payment logicapp/services/webhook_handler.py- Webhook processingapp/controllers/payments.py- API endpointsapp/config/payments.py- Stripe configurationfrontend/src/hooks/api/usePayments.ts- React hooksfrontend/src/pages/Billing.tsx- Billing management UI