Aug 15, 2026 · Preyforge
How subscription billing works in Quarry
Billing bugs are the most expensive bugs a SaaS can have. Quarry keeps the Stripe integration small, explicit and testable.
The kit itself is a one-time purchase. The plans and checkout below are what your customers use inside the product you ship — not how you buy Quarry.
The flow
- An organization owner picks a plan; the app creates a Stripe Checkout
session with the organization ID in
metadata. - Stripe redirects back to the app, and delivers a
checkout.session.completedwebhook. - The webhook handler verifies the signature, fetches the subscription and
writes it to the
subscriptiontable — the only write-path for billing state. - Later plan changes and cancellations arrive as
customer.subscription.updated/deletedevents and go through the same path.
Why one write-path matters
Because every state change funnels through applySubscriptionState, the
whole flow is unit-testable with fake events — no Stripe account needed. The
database is always a faithful mirror of Stripe, and the UI only ever reads
from the database.
Trying it locally
Run the Stripe CLI with stripe listen --forward-to localhost:3000/api/webhooks/stripe and use the test card 4242 4242 4242 4242. The kit works without any Stripe keys, too — billing UI simply shows
as not configured.