fix: preserve active Pro entitlement on stale Stripe webhooks - #2336
Open
richiemcilroy wants to merge 2 commits into
Open
richiemcilroy wants to merge 2 commits into
richiemcilroy wants to merge 2 commits into
Conversation
Comment on lines
+778
to
+782
| const currentSubscription = effectiveProSubscription( | ||
| subscription, | ||
| subscriptions.data, | ||
| ); | ||
| const inviteQuota = proInviteQuota(subscriptions.data); |
Contributor
There was a problem hiding this comment.
Pagination can revoke entitlement
If a customer has more than 100 subscription attempts, their entitled Pro subscription can be on a later Stripe page. This code only selects from the first 100 records, so a stale canceled or expired webhook can fall back to its own subscription and overwrite the user's active entitlement. Fetch all subscription pages before choosing the effective subscription and calculating the combined quota. The deleted-event path at lines 911–926 has the same problem.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/app/api/webhooks/stripe/route.ts
Line: 778-782
Comment:
**Pagination can revoke entitlement**
If a customer has more than 100 subscription attempts, their entitled Pro subscription can be on a later Stripe page. This code only selects from the first 100 records, so a stale canceled or expired webhook can fall back to its own subscription and overwrite the user's active entitlement. Fetch all subscription pages before choosing the effective subscription and calculating the combined quota. The deleted-event path at lines 911–926 has the same problem.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.This branch was successfully deployed
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
Incident
An abandoned checkout's
customer.subscription.updatedevent arrived after a paid checkout and overwrote the user's active Pro status withincomplete_expired. Two affected production accounts have been reconciled separately.Verification
bun run test __tests__/unit/signed-baa-webhook.test.ts --silent --reporter=dot(36 passed)