feat(admin): allow removing an admin-granted subscription#1723
Open
giladresisi wants to merge 2 commits into
Open
feat(admin): allow removing an admin-granted subscription#1723giladresisi wants to merge 2 commits into
giladresisi wants to merge 2 commits into
Conversation
The impersonation bar could grant a free/admin subscription but not undo it.
Adds a super-admin "Remove Subscription" action next to the grant selector.
- New POST /billing/remove-subscription (super-admin) →
removeAdminGrantedSubscription: downgrades the org to FREE, drops the local
subscription row via the existing deleteSubscription path, and clears the
org's fake paymentId — all with NO Stripe calls. Clearing paymentId is
required: admin grants store the user id in paymentId, and leaving it would
make later Stripe flows (checkout, discount checks) call Stripe with a
non-existent customer and error ("No such customer").
- Guarded to admin-granted subscriptions only: those store the user id in
Organization.paymentId, so any paymentId starting with `cus_` is a real
Stripe customer and is rejected (use cancel-subscription instead) — a real
paid subscription can never be removed here.
- /self now returns `adminGrantedSubscription`, and the impersonation bar shows
the remove control only when it is true, so a genuine Stripe subscription is
never accidentally removed.
- Since an admin-granted subscription has no Stripe subscription to cancel, the
now-redundant Cancel controls are hidden when `adminGrantedSubscription` is
true: the impersonation bar's "Cancel Subscription" (Remove is used instead)
and the billing page's self-service "Cancel subscription" button. Their
backend endpoints (in the previous commit) already reject non-`cus_` orgs
with a clean 400 as defense-in-depth.
Validated by impersonating an admin-granted account: the Remove control shows
while both Cancel controls (impersonation bar and billing page) are hidden;
impersonating a real `cus_` subscriber hides Remove and still shows the Cancel
controls, which continue to work.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Contribution-checker quality warning Heuristics that flagged:
If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Comment on lines
+128
to
+131
| adminGrantedSubscription: | ||
| // @ts-ignore | ||
| !!organization?.subscription && | ||
| !organization?.paymentId?.startsWith('cus_'), |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment.
Fixed by followup commit
Lifetime-deal orgs have a subscription row but a null paymentId, so
!paymentId?.startsWith('cus_') was true for them and the impersonation
bar showed a Remove Subscription button that always fails server-side.
Require a non-null paymentId, which only the admin-grant path sets.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
The impersonation bar could grant a free/admin subscription but not undo it. Adds a super-admin Remove Subscription action next to the grant selector.
POST /billing/remove-subscription(super-admin): downgrades the org to FREE, drops the local subscription row via the existingdeleteSubscriptionpath, and clears the org's fakepaymentId— all with no Stripe calls. ClearingpaymentIdmatters: admin grants store the user id there, and leaving it makes later Stripe flows error with "No such customer".cus_...paymentId is a real Stripe customer and is rejected (use cancel-subscription instead), so a real paid subscription can never be removed here./selfreturnsadminGrantedSubscription; the impersonation bar shows the Remove control only for admin grants, and the billing page hides the Cancel button for them.Validated by impersonation both ways: an admin-granted account shows Remove and hides the Cancel controls; a real
cus_subscriber shows Cancel (working) and hides Remove.Split from #1668. Independent of #1721, though they touch adjacent code — either merge order resolves automatically.
🤖 Generated with Claude Code