Prompt
How do I generate invoices for monthly and annual SaaS subscriptions?
Latest observation
Oct 15, 2026
OpenAI APIWeb search: off
To generate invoices for monthly and annual SaaS subscriptions, use a subscription billing flow that ties billing cycles, proration, taxes, and invoice generation together.
1) Define the billing model
For each plan, store:
- Plan price: e.g. $20/month or $200/year
- Billing interval: monthly or annual
- Renewal date
- Trial period (if any)
- Tax settings: VAT/GST/sales tax rules
- Currency
- Customer billing details: company name, address, tax ID, payment method
2) Generate invoices on a billing schedule
Monthly subscriptions
Create an invoice:
- At signup if billing starts immediately, or
- At the start of each monthly cycle, or
- At the end of the free trial
Then repeat every month on the renewal date.
Annual subscriptions
Create one invoice:
- At signup or annual renewal
- Covering the full 12-month period
Example
- Customer subscribes on Jan 10
- Monthly plan: invoice for Jan 10–Feb 9, then next invoice on Feb 10
- Annual plan: invoice for Jan 10–Jan 9 next year
3) Handle proration
If the customer upgrades/downgrades mid-cycle:
- Calculate the unused portion of the old plan
- Calculate the remaining portion of the new plan
- Add a proration line item or credit memo
Example:
- Monthly plan: $30/month
- Upgrade on day 15
- Credit for 15 unused days of old plan
- Charge for remaining days of new plan
4) Build the invoice line items
Typical line items:
- Subscription fee
- Proration adjustments
- Discounts/coupons
- Taxes
- One-time charges
- Late fees (if applicable)
Invoice totals usually look like:
- Subtotal
- Tax
- Total
- Amount due
5) Automate invoice creation
A basic invoice-generation process:
- Detect subscription start or renewal
- Calculate charge amount
- Apply discounts/proration
- Compute taxes
- Generate invoice record
- Send invoice to customer
- Attempt payment via saved card or ACH
- Mark paid or schedule reminders
6) Use invoice statuses
Common statuses:
- Draft
- Open/Sent
- Paid
- Past due
- Void
- Uncollectible
7) Keep invoice numbering and compliance
Make sure invoices include:
- Unique invoice number
- Issue date
- Service period
- Billing address
- Tax ID if required
- Your business legal details
8) Implementation options
You can:
- Use a billing platform like Stripe Billing, Chargebee, Recurly, Paddle, Zuora
- Build it yourself with scheduled jobs and your own invoice templates
If building yourself, a common setup is:
- Cron/job queue for renewals
- Subscription database table
- Invoice table
- Line items table
- Payment gateway integration
- PDF generator + email sender
9) Simple pseudocode
def create_invoice(subscription):
period_start, period_end = get_billing_period(subscription)
base_amount = subscription.plan_price
proration = calculate_proration(subscription) # 0 if none
discount = apply_discount(subscription.customer, base_amount)
tax = calculate_tax(subscription.customer, base_amount + proration - discount)
total = base_amount + proration - discount + tax
invoice = Invoice(
customer_id=subscription.customer_id,
period_start=period_start,
period_end=period_end,
line_items=[
("Subscription fee", base_amount),
("Proration", proration),
("Discount", -discount),
("Tax", tax),
],
total=total
)
save(invoice)
send_invoice(invoice)
charge_payment_method(invoice)
return invoice
10) Best practices
- Invoice in the customer’s local currency if possible
- Store tax evidence for compliance
- Send reminders before renewal
- Grace periods for failed payments
- Use webhooks/events to keep subscription state in sync
- Generate invoices idempotently to avoid duplicates
If you want, I can also show you:
- a database schema for SaaS invoices,
- a Stripe Billing setup, or
- a sample invoice generation algorithm in Python/Node.js.