fix(billing): plan should be detected from stripe subscription object#3090
Merged
icecrasher321 merged 2 commits intostagingfrom Jan 31, 2026
Merged
fix(billing): plan should be detected from stripe subscription object#3090icecrasher321 merged 2 commits intostagingfrom
icecrasher321 merged 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Collaborator
Author
|
@cursor review |
Contributor
Greptile OverviewGreptile SummaryFixed critical bug where Pro-to-Team subscription upgrades were not properly detected because they trigger Stripe Key Changes:
Impact:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Stripe
participant Webhook as Webhook Handler
participant DB as Database
participant Resolver as resolvePlanFromStripeSubscription
participant OrgEnsure as ensureOrganizationForTeamSubscription
Note over User,Stripe: User upgrades from Pro to Team
User->>Stripe: Upgrade subscription
Stripe->>Webhook: subscription.updated event
Note over Webhook: Event contains updated Stripe subscription
Note over DB: DB subscription.plan still shows 'pro' (stale)
Webhook->>Resolver: resolvePlanFromStripeSubscription(stripeSubscription)
Resolver->>Resolver: Extract priceId from subscription.items[0].price.id
Resolver->>Resolver: getPlanByPriceId(priceId)
Resolver-->>Webhook: {planFromStripe: 'team', isTeamPlan: true}
Webhook->>Webhook: Detect upgrade: isTeamPlan && db.plan !== 'team'
Note over Webhook: isUpgradeToTeam = true
Webhook->>Webhook: Create subscriptionForOrgCreation<br/>with plan: 'team'
Webhook->>OrgEnsure: ensureOrganizationForTeamSubscription(subscriptionForOrgCreation)
OrgEnsure->>OrgEnsure: Check if subscription.plan === 'team'
Note over OrgEnsure: Now sees 'team' instead of stale 'pro'
OrgEnsure->>DB: Create organization for user
OrgEnsure->>DB: Update subscription.referenceId to org_xxx
OrgEnsure-->>Webhook: resolvedSubscription (with org referenceId)
Webhook->>Webhook: Use effectivePlanForTeamFeatures = 'team'
Webhook->>DB: syncSeatsFromStripeQuantity()
Note over Webhook: Team features now active
|
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.
Summary
Pro to Team triggers sub update not create. Need to pick out plan from event object instead of stale db entry.
Type of Change
Testing
Tested using Stripe CLI
Checklist