Repository navigation
fix(billing): bill a company once it stops being managed by Aixle - #456
Merged
Merged
Conversation
Unticking "Managed by Aixle" on an existing company left it `active` with no Stripe subscription: the Billing tab showed an Active subscription with an empty period and a Cancel that refused, and offered no way to add a card. Only admin create applied the billing terms. Leaving management now puts a company without a subscription on the allowance, or blocks it for `allowance` when the hours it ran while managed already used it up. A company that still has a subscription from before keeps paying through it. Unticking needs a worker limit, as creating a paying company does. The Billing tab offers Add a card instead of Cancel to an active company with no subscription. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
A company we carry is kept active, so the deleted webhook leaves only its end date behind. Unticking it read the stale subscription id as a live one and showed a cancellation in the past with a Keep subscription button Stripe refuses. It now goes back to blocked/canceled, where Add a card opens Checkout. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
artempartos
added a commit
that referenced
this pull request
Oct 30, 2026
Unticking Managed by Aixle counted the trial over everything the company ever ran (#456), so a company we had carried for months landed stopped the moment it was unticked. It now starts a fresh trial of the default length, or to the last day set in the same save. A live subscription still keeps billing it instead. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
artempartos
added a commit
that referenced
this pull request
Oct 30, 2026
…621) * feat(billing): make the hosted trial a number of days on one worker The trial was 100 worker-hours spent at whatever number of workers a workspace chose, so a big limit bought a trial of a few hours and nobody could say when it would end. A trialing company now runs one worker and cannot change that until it adds a card; the signup form no longer asks. The allowance is still counted in worker-hours from the usage ledger. One worker is offered around the clock, so an hour of the trial is an hour on the clock and the banner and Billing tab can speak in days and a last day. TRIAL_DAYS (30) replaces TRIAL_QUEUE_HOURS; each company keeps the length of the trial it started, and an operator moves a company's last day from its admin page. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * style(web): wrap the how-it-works call to action the way prettier wants Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]> * test(signup): expect the trial's one worker when the emailed link is opened Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]> * fix(billing): end every trial with its last day and keep workers fixed until a card A browser walkthrough found the rough edges of the first cut: - A default trial ran 720 hours from signup, so its "last day" was only the first hours of that day; it now ends with the last day's end, like a last day an operator sets, and day one is the signup day. - A company whose trial had ended could change its workers without a card. - The Workers card showed the stored limit's reservations under the trial's one worker, and the trial hint pushed the admin form sideways. - Dates read "29 нояб. 2026 г.." in a Russian browser and "November 01" in the admin; the Billing tab offered a card where there is nowhere to pay. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(billing): date the trial from the meter and lock project reservations too Counted from now, the last day ran ahead of the meter, which writes only closed hours and left out the hour a trial began in: a trial ending at 23:40 showed the next day as its last. What is left now runs on from the end of the last metered hour, the start hour counts, and days left is calendar days to the last one. A company whose ended subscription put it on a trial kept the subscription id and so could never have its last day moved; whether a subscription still bills is now read from the state. Projects can no longer reserve workers while the company's workers are fixed. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(billing): a trial after an ended subscription can still be moved Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]> * feat(billing): hold a trial to one worker for everyone, and let every writer pay Nobody chooses the number of workers before a card is added, the platform admin included: Company and SessionConcurrencyLimit refuse any number but one, and a company going onto a trial — or stopped at its end — drops to one. A company that needs more is one we carry. Unticking Managed by Aixle now says when it leaves the company stopped for a trial it already used up. The banner's Add a card and Pay invoice were an administrator's only, so a workspace whose admin was away stayed stopped. Every member who can make changes may now pay; the Billing tab and cancelling stay the admins', and Checkout brings anyone else back to the workspace. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(billing): give a company we stop carrying a fresh trial Unticking Managed by Aixle counted the trial over everything the company ever ran (#456), so a company we had carried for months landed stopped the moment it was unticked. It now starts a fresh trial of the default length, or to the last day set in the same save. A live subscription still keeps billing it instead. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(billing): put companies already on a trial onto one worker Companies that signed up before kept the number of workers they typed, which they would have been billed for the moment they paid; new signups get one. Where we host, every company on a trial or stopped at its end now has one, and chooses again once a card is added. The capacity log is written in the same statement: the meter reads a company's limit from it, so a limit changed without it would be billed at the old number once the company pays. Signed-off-by: Artem Petrov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: Artem Petrov <[email protected]> Co-authored-by: Claude Opus 5.5 <[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.
Fixes board task #168 (project 56): unticking Managed by Aixle in the admin left the company in a broken billing state.
Problem
Admin::CompaniesController#apply_billing_termssets a company's billing terms on create only. Unticking the box on an existing company never ran it, so the company stayedactivewith no Stripe subscription. On the Billing tab this showed:— – —),The meter also skipped the company, because it had no Stripe customer.
Change
When
managed_by_aixlegoes from true to false in saas,Companynow sets billing state in abefore_validation. It sits next tokeep_managed_company_running, so console changes are covered too.trialing: Billing tab shows free capacity + Add a cardblocked/allowance: Stopped + Add a cardactive, keeps paying through it (a scheduled cancellation stays scheduled)blocked/canceled: Add a card opens CheckoutThe allowance counts all recorded usage, including the hours run while managed. This was a product decision: nobody gets a second free allowance.
The Billing tab also gets a new
has_subscriptionflag. Anactivecompany without a subscription (for example,billing_stateset by hand in the admin) is now offered Add a card instead of Cancel subscription. Checkout confirms "Card added" only when a subscription exists.The ended case is needed because
keep_managed_company_runningholds a managed companyactive. Acustomer.subscription.deletedwebhook therefore leaves onlybilling_cancels_atbehind, and a past end date is how the ended subscription is recognized on untick.UNBOUNDED_PAYING_COMPANYmoved from the admin controller toCompany, since both now use it.Not in this PR
activeuntil someone acts: re-tick, save, untick, save in the admin, or a company admin adds a card from the Billing tab.Verification
billing_state=active, no subscription, no period, Cancel refused.billing_state=trialing, 100 h allowance shown, no Cancel.hasSubscription), and vitest for the page.changelog_test, rubocop, brakeman, tsc and eslint all pass. The full suite is left to CI.🤖 Generated with Claude Code