- ✅ Automatic invoice sync to Stripe
- ✅ Secure payment method storage
- ✅ Automated payment processing
- ✅ Real-time webhook reconciliation
- ✅ Customer and subscription sync
Step-by-Step Workflow
Phase 1: Initial Setup
1
Create Stripe Connection
Set up your Stripe connection with invoice sync enabled. This allows Flexprice to automatically sync invoices to Stripe and process payments.📚 Complete Guide: Stripe Connection Setup
Phase 2: Product Catalog Setup
1
Create Feature
Define a metered feature for usage-based billing:Endpoint: Response:
POST /api/v1/features2
Create Plan
Create a subscription plan with pricing:Endpoint:
POST /api/v1/plansPhase 3: Customer Onboarding
1
Create Customer
Create a customer in Flexprice (automatically synced to Stripe):Endpoint: Response:Note: Customer is automatically created in Stripe when connection is configured.
POST /api/v1/customers2
Save Payment Method
Generate a secure link for customer to save their card:Endpoint: Response:Integration Steps:
POST /api/v1/payments/customers/{customer_id}/setup/intentRequest:- Send
checkout_urlto customer via email or display in your application - Customer enters card details on Stripe’s hosted page
- Card is saved and set as default payment method
- Flexprice receives webhook confirmation from Stripe
save_card_and_make_default flag:
Endpoint: POST /api/v1/payments
Phase 4: Subscription Creation
1
Create Subscription
Create a subscription that will generate invoices automatically:Endpoint: Response:
POST /api/v1/subscriptionsPhase 5: Usage Tracking
1
Track Usage Events
Send usage events throughout the billing period:Single Event:
Endpoint: Bulk Events:
Endpoint:
POST /api/v1/eventsPOST /api/v1/events/bulk2
Query Usage
Query aggregated usage data anytime:Endpoint: Response:
POST /api/v1/events/usage/meterPhase 6: Invoice Generation & Sync
1
Invoice Auto-Generated
At end of billing period, Flexprice automatically:
- Creates draft invoice with usage charges
- Calculates pricing based on usage
- Finalizes invoice
- Syncs to Stripe (if connection configured)
2
Sync Trigger Check
Flexprice checks if invoice should sync:
- ✅ Stripe connection exists
- ✅ Connection is active
- ✅ Invoice sync is enabled
- ✅ Customer synced to Stripe
3
Invoice Synced to Stripe
Invoice is automatically synced to Stripe:Response:
Phase 7: Payment Processing
1
Automatic Payment Attempt
When
collection_method: "charge_automatically":- Stripe automatically attempts to charge customer’s default payment method
- Payment intent is created and confirmed
- Charge is processed immediately
- Stripe sends
invoice.payment_paidwebhook - Flexprice updates invoice status to “paid”
- Customer receives payment confirmation email
2
Webhook Processing
Flexprice receives webhook at:Webhook Flow:
- Stripe sends webhook → Flexprice
- Verify webhook signature
- Extract invoice/payment ID from metadata
- Update invoice status in Flexprice
- Return 200 OK immediately
3
Payment Status Updated
Check invoice payment status:Endpoint:
GET /api/v1/invoices/{invoice_id}Payment Collection Methods
Flexprice supports multiple payment collection methods for invoices. For detailed information on all payment options including offline payments, credit/wallet usage, and automated charging: 📚 Complete Guide: Record Payment & Collection MethodsQuick Overview
Charge Automatically (charge_automatically)
- Best for: Subscriptions with saved payment methods
- Stripe automatically charges customer’s default payment method
- Immediate payment confirmation via webhooks
send_invoice)
- Best for: Manual payment workflows, B2B customers
- Customer receives email with Stripe-hosted payment link
- Flexible payment options
Key Integration Points
1. Entity Synchronization
Flexprice maintains bidirectional mapping between entities:| Flexprice Entity | Stripe Entity | Sync Direction |
|---|---|---|
| Customer | Customer | Bidirectional |
| Plan | Product | Outbound |
| Subscription | Subscription | Bidirectional |
| Invoice | Invoice | Outbound |
| Payment | Payment Intent | Inbound (via webhooks) |
2. Invoice Sync Configuration
Invoice Sync:- Status synchronization: Payment status updates via webhooks
- PDF generation: Access invoices as PDF from Stripe
- Hosted pages: Use Stripe’s branded invoice pages
3. Payment Method Management
Setup Intent Flow:- Create Setup Intent via Flexprice API
- Customer enters card on Stripe hosted page
- Card saved and set as default
- Webhook confirms setup completion
- Saved cards used for recurring charges
- Off-session payments supported
- Multiple payment methods per customer
- Automatic default payment method selection
Error Handling
Common Scenarios
| Scenario | Handling | Result |
|---|---|---|
| Customer already exists | Use existing Stripe customer | No error |
| Invoice already synced | Skip sync, return mapping | No error |
| Payment method missing | Return error, require setup | User must save card |
| Card declined | Stripe retries automatically | Eventual success or failure |
| Webhook signature fail | Log warning, skip processing | Security measure |
Testing
Test Mode
Use Stripe test keys (sk_test_...) for development:
-
Test Cards: Use Stripe’s test card numbers
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002
- Success:
-
Test Webhooks: Use Stripe CLI for local testing
- Test Events: Trigger test webhooks from Stripe Dashboard
Production Checklist
Before going live:- Stripe connection created with production keys (
sk_live_...) - Webhook endpoint configured with production URL
- Webhook secret updated in connection
- Test customer creation and sync
- Test card save flow (Setup Intent)
- Test subscription creation
- Test usage event ingestion
- Verify invoice generation and sync
- Test automatic payment flow
- Monitor webhook delivery
- Set up error alerting
- Document customer support procedures
Security Best Practices
API Key Management
- Never expose API keys in client-side code
- Use environment variables for key storage
- Rotate keys regularly (quarterly recommended)
- Use separate keys for test and production environments
- Implement key scoping - use least privilege principle
Webhook Security
- Verify webhook signatures - Flexprice does this automatically
- Use HTTPS only for webhook endpoints
- Implement replay protection via idempotency
- Rate limit webhook endpoints
- Log all webhook events for audit trails
Customer Data
- Never store raw card numbers - use tokenized references only
- PCI compliance - Stripe handles card data securely
- Encrypt sensitive data at rest and in transit
- Implement access controls for customer information
- Regular security audits
Recommended Dashboards
- Billing Overview: Total revenue, invoice count, payment success rate
- Customer Health: Active subscriptions, churn rate, payment failures
- Integration Health: Sync success rate, webhook delivery, API errors
- Usage Analytics: Event volume by customer, feature adoption, usage trends
Support & Resources
API Documentation
Code Examples
Getting Help
- Flexprice Support: [email protected]
- Documentation: https://docs.flexprice.io
- Community: https://community.flexprice.io
- Stripe Support: https://support.stripe.com
Your Flexprice-Stripe integration is now complete and ready to handle automated usage-based billing with seamless payment processing! 🎉

