Docs menuFeatures

DOCS / FEATURES

Billing

LaunchCrate bills each organization per seat, monthly or yearly, through a pluggable payment provider (Stripe, Paddle, Polar or Lemon Squeezy). It can bill metered usage on top and sell one-time products such as "Pro for life". The code lives in api/src/billing/, split so that only one file per vendor knows the vendor exists.

api/src/billing/
├── provider.rs        # the PaymentProvider trait and neutral types
├── providers/
│   ├── stripe.rs      # Stripe adapter + POST /api/webhooks/stripe
│   ├── paddle.rs      # Paddle adapter + POST /api/webhooks/paddle
│   ├── polar.rs       # Polar adapter + POST /api/webhooks/polar
│   └── lemonsqueezy.rs # Lemon Squeezy adapter + POST /api/webhooks/lemonsqueezy
├── service.rs         # checkout, portal, seat sync, cancellation, webhook pipeline
├── plans.rs           # plan catalog and entitlement guards
├── products.rs        # one-time products and what they grant
├── usage.rs           # usage meters, counting, and the hourly report
├── repo.rs            # customers, subscriptions, webhook dedup markers
└── routes.rs          # HTTP surface

Billing is optional. Until the active provider's API key is set (and, for Lemon Squeezy, LEMONSQUEEZY_STORE_ID), state.payments is None and checkout/portal answer 503 not_configured. Seat sync, and the cancellation that runs before an org (or an account that owns one) is deleted, become no-ops, so member changes never depend on a provider being reachable.

The provider seam

PaymentProvider (api/src/billing/provider.rs) is the complete outbound surface. Each operation can be expressed against Stripe, Paddle, Lemon Squeezy and Polar:

Method Does
create_customer Creates a provider customer for an org (name + the owner's email)
create_checkout_session Returns a hosted-checkout URL for a price and seat quantity
create_portal_session Returns a customer-portal URL
sync_seat_quantity Sets the subscription's quantity, prorated
cancel_subscription Cancels immediately
create_purchase_checkout Returns a hosted-checkout URL for a one-time payment
report_usage Bills units of a meter on a subscription
change_subscription_price Moves a subscription to another price (plan or interval), billing the prorated difference now
resolve_promotion_code Looks up a code for a price: its provider id and what it gives, or none
subscription_discount Describes the discount running on a subscription

There is also capabilities(), which reports what the provider honours (trial_days_per_checkout, redirect_urls, promotion_codes, usage_billing) so the UI doesn't promise what the provider would ignore.

Everything above the trait speaks provider-neutral terms: string ids, URLs, and a normalized status vocabulary. Exactly one provider is active per deployment, selected by PAYMENT_PROVIDER. Rows in subscriptions and billing_customers record which provider wrote them.

Every adapter but Stripe's calls its provider over HTTP. The Polar and Lemon Squeezy adapters also take a base URL, so api/tests/billing_adapters.rs can point them at a local server that records each request and answers like the docs say.

Adding a provider is one file in providers/ implementing the trait and a webhook handler, an arm in providers::from_config (api/src/billing/providers/mod.rs), a variant in PaymentProviderKind (api/src/config.rs), and a webhook route in api/src/routes.rs. FakePaymentProvider in provider.rs is a recording test double that also serves as a reference implementation.

Plans and entitlements

The plan catalog lives in code (api/src/billing/plans.rs), and the provider owns the money. Display prices are cosmetic, so keep them in sync with your provider dashboard.

Plan max_seats Audit log Webhooks SSO Custom roles Price ids from
free 3 no no no no — (always available)
pro 10 yes yes no no STRIPE_PRICE_PRO, STRIPE_PRICE_PRO_YEARLY (or PADDLE_PRICE_…, POLAR_PRODUCT_…, LEMONSQUEEZY_VARIANT_…)
scale 100 yes yes yes yes STRIPE_PRICE_SCALE, STRIPE_PRICE_SCALE_YEARLY (or PADDLE_PRICE_…, POLAR_PRODUCT_…, LEMONSQUEEZY_VARIANT_…)

Each paid plan can be sold monthly, yearly, or both. Its intervals lists the ones whose price id is set for the active provider, and it's available when there's at least one. price_monthly_usd and price_yearly_usd are cosmetic (the yearly figures are "two months free", $290 and $990). No column stores the interval: it comes from matching the subscription's price id, so the same match gives both the plan and the interval. Startup refuses a price id used in two slots, since that match would be ambiguous. GET /api/billing/plans (public) returns the catalog.

An org's effective plan is resolved from the local mirror, never by calling the provider. Take the newest subscription whose status is active, trialing, or past_due (a grace period: the UI nags rather than cutting access) and map its price id to a plan. Take any plan its unrefunded one-time purchases grant. Use the better of the two. Neither means free, and so does a price id that matches no plan (logged as a warning, since it means a paying org silently dropped to Free).

Entitlement guards answer 402 plan_limit with a message to show the user:

  • plans::require_seat_available: seats (see Organizations)
  • plans::require_audit_access: the audit log
  • plans::require_webhook_access: outbound webhooks (see Webhooks)
  • plans::require_sso_access: single sign-on (see Single sign-on)
  • plans::require_custom_roles_access: creating, editing and handing out custom roles (holders keep theirs after a downgrade)

Each plan also carries ai_tokens_per_month, the AI chat's monthly allowance: 50,000 on Free, 1,000,000 on Pro, 5,000,000 on Scale, and 0 on every plan when the server has no chat model.

To add an entitlement, add a field to Plan, set it per plan in build_catalog, and write a guard next to the existing ones.

Checkout and portal

Method Path Who
GET /api/orgs/{org_id}/billing Member or API key: {plan, interval, subscription, seats_used, provider, usage, purchases}
POST /api/orgs/{org_id}/billing/checkout Admin: {"plan": "pro", "interval": "year", "promo_code": "LAUNCH50"} → {"url"}. interval defaults to month, promo_code is optional
POST /api/orgs/{org_id}/billing/change Admin: {"plan": "scale", "interval": "month"} → 202
POST /api/orgs/{org_id}/billing/portal Admin: {"url"}

"Admin" here means the manage_billing permission: owners and admins hold it, and so can a custom role.

Checkout:

  1. Refuses with 409 conflict when the org already has a live subscription (active, trialing or past_due), before any provider call. A second checkout would open a second subscription and bill the org twice. A paying org changes plan instead (see Plan changes). The check reads the local mirror, so it starts protecting once the first subscription's webhook has arrived. Two checkouts completed within that delay, seconds in practice, can still both go through.
  2. Picks the plan's price for the interval (422 when it has none), refuses with 422 when the org already owns this plan or a better one as a one-time purchase (see One-time purchases), and, with a promo_code, resolves it (see Promotion codes).
  3. Ensures the org has a provider customer, creating one with the owner's email on first use. A race between two requests is resolved in favour of the stored row.
  4. Creates a hosted checkout for that price with quantity = max(members, 1), org_id stamped into provider metadata, TRIAL_DAYS (Stripe only), and success/cancel URLs back to {APP_URL}/orgs/{org_id}?billing=success|cancelled. Stripe and Polar use both URLs, Lemon Squeezy only the success URL, and Paddle neither (see Paddle).
  5. Records billing.checkout_started in the audit log, with the interval and any code.

The SPA redirects the browser to the returned URL. The subscription itself arrives later, by webhook.

Per-seat quantities

The billing.sync_seats job runs after every membership change and sets the live subscription's quantity to the org's current member count. It skips the update when the provider already has that count, and does nothing without a configured provider or a live subscription. Checkout and plan changes bill the same member count (at least 1). Pending invitations reserve a seat against the plan's limit but aren't billed until someone accepts one.

Provider Sets Yearly Monthly
Stripe the seat item's quantity invoiced at once (always_invoice) prorated onto the next invoice (create_prorations)
Paddle the item's quantity charged at once (prorated_immediately) charged at once (prorated_immediately)
Polar the subscription's seats invoiced at once (invoice) prorated onto the next invoice (prorate)
Lemon Squeezy the first subscription item's quantity no proration setting is sent; the store's default applies same as yearly

A yearly subscription's next invoice may be eleven months away, which is why Stripe and Polar invoice its seat changes at once.

Dunning

A failed payment (Stripe invoice.payment_failed, Paddle transaction.payment_failed, Lemon Squeezy subscription_payment_failed) queues an email.payment_failed job to the org owner, linking to {APP_URL}/orgs/{org_id}, and records billing.payment_failed. Access continues while the subscription is past_due. When the provider finally cancels, the next webhook drops the org back to free. Polar queues no dunning email: it emails the customer itself, and the app only mirrors the past_due status.

[ full guide ]

The rest of this guide comes with the repo.

  • Plan changes
  • Promotion codes
  • One-time purchases
  • Usage billing
  • Webhooks
  • Stripe
  • Paddle
  • Polar
  • Lemon Squeezy
  • Local mirror
Get LaunchCrate