Payments & Money APIs · Webhooks, Orchestration & Recurring Payments

Subscriptions, Invoicing & Dunning

Recurring billing, proration, failed payments and entitlements.

Subscriptions add plans/prices, billing cycles, trials, proration on upgrades/downgrades, invoices, taxes, and dunning (retrying failed renewals with smart schedules, card updater, emails). Use a billing system (Stripe Billing, Chargebee, Recurly, or the PSP's) rather than building one, and keep entitlements (what the customer can use) in your app, driven by billing events (invoice.paid, customer.subscription.updated/deleted). Decide grace-period policy: how long access continues while payment is past due.

Build vs buy billing

Concern Build yourself Billing platform
Proration math Complex, error-prone Built in
Dunning & smart retries Must build Built in
Tax & invoices Integrate tax engine, PDFs Built in / integrated
Usage-based billing Metering pipeline Meters + aggregation
Revenue recognition Hard Add-ons
Control & cost Full; engineering time Less; platform fees

Python (entitlements from events)

async def on_billing_event(event):
    sub = event.data.object
    account = await accounts.by_customer(sub.customer)
    if event.type in ("customer.subscription.created", "customer.subscription.updated"):
        await entitlements.set(account.id, plan=sub.items.data[0].price.lookup_key,
                               status=sub.status,                      # active | trialing | past_due | canceled…
                               current_period_end=sub.current_period_end)
    elif event.type == "customer.subscription.deleted":
        await entitlements.downgrade_to_free(account.id)
# Access check: active/trialing → full; past_due → grace period banner; canceled → free tier

Common pitfalls

  • Checking the PSP on every request for access (latency, rate limits).
  • Immediate lockout on first failed renewal.
  • Ignoring proration and tax on plan changes.

Key points

  • Use a billing platform
  • Entitlements in your app, driven by events
  • Explicit dunning and grace policy

Further reading: Stripe Billing: How subscriptions work

Practice questions

What is dunning?

Answer

The process of recovering failed recurring payments: retry schedules, card updates and customer notifications before cancelling.

Why keep entitlements in your own database instead of querying the PSP each request?

Answer

For low latency and resilience; the PSP is the source of billing truth, synced via events, while your app makes fast local access decisions.

Open in the app to mark lessons complete, take notes and track your progress.