The Four States
1. Draft
Initial state for unpublished invoices An invoice in draft state has been created but not sent to the customer. Characteristics:status: draftsent_date: null- Customer has not been notified
- No payment link active
- Can be modified freely
- Review invoices before sending
- Batch preparation of monthly invoices
- Approval workflows
- Price calculations that need verification
nodejs
2. Not Paid (Published)
Active invoice awaiting payment The invoice has been sent to the customer and is awaiting payment. Characteristics:status: "not-paid"sent_date: <ISO timestamp>paid_date: null- Customer has received email notification
- Payment link is active
- Can still be updated (with caution)
- Standard invoice flow
- Active subscription billing
- Pending payments
- Awaiting customer action
nodejs
nodejs
3. Paid
Invoice successfully paid Payment has been received and confirmed. Characteristics:status: "paid"paid_date: <ISO timestamp>- Payment link no longer accepts payments
- Final state (cannot transition back)
- Triggers
paymentrequest.successwebhook event
- Successful subscription payment
- Grant service access
- Generate receipt
- Update billing records
- Provision resources
4. Overdue
Payment deadline passed without payment The due date has passed and the invoice remains unpaid (production mode only). Characteristics:status: "overdue"paid_date: null- Due date has passed
- Only in production mode (not test mode)
- Automatically set at midnight on due date
- Triggers
invoice.overduewebhook event - Can still transition to paid
- Subscription payment failures
- Grace period enforcement
- Service suspension
- Collections process
- Dunning management
State Transitions
Creating Invoices
Direct Creation (Published):nodejs
nodejs
Publishing Drafts
nodejs
Payment
nodejs
Overdue Detection
nodejs
Timeline Example
Here’s a complete subscription invoice lifecycle:Working with Invoice States
Checking Current State
nodejs
State-Based Business Logic
nodejs
Subscription State Management
nodejs
Important Timestamps
Invoices track several key timestamps:nodejs
Test Mode vs Production
Test Mode Behavior
nodejs
Production Mode Behavior
nodejs
Best Practices
Always Use Webhooks for Status Changes
Always Use Webhooks for Status Changes
Don’t poll for status changes. Implement webhook handlers for
paymentrequest.success and invoice.overdue events for real-time updates.Set Reasonable Due Dates
Set Reasonable Due Dates
For subscriptions, set due dates 7-14 days after invoice creation to give customers time to pay. For monthly billing, due date should be before the next billing cycle.
Implement Grace Periods for Overdue
Implement Grace Periods for Overdue
Don’t immediately suspend services when invoices go overdue. Implement a 3-7 day grace period with automated reminders before taking action.
Use Drafts for Batch Processing
Use Drafts for Batch Processing
When generating invoices for many customers, create drafts first, review for accuracy, then publish in batches.
Track reminder_count
Track reminder_count
Monitor
reminder_count to avoid spamming customers. Implement logic like: reminder at 7 days before due, at due date, and 3 days after due date.Test Thoroughly in Test Mode
Test Thoroughly in Test Mode
Test your entire flow in test mode before going live. Remember: test invoices never go overdue, so test overdue logic separately.
Common Patterns
Subscription Billing State Machine
nodejs
