Guard late invoice payments for ended subscriptions#956
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe invoice-paid webhook now recognizes canceled and incomplete-expired subscriptions, logs a reconciliation warning, and skips restoration and billing side effects. Parameterized tests verify the response, skipped operations, warning event, and idempotency checks. ChangesTerminal invoice handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Stripe
participant WebhookHandler
participant PostHog
Stripe->>WebhookHandler: invoice.paid with terminal subscription
WebhookHandler->>PostHog: emit terminal subscription skip warning
WebhookHandler-->>Stripe: return success without restoration side effects
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
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
invoice.paidentitlement side effects when Stripe reports a terminalcanceledorincomplete_expiredsubscriptionWhy
Stripe can leave a renewal invoice collectible after its subscription has been canceled. Paying that invoice later succeeds financially but does not reactivate the subscription. The existing webhook treated the late payment like an active renewal, which could create split state between Stripe/WorkOS entitlements and HackerAI billing side effects.
Validation
corepack pnpm test --runInBand— 296 suites, 2,922 tests passedcorepack pnpm typecheckcorepack pnpm lint— passes with 5 existing unrelated warningscorepack pnpm exec eslint app/api/subscription/webhook/route.ts app/api/subscription/webhook/__tests__/route.test.tscorepack pnpm exec prettier --check app/api/subscription/webhook/route.ts app/api/subscription/webhook/__tests__/route.test.tsgit diff --checkManual verification
invoice.paidevent whose referenced subscription iscanceledorincomplete_expired. Confirm the webhook returns 200, emitsbilling_invoice_paid_terminal_subscription_skipped, and does not restore paid entitlements or usage credits.Summary by CodeRabbit