Skip to content

feat(billing): take payment through Stripe - #352

Merged
artempartos merged 5 commits into
artempartos/domain-verificationfrom
artempartos/stripe-billing
Sep 29, 2026
Merged

artempartos merged 5 commits into
artempartos/domain-verificationfrom
artempartos/stripe-billing

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Stacked on #351. Merge that first; the diff here is the last commit alone.

Why

Capacity has been measured and recorded since the metering work. Nothing was ever
sent anywhere, and there was nowhere for a customer to pay: a workspace that spent
its free allowance stopped, and the only way out was a platform administrator
moving a column by hand.

What

Billing::StripeClient The one place this application talks to Stripe
Billing::Meter::Stripe Stops logging; sends one meter event per company per hour
Web::Company::BillingCheckoutsController Opens Stripe's own card page
Webhooks::StripeController Acts on what comes back
TrialBanner Offers Add a card where there is somewhere to pay

Replays cannot bill twice

The part that had to be proved against the real API rather than reasoned
about.
Each meter event carries an identifier built from the company and the
hour. Stripe answers a repeat with a 400 carrying neither a code nor a param —
the message is the only signal there is — and our delivery loop treats any raised
error as a failure and replays the hour from the ledger.

Left alone, the first partial failure would have replayed that hour on every run
until the six-hour window closed, failing every time and reporting a broken
provider. The duplicate is now read as recorded and counted separately on the
ledger row (sent=N:already=M). If Stripe ever changes the wording, the hour
looks failed, is replayed, is refused again and is abandoned at the window:
noise, never a second bill.

I found this by sending the same hour twice at the real test account. No mock
would have shown it.

The signature is the authentication

The webhook URL appears in Stripe's dashboard and in delivery logs, so it grants
nothing on its own. A body not signed with this endpoint's secret is refused
before it is read as anything, and an installation with no secret configured
accepts nothing at all. The tests sign real bodies and let the real adapter
verify them — the one path not driven through the fake.

past_due keeps a customer running on purpose: a failed payment starts a
dunning cycle that usually ends in payment, and stopping their work on the first
retry is the worse mistake. A company stopped by cancellation or non-payment goes
to blocked, not back to trialing — the free allowance was spent once and
cancelling does not return it.

Configured, or not at all

The Stripe customer is created lazily, on the first checkout rather than at
signup: signing up already waits on an email round trip, and a Stripe outage must
not be able to stop somebody registering.

With no credentials — every self-hosted installation, permanently — nothing calls
Stripe, the banner offers no button, the checkout endpoint refuses, and capacity
is still measured and recorded.

In the Stripe account (test mode)

Created and recorded in docs/operations/stripe-setup.md:

Meter mtr_test_…AXI — queue_minutes, sum, customer by stripe_customer_id
Product prod_VLYLkzDfhdW0A4
Price price_1UKrEiRfWGHL113SKW7Snqaa — $0.08333333/queue-minute = $5/queue-hour, monthly metered

The webhook endpoint is not created. It needs a public host, which is a
deployment decision rather than a code one — and until it exists, a card added
through Checkout is taken by Stripe and the company is not moved to active,
because the webhook is the only thing that does that.

The gem was pinned at ~> 15.6 in the first draft, a version that does not
exist; it is ~> 19.6, the current stable.

Checks

rubocop (1758 files), brakeman (0 warnings), tsc, eslint, steiger
clean. Frontend 1701/1701. Backend: the touched suites 706/706, run with
DEPLOYMENT_MODE=self_hosted to match CI. The full suite is left to CI, since a
worktree run shares a Postgres with the main checkout.

🤖 Generated with Claude Code

artempartos and others added 5 commits September 29, 2026 11:27
Capacity has been measured and recorded since the metering work; nothing was
ever sent anywhere, and there was nowhere for a customer to pay. A workspace that
spent its free allowance stopped, and the only way out was a platform
administrator moving a column by hand.

Four parts. Billing::StripeClient is the one place this application talks to
Stripe, so the decision "is Stripe even configured here" is asked once rather
than at every call site, and the tests below it drive a fake of it rather than
the vendor's classes. Billing::Meter::Stripe stops logging and sends one meter
event per company per hour. A checkout controller opens Stripe's own card page.
A webhook receiver acts on what comes back.

REPLAYS CANNOT BILL TWICE, and this is the part that had to be proved against
the real API rather than reasoned about. Each event carries an identifier built
from the company and the hour. Stripe answers a repeat with a 400 carrying
neither a code nor a param — the message is the only signal there is — and our
delivery loop treats any raised error as a failure and replays the hour. Left
alone, the first partial failure would have replayed that hour every run until
the six-hour window closed, failing every time. The duplicate is now read as
"recorded" and counted separately on the ledger row. A message that changes makes
the hour look failed and be abandoned at the window: noise, never a second bill.

THE SIGNATURE IS THE AUTHENTICATION on the webhook. The URL appears in Stripe's
dashboard and in delivery logs, so a body that is not signed with this endpoint's
secret is refused before it is read as anything, and an installation with no
secret configured accepts nothing at all. `past_due` deliberately keeps a
customer running: a failed payment starts a dunning cycle that usually ends in
payment, and stopping their work on the first retry is the worse mistake. A
company stopped this way goes to `blocked` rather than back to `trialing` — the
free allowance was spent once and cancelling does not return it.

The Stripe customer is made lazily, on the first checkout rather than at signup:
signing up already waits on an email round trip, and a Stripe outage must not be
able to stop somebody registering. With no credentials configured — every
self-hosted installation, permanently — nothing calls Stripe, the banner offers
no button, and capacity is still measured and recorded.

Test-mode meter, product and metered price created and recorded in the runbook.
The webhook endpoint is not: it needs a public host, which is a deployment
decision.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The banner told a blocked workspace to talk to us while showing it an "Add a
card" button. Two different answers in one line.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The two switches drift apart quietly and are found out by a customer: open
signup on a hosted deployment with no Stripe key, and people sign up, spend the
free allowance, and reach a stop with no card to add and no button to press.
Nothing in the application would have said so until it happened to somebody.

So the deploy refuses instead. Beside the encryption keys in required_env,
because it is the same kind of misconfiguration: harmless at boot, expensive
later. In the initializer rather than in Deployment.self_serve_signup? on
purpose — a key that goes missing must fail loudly rather than quietly closing
the door on new customers and leaving the ones inside wondering.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
It named Deployment and Billing::StripeClient from an initializer, where
Zeitwerk has not made them yet — NameError, and the image build died in
assets:precompile. The guard meant to stop a bad deploy stopped every deploy.

Moved into after_initialize rather than rewritten against ENV: a second copy of
the rule in environment-variable terms is a second thing to keep in step with
Deployment.self_serve_signup?, and it would drift the first time either changes.

Verified both ways against a production boot with the image build variables: it
boots clean where registration is closed, and refuses where it is open with no
Stripe key. A test pins the deferral so nobody moves it back.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Rubocop caught it, mine did not run: I edited the file after the last full pass
and went straight to the next thing.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@artempartos
artempartos merged commit 2e4f76b into artempartos/domain-verification Sep 29, 2026
7 checks passed
artempartos added a commit that referenced this pull request Sep 29, 2026
…lop) (#355)

* feat(billing): take payment through Stripe

Capacity has been measured and recorded since the metering work; nothing was
ever sent anywhere, and there was nowhere for a customer to pay. A workspace that
spent its free allowance stopped, and the only way out was a platform
administrator moving a column by hand.

Four parts. Billing::StripeClient is the one place this application talks to
Stripe, so the decision "is Stripe even configured here" is asked once rather
than at every call site, and the tests below it drive a fake of it rather than
the vendor's classes. Billing::Meter::Stripe stops logging and sends one meter
event per company per hour. A checkout controller opens Stripe's own card page.
A webhook receiver acts on what comes back.

REPLAYS CANNOT BILL TWICE, and this is the part that had to be proved against
the real API rather than reasoned about. Each event carries an identifier built
from the company and the hour. Stripe answers a repeat with a 400 carrying
neither a code nor a param — the message is the only signal there is — and our
delivery loop treats any raised error as a failure and replays the hour. Left
alone, the first partial failure would have replayed that hour every run until
the six-hour window closed, failing every time. The duplicate is now read as
"recorded" and counted separately on the ledger row. A message that changes makes
the hour look failed and be abandoned at the window: noise, never a second bill.

THE SIGNATURE IS THE AUTHENTICATION on the webhook. The URL appears in Stripe's
dashboard and in delivery logs, so a body that is not signed with this endpoint's
secret is refused before it is read as anything, and an installation with no
secret configured accepts nothing at all. `past_due` deliberately keeps a
customer running: a failed payment starts a dunning cycle that usually ends in
payment, and stopping their work on the first retry is the worse mistake. A
company stopped this way goes to `blocked` rather than back to `trialing` — the
free allowance was spent once and cancelling does not return it.

The Stripe customer is made lazily, on the first checkout rather than at signup:
signing up already waits on an email round trip, and a Stripe outage must not be
able to stop somebody registering. With no credentials configured — every
self-hosted installation, permanently — nothing calls Stripe, the banner offers
no button, and capacity is still measured and recorded.

Test-mode meter, product and metered price created and recorded in the runbook.
The webhook endpoint is not: it needs a public host, which is a deployment
decision.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(billing): point a stopped workspace at the button beside the words

The banner told a blocked workspace to talk to us while showing it an "Add a
card" button. Two different answers in one line.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(billing): refuse to boot with registration open and no way to pay

The two switches drift apart quietly and are found out by a customer: open
signup on a hosted deployment with no Stripe key, and people sign up, spend the
free allowance, and reach a stop with no card to add and no button to press.
Nothing in the application would have said so until it happened to somebody.

So the deploy refuses instead. Beside the encryption keys in required_env,
because it is the same kind of misconfiguration: harmless at boot, expensive
later. In the initializer rather than in Deployment.self_serve_signup? on
purpose — a key that goes missing must fail loudly rather than quietly closing
the door on new customers and leaving the ones inside wondering.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(billing): run the registration guard after initialization

It named Deployment and Billing::StripeClient from an initializer, where
Zeitwerk has not made them yet — NameError, and the image build died in
assets:precompile. The guard meant to stop a bad deploy stopped every deploy.

Moved into after_initialize rather than rewritten against ENV: a second copy of
the rule in environment-variable terms is a second thing to keep in step with
Deployment.self_serve_signup?, and it would drift the first time either changes.

Verified both ways against a production boot with the image build variables: it
boots clean where registration is closed, and refuses where it is open with no
Stripe key. A test pins the deferral so nobody moves it back.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* style(billing): drop the blank line left by removing the skip method

Rubocop caught it, mine did not run: I edited the file after the last full pass
and went straight to the next thing.

Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
artempartos pushed a commit that referenced this pull request Nov 30, 2026
DPA §7.3 points customers to /legal/subprocessors, and the URL answered
404. The page is a LegalDocument accepted by nobody, so it is listed on
/legal, versioned and digest-checked like the other texts, and asks no
one to accept anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
artempartos added a commit that referenced this pull request Nov 30, 2026
* feat(legal): publish the subprocessors page (#352)

DPA §7.3 points customers to /legal/subprocessors, and the URL answered
404. The page is a LegalDocument accepted by nobody, so it is listed on
/legal, versioned and digest-checked like the other texts, and asks no
one to accept anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* chore(legal): regenerate the route helpers for the subprocessors page

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Aixle Flow <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Artem Petrov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant