Repository navigation
feat(billing): take payment through Stripe - #352
Merged
artempartos merged 5 commits intoSep 29, 2026
Merged
Conversation
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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::StripeClientBilling::Meter::StripeWeb::Company::BillingCheckoutsControllerWebhooks::StripeControllerTrialBannerReplays 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 hourlooks 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_duekeeps a customer running on purpose: a failed payment starts adunning 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 totrialing— the free allowance was spent once andcancelling 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:mtr_test_…AXI—queue_minutes, sum, customer bystripe_customer_idprod_VLYLkzDfhdW0A4price_1UKrEiRfWGHL113SKW7Snqaa— $0.08333333/queue-minute = $5/queue-hour, monthly meteredThe 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.6in the first draft, a version that does notexist; it is
~> 19.6, the current stable.Checks
rubocop(1758 files),brakeman(0 warnings),tsc,eslint,steigerclean. Frontend 1701/1701. Backend: the touched suites 706/706, run with
DEPLOYMENT_MODE=self_hostedto match CI. The full suite is left to CI, since aworktree run shares a Postgres with the main checkout.
🤖 Generated with Claude Code