Skip to main content
TRXN automatically generates invoices from active subscriptions through the GenerateInvoicesJob. This ensures that recurring charges are billed on time without manual intervention.

How it works

1

Scheduled execution

The GenerateInvoicesJob runs on a regular schedule, typically daily. It evaluates all subscriptions to determine which ones are due for billing.
2

Subscription processing

The job iterates through all subscriptions and checks billing eligibility based on the subscription’s next billing date and the current time.
3

Active phase check

Only subscriptions with an active phase containing recurring items are processed. If a subscription has no active phase or the active phase contains only one-time items, it is skipped.
4

Due date calculation

The job compares each subscription’s next_billing_date with the current time. If the billing date has arrived or passed, the subscription is eligible for invoice generation.
5

Invoice creation

For each eligible subscription, the job generates an invoice with line items corresponding to the recurring phase items in the active phase.

Invoice structure

When an invoice is generated, it contains:
  • Invoice level — customer, account, and subscription references
  • Line items — one line item per subscription phase item
  • Pricing — uses overridden prices when set, otherwise falls back to the base product price
  • Quantities — reflects the quantity specified in each phase item

Example

Subscription: John's Enterprise Plan
Active Phase: "Regular Pricing" (contains 3 recurring items)
Next Billing Date: 2024-01-15
Current Date: 2024-01-15

Generated Invoice:
├── Line Item 1: Base Platform Access -- $199.00 (qty: 1)
├── Line Item 2: Additional User Seats -- $125.00 (qty: 5 x $25)
└── Line Item 3: Premium Support -- $50.00 (qty: 1)

Total: $374.00

Duplicate prevention

The invoice generation system includes safeguards to prevent duplicate invoices. If an invoice has already been generated for a billing period, the job will not create another one for the same period.

Billing cycle anchors

Invoice generation respects billing cycle anchors. When a subscription has an anchor set, the next_billing_date calculation aligns with the anchor date rather than the subscription creation date.

Initial invoices

When a subscription is first created, the system may generate an initial invoice depending on the proration behavior:
Proration behaviorInitial invoice
create_prorationsProrated charge for the partial period between creation and the billing anchor
always_invoiceImmediate full-price invoice
noneNo initial invoice if an anchor is set; immediate full-price invoice if no anchor