Billing Lifecycle
In a nutshell
The billing engine is centered on subscriptions, invoices, payment attempts, and payment sources.Upcoming invoices
The invoice service creates upcomingdraft invoices for active subscriptions whose currentBillingCycleStart falls within the next 3 days and does not already have a draft/open invoice for that due date.
Events/emails:
invoice.upcomingupcoming_invoice.html
Due invoices
A due subscription is active, hascurrentBillingCycleStart <= now, and either has no trial or has already started paid billing.
Processing behavior:
- Ensure an invoice exists.
- Open draft invoice if needed.
- Attach invoice as subscription
latestInvoiceId. - If no payment source exists, create checkout.
- If active card source exists, charge tokenized card.
- On success, mark invoice paid and advance cycle.
- On failure, mark invoice failed and pause subscription.
Trial lifecycle
Trial fields are date-based. There is no separatetrialing status.
| Field | Meaning |
|---|---|
trialStartDate | Trial begins. |
trialEndDate | Trial ends. |
trialEndingSoonSent | Prevents duplicate soon-ending notification. |
startedAt | Paid billing has started. |
subscription.trial_ending_soonsubscription.billing_startedtrial_ending_soon.htmltrial_ended_billing_started.html
Payment failure
Failed collection sets:- Invoice
status = failed - Invoice
failedAt - Invoice
failureReason - Subscription
status = paused - Subscription
pausedAt
invoice.payment_failedorinvoice.marked_uncollectiblesubscription.pausedsubscription_paused.html
