Scheduled Invoices

Scheduled Invoices

Scheduled invoices enable merchants to automate recurring billing for their customers using the Stax Pay API. By creating a schedule record, you can define when and how often invoices are generated, with options to automatically charge a saved payment method (autopay) or allow the customer to manually pay each invoice.

How Scheduled Invoices Work

A schedule record acts as an "invoice generator." It stores information such as:

  • Customer Details: Who the invoice is for.
  • Invoice Details: The total amount, taxes, line items, and other metadata.
  • Frequency Rules: How often the invoice should be generated (daily, weekly, monthly, etc.).
  • Autopay Setup: Optional saved payment method to automatically process payments.

At each scheduled interval:

  1. An invoice is generated based on the schedule's details.
  2. If a payment method is attached (autopay), a payment is attempted immediately.
  3. The system updates the schedule's next_run_at field to calculate the next occurrence.

Note: If no payment method is attached, the customer can manually pay the invoice, and optionally save a payment method for future use.

Schedule Lifecycle and Statuses

Scheduled invoices can have the following statuses:

StatusDescription
NOT STARTEDThe schedule's DTSTART is in the future, and the schedule has not yet generated any invoices.
WAITINGThe schedule is active and awaiting the next run date.
PENDINGThe DTSTART has passed, but the system has not yet processed the schedule.
PAUSEDThe schedule has been paused manually, and the next_run_at is set to null.
COMPLETEDThe schedule has reached its defined end (COUNT or UNTIL parameters).
DELETEDThe schedule has been soft-deleted, making it inaccessible but still stored in the database.

Key Status Transitions

  • Pause and Resume: Pausing a schedule clears the next_run_at field. To resume, set active=true and update the DTSTART with a future date.
  • Delete: Deleting a schedule sets the deleted_at field, halts future occurrences, and makes the schedule inaccessible.