Skip to main content

Period Management

When a subscription is created, Fluxrate sets:
  • current_period_start = start_date
  • current_period_end = start_date + billing_interval
The invoice worker runs every hour. When it finds subscriptions where current_period_end <= now, it:
  1. Generates a DRAFT invoice for the period
  2. Calculates all fixed charges + metered usage
  3. Advances the period: current_period_start = old end, current_period_end = old end + interval
  4. Updates last_invoiced_date

Proration

When a subscription is created mid-month, the first invoice covers the partial period (prorated):
Plan: $30/month
Subscription start: Jan 15 (mid-month)
First period: Jan 15 → Feb 1

Prorated charge: $30 × (17 days / 31 days) = $16.45

Previewing an Invoice

Before the billing period ends, preview the current invoice:
POST /api/v1/subscriptions/<subscription_id>/preview-invoice
This returns a preview of what the invoice would look like if generated now, including all usage accumulated so far.

Manual Invoice Generation

Force generate an invoice immediately (useful for testing):
POST /api/v1/subscriptions/<subscription_id>/generate-invoice

Subscription Usage

View usage accumulated in the current billing period:
GET /api/v1/subscriptions/<subscription_id>/usage

Subscription Invoices

View all invoices for a subscription:
GET /api/v1/subscriptions/<subscription_id>/invoices