Automated Billing

Set up a daily cron to generate invoices, send overdue reminders, and auto-suspend delinquent services.

Last updated : April 19, 2026

How it works

A single GET request to /api/cron/billing (protected by a bearer token) runs three tasks in sequence:

  • Invoice generation β€” creates UNPAID invoices for services due within 3 days
  • Overdue marking β€” flips UNPAID invoices to OVERDUE once past their due date, and sends a reminder email
  • Auto-suspension β€” suspends services whose invoice has been OVERDUE for 7+ days, and notifies the client

Setup

Add a secret token to .env:

CRON_SECRET="a-long-random-secret"

Cron endpoint

Schedule the following command to run once a day (e.g. at 02:00 UTC) on your VPS:

0 2 * * * curl -s -H "Authorization: Bearer $CRON_SECRET" https://your-domain.com/api/cron/billing
πŸ’‘
The endpoint returns JSON with counts: { generated, markedOverdue, suspended }.

After payment

When a payment is received via Stripe, the webhook automatically:

  • Marks the invoice PAID
  • Records the payment with the Stripe transaction ID
  • Advances the service nextDueDate by one billing cycle
  • Reactivates the service if it was SUSPENDED