Test
Before going live, use your sandbox environment to thoroughly test the Usage-based Billing integration. Your testing should involve:1. Billing infrastructure setup
- Metrics: Create, update, and validate metrics with different aggregation types and fields
- Pricing plans: Create plans with various fee structures (subscription, usage-based, minimum commitments)
- Customer management: Register customers, update details, and test customer lifecycle
- Subscriptions: Create subscriptions, handle plan changes, and test trial periods
2. Prepaid credits and wallets
- Wallet creation: Test manual credit management and automatic top-up configurations
- Top-up strategies: Validate fixed amount and target balance methods with different triggers (schedule, threshold)
- Wallet scenarios:
- Partial balance (insufficient credits)
- Empty wallet (no credits)
- No wallet exists for customer
- Wallet management: Add credits, void credits, update configurations, and terminate wallets
3. Usage recording and billing
- Event recording: Test single events and batch submissions
- Usage aggregation: Verify events are properly aggregated according to metrics
- Invoice generation: Generate invoices and validate charge calculations
- Billing calculation: Test the complete payment priority system:
- Credit notes applied first
- Prepaid credits deducted second
- Payment method charged for remaining amount
4. Payment processing and issues
- Payment priority testing: Create scenarios with different combinations of credit notes, prepaid credits, and payment methods
- Payment failures: Test failed payment scenarios and retry functionality
- Credit notes:
- Create credit notes with refund amounts only
- Create credit notes with credit amounts only
- Create credit notes with both refund and credit amounts
- Test credit note wallet auto-creation
- Void credit notes and validate status changes
5. Monitoring and auditing
- Usage monitoring: Poll customer usage data and validate accuracy
- Event auditing: Retrieve and verify recorded usage events
- Credit note management: List, retrieve, and manage credit note details
- Wallet monitoring: Track wallet balances and transaction history
6. Webhooks and notifications
- Webhook setup: Configure and validate webhook endpoints
- Event testing: Test webhook delivery for:
- Invoice events (generated, payment failed, payment completed)
- Wallet events (balance changes, top-ups, termination)
- Credit note events (created, applied, voided)
- Webhook reliability: Test retry mechanisms and failure handling
7. Error handling and edge cases
- Invalid requests: Test with missing required fields, invalid data formats, and malformed requests
- Business logic errors: Test scenarios like:
- Recording events for non-existent subscriptions
- Creating credit notes for invalid invoices
- Insufficient wallet balances
- Duplicate transaction IDs
- Rate limiting: Test API rate limits and error responses
- Authentication: Test with invalid or expired access tokens
8. End-to-end workflows
- Complete billing cycle: From usage recording to invoice payment
- Customer lifecycle: From registration to subscription termination
- Payment issue resolution: From failed payment to successful retry with credit notes
- Prepaid credit flow: From wallet setup to credit consumption during billing