Access & APIsUpdated 2026-11-20

Payments and billing

Letting a provider hold the money while the app keeps entitlements in sync: webhooks, idempotency keys, metering and reconciliation.

The card terminal run by a bank. We never touch card numbers.

That is the whole safety idea. The customer taps their card on the bank's machine. The shop only learns whether it worked.

How it works

Payments and billing means charging customers, keeping what they are entitled to in step with what they paid for, and recovering failed payments. The payment provider is the source of truth for money. The app keeps a synced copy.

Code
Hosted checkout → provider creates the subscription
Provider webhook → inbox (verify, dedupe) → sync customer → local subscription + entitlements
Feature → check entitlement → meter usage → provider bills later
Nightly job → compare local state with the provider

Key concerns

  • Source of truth. Never trust the success-page redirect alone. One function re-reads the customer's state from the provider and writes it locally. Both the webhook and the success page call it.
  • Webhooks. Verify the signature, store the event, return 2xx fast and process later. Expect duplicates and out-of-order events. See webhooks.
  • Idempotency. Send an idempotency key on every create call, and make handlers safe to run twice. See idempotency.
  • Entitlements. Map plans to features and limits in one place. The interface and API check entitlements, not plan names.
  • Usage metering. Record usage locally and exactly per tenant, then report it. Hard caps come from your own counters, because providers bill usage after the fact.
  • Credits. Prepaid credits are a ledger of grants, reservations, debits and expiries. The balance is the sum of entries, never an overwritten number.
  • Dunning. Retry smartly, send reminders, allow a grace period, then restrict access. Never delete data on the first failure.
  • Proration. Decide upgrade and downgrade rules up front.
  • Tax. Use the provider's tax product or a merchant of record for VAT and sales tax.
  • Reconciliation. A nightly comparison between local and provider state alerts on drift.

Do not handle raw card data

Use a hosted checkout and a customer portal. The provider takes on card storage, compliance and retries, and your servers never see card numbers.

Testing time

Billing is mostly about time: trials ending, renewals, grace periods and retries. Waiting for real days to pass is not a test strategy. Providers offer test clocks that move a test customer through a month in a few calls, so you can check what happens on renewal, on a failed card and on a downgrade. Use them to confirm entitlements change at the right moment, that reminders go out, and that data is restricted, not deleted, when payment lapses.

Where I used it

I haven't shipped live payments in a public project, and I make no live-payment claim for anything on this site.

IMS builds payments in source, as part of its sales and documents. I will not describe that as a provider or card integration, and IMS is in progress with no production claim. The ledger thinking in this note similar in spirit to how IMS records stock and money: append-only entries, with corrections as new documents, and money held as decimal strings.

Trade-offs

BenefitCost
Provider handles cards, PCI, tax and retriesLock-in and fees
Hosted checkout and portal ship fastLess control over the interface
Usage billing aligns price with costComplex metering, and surprise bills if uncapped
  • Do not build your own billing engine for invoicing, tax and retries before the product has proven itself.
  • Two copies of the truth. The local copy can drift. That is why reconciliation exists.
  • Failure paths are the product. Failed cards, expired trials and refunds take more design than the happy path.

A useful rule: let the provider hold the money, keep your own exact record of usage, and check the two against each other every night.