Skip to main content

Payments

Payments are optional: off on an installation without a Connect client id, and without effect on a workspace that links no account. Who does not sell does not see them.

The product decides access; Stripe decides the money. The product takes no payment, computes no invoice, handles no tax and stores no means of payment. Nothing of it is in the request path: the gateway sees an apikey, enabled or disabled — if the product is down, the traffic flows, the one of a customer whose payment just failed included, until the next projection.

The Stripe account of a workspace​

A workspace sells its paid plans through its own Stripe account, linked by Stripe Connect: Workspace settings › Payments › Link a Stripe account sends one of its administrators to Stripe, who authorises the installation and comes back. The product keeps the id of the account, its name and whether it is live — never a key of it; it calls Stripe with the key of the installation, on behalf of the account. Unlinking is refused while paid subscriptions are open; an account that takes its authorisation back from Stripe is unlinked.

A paid plan is published only once the account is linked: before, the draft says why and the publication is refused — a consumer never meets a plan nobody can pay. The same with payments off on the installation.

The installation sets, once:

Variable
APIM_PAYMENTS_PROVIDERstripe, fake (the development and the tests) or off (the default without a Connect client id)
APIM_STRIPE_SECRET_KEYthe secret key of the platform's Stripe account
APIM_STRIPE_CLIENT_IDthe Connect client id (ca_…)
APIM_STRIPE_WEBHOOK_SECRETthe secret of the Connect webhook endpoint (whsec_…)
APIM_STRIPE_API_VERSIONthe version of the Stripe api the product speaks, 2025-03-31.basil
APIM_PAYMENTS_RECONCILE_MShow often the paid subscriptions are read again from Stripe, every hour

The webhook: one endpoint for every linked account, <public url>/payments/stripe/webhook, registered once in the Stripe dashboard of the platform as a Connect endpoint, with the events checkout.session.completed, customer.subscription.updated, customer.subscription.deleted and account.application.deauthorized.

Paying a plan​

  1. On the portal, a consumer subscribes an application to a paid plan: the subscription waits in pending_payment.
  2. Pay opens a Stripe Checkout, a page of Stripe, on the account of the workspace. The price is the plan's — its amount, currency and interval — unless the plan names a price at Stripe; the id of the subscription goes in the metadata.
  3. Stripe tells the product (checkout.session.completed): the subscription becomes active, and only then its key is projected on the gateway.

The team pays. Its billing account at Stripe — one per team and Stripe account — groups the invoices of its applications. Invoices and card, on the application in the portal, opens the customer portal of Stripe: invoices, means of payment, cancellation. The product has no screen for them.

What follows​

The subscription follows what Stripe says of its Stripe subscription:

At StripeThe subscriptionIts key
active, trialingactive, paidenabled
past_due — a payment failed, Stripe retriesactive, past dueenabled, for the grace period of the plan at most
past due beyond the grace periodsuspended for want of paymentdisabled
unpaid, incomplete_expired, pausedsuspended for want of paymentdisabled
paid againresumed — what a producer suspended stays suspendedenabled
canceledcloseddeleted

The other way round, closing a paid subscription in the product cancels it at Stripe, and a move between two paid plans changes its price at Stripe, prorated.

A move from a free plan to a paid one goes through a payment. Once agreed — the consumer asks and the producer applies, or the producer proposes and the consumer agrees — it waits for the consumer's payment: the subscription stays on its free plan, its key working, and the portal offers to pay the move, through a Checkout of the paid plan, or to drop it. When Stripe says it is paid, the subscription moves to the paid plan with the same key, and its payment is followed as any other. Either side can drop a move that waits for its payment.

Billing the usage​

A paid plan can bill the usage of its subscriptions, with its recurring price or alone (a price of 0): Plan › Pricing › Usage price. It names a metered price at Stripe (price_…) and the event name of its meter, on the Stripe account of the workspace, and what is counted: the calls answered below 400 (success), or every call the gateway served — below 500, a 429 of the quotas aside (served). The Checkout then bills the metered price beside the recurring one. The price of a call the portal shows is the one the plan says: keep it equal to the metered price at Stripe.

The usage is counted from the computed path — every call, never sampled — and pushed to the meter in batches, after the rollups, every five minutes: the gateway never sends an event per call. A batch is the calls received since the last one, taken by id like the rollups — a late call goes in the next batch, none is counted twice — and makes one report per subscription, at the price of the plan the calls were made on, in one transaction with the move of the watermark. A report is then sent once — its id is the identifier Stripe dedupes on — and replayed until it is. The calls are kept until they are billed.

The reports of a subscription are on its drawer in the console (Usage billed), in the admin API (GET …/subscriptions/<id>/usage) and the CLI (subscriptions usage); the consumer sees, on the application in the portal, the calls reported to the billing. A plan with a usage price is refused when the payment provider of the installation cannot meter.

Billing is where usage can be added up across the APIs of an application, after the fact: the invoice adds, the enforcement does not — each subscription keeps its own quotas.

Lost webhooks, replayed ones​

A webhook is checked by its signature (and its age: five minutes, against a replay), kept once by its id — Stripe redelivers what it is not sure was received — and handled by the projection queue, so that a failure is retried. Every event and what it did is listed in Workspace settings › Payments.

A webhook can also be lost: the product reconciles its paid subscriptions with Stripe every hour (and on demand, Reconcile now), the way it reconciles with the gateway.

In the development​

APIM_PAYMENTS_PROVIDER=fake — the default of the docker stack — stands for Stripe: linking an account answers at once, a Checkout is a page of the product that pays or cancels, and the events are the ones Stripe would send, signed, on the same endpoint. mise run demo links it to the default workspace. The product refuses to start with it when NODE_ENV=production — the setting of its image.