ContentFlow now includes a comprehensive Stripe subscription integration based on official Stripe documentation. This implementation provides enterprise-grade billing, subscription management, and promotional capabilities.
- Subscription Management - Create, update, cancel subscriptions
- Customer Portal - Self-service billing management
- Webhook Handling - Real-time subscription events
- Promotional Codes - Discount and coupon system
- Usage Tracking - Monitor content generation limits
- Analytics Dashboard - Revenue and subscription metrics
- Flexible Billing Mode - Enhanced subscription behavior
- Custom Terms - Subscription and cancellation terms
- Tax Collection - Automatic tax ID collection
- Address Collection - Required billing address
- Promotion Codes - Built-in discount support
- Revenue Analytics - Monthly recurring revenue tracking
- Subscription Distribution - Plan usage statistics
- Customer Management - User subscription overview
- Promotional Campaigns - Create and manage discounts
GET /api/enhanced-payments/plans # Get available pricing plans
POST /api/enhanced-payments/webhook # Stripe webhook handler
POST /api/enhanced-payments/create-checkout-session # Start subscription
POST /api/enhanced-payments/create-portal-session # Billing portal
GET /api/enhanced-payments/subscription # Current subscription
POST /api/enhanced-payments/update-subscription # Upgrade/downgrade
POST /api/enhanced-payments/cancel-subscription # Cancel subscription
GET /api/enhanced-payments/analytics # Subscription analytics
POST /api/enhanced-payments/create-coupon # Create promotional codes
POST /api/enhanced-payments/setup-products # Initialize Stripe products
# Using Stripe CLI (recommended)
stripe products create --name="ContentFlow Starter" --description="Perfect for content creators"
stripe prices create --product=prod_xxx --unit-amount=2900 --currency=usd --recurring-interval=month --lookup-key=starter_monthly
stripe products create --name="ContentFlow Pro" --description="Advanced features for businesses"
stripe prices create --product=prod_xxx --unit-amount=5900 --currency=usd --recurring-interval=month --lookup-key=pro_monthlyPOST /api/enhanced-payments/setup-products
Authorization: Bearer <admin_token>Add these to your .env.local file:
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_your_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_here
# Frontend URL for redirects
FRONTEND_URL=https://your-domain.vercel.app- Go to Stripe Dashboard → Webhooks
- Add endpoint:
https://your-api-domain.vercel.app/api/enhanced-payments/webhook - Select events:
customer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeededinvoice.payment_failedcheckout.session.completed
stripe listen --forward-to localhost:3001/api/enhanced-payments/webhookThe integration uses existing Supabase tables:
user_subscriptions- User subscription datacontent_submissions- Usage trackingpromotions- Admin promotional campaigns
import EnhancedCheckout from './components/EnhancedCheckout';
function PricingPage() {
return (
<EnhancedCheckout
user={currentUser}
onSuccess={() => {
// Handle successful subscription
window.location.href = '/dashboard';
}}
/>
);
}// Admin only - create 50% off coupon
const response = await fetch('/api/enhanced-payments/create-coupon', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({
code: 'LAUNCH50',
percentOff: 50,
duration: 'once'
})
});// Get current subscription
const subscription = await fetch('/api/enhanced-payments/subscription', {
headers: { 'Authorization': `Bearer ${userToken}` }
});
// Cancel subscription
await fetch('/api/enhanced-payments/cancel-subscription', {
method: 'POST',
headers: { 'Authorization': `Bearer ${userToken}` },
body: JSON.stringify({ cancelAtPeriodEnd: true })
});- Monthly Recurring Revenue (MRR)
- Active Subscriptions Count
- Plan Distribution (Starter vs Pro)
- Recent Subscription Activity
- Customer Lifetime Value
- Content Pieces Generated
- Monthly Usage Limits
- Usage Percentage by Plan
- Overage Notifications
- Row Level Security - Database access control
- Webhook Signature Verification - Secure event handling
- Customer Data Isolation - User-specific data access
- PCI Compliance - Stripe handles payment data
- Email-based Admin Authentication
- Admin-only Endpoints - Analytics and coupon creation
- Audit Logging - Track administrative actions
Success: 4242 4242 4242 4242
Decline: 4000 0000 0000 0002
3D Secure: 4000 0000 0000 3220
# Test webhook locally
stripe trigger customer.subscription.created- Subscription Flow - Complete checkout process
- Portal Access - Billing management
- Plan Changes - Upgrade/downgrade
- Cancellation - Subscription termination
- Usage Limits - Content generation tracking
- Switch to live Stripe keys
- Configure production webhooks
- Set up monitoring and alerts
- Test payment flows end-to-end
- Configure tax settings
- Set up customer support workflows
- Stripe Dashboard alerts
- Failed payment notifications
- Subscription churn tracking
- Revenue goal monitoring
- Verify webhook secret in environment variables
- Check endpoint URL accessibility
- Review Stripe Dashboard webhook logs
- Check customer payment method
- Verify billing address requirements
- Review Stripe Dashboard payment logs
- Confirm product and price IDs
- Check subscription status in Stripe
- Verify database synchronization
- Stripe Documentation: https://docs.stripe.com/billing/subscriptions
- Stripe Support: Available in Dashboard
- ContentFlow Admin: Access analytics at
/admin
- Usage-based Billing - Pay per content piece
- Annual Subscriptions - Discounted yearly plans
- Team Management - Multi-user subscriptions
- Custom Pricing - Enterprise negotiations
- Dunning Management - Failed payment recovery
- Zapier Integration - Workflow automation
- Slack Notifications - Team alerts
- Email Marketing - Customer lifecycle
- Analytics Platforms - Advanced reporting
ContentFlow's enhanced Stripe integration provides enterprise-grade subscription management with comprehensive analytics, promotional capabilities, and seamless user experience. Ready for production deployment and scaling to $10B+ platform status!