-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix Stripe webhook mode handling for live mode installations receiving test events #2999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a safeguard to the Stripe webhook route: after validating/wrapping the incoming event, if the app is running the live route but the Stripe event is in test mode, the route now logs and returns early (skipping event-type handling). Also removes an explicit error prop from a country combobox in a profile form. Changes
Sequence DiagramsequenceDiagram
participant Stripe
participant WebhookRoute as Webhook Route
participant Handler
Stripe->>WebhookRoute: POST webhook event
WebhookRoute->>WebhookRoute: Validate & wrap event
rect rgb(255, 245, 230)
Note over WebhookRoute: NEW: Pre-switch safeguard
WebhookRoute->>WebhookRoute: If route.mode == live && event.livemode == false\nlog warning + return 200 (skip processing)
end
alt not returned
WebhookRoute->>WebhookRoute: Switch on event.type
WebhookRoute->>Handler: Dispatch to handler
Handler->>WebhookRoute: Processing result
WebhookRoute->>Stripe: Respond 200 OK
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/app/(ee)/api/stripe/integration/webhook/route.ts (1)
70-76: Logic correctly addresses live mode installations receiving test events.The implementation properly handles the documented Stripe App behavior where live mode installations receive both live and test events. The placement after webhook validation and before event processing is correct.
Consider two enhancements for robustness:
- Add logging when mode is switched to aid debugging:
if (mode === "live" && !event.livemode) { + console.log(`[Stripe Webhook] Switching mode from live to test for event ${event.id}`); mode = "test"; }
- Verify whether other mode mismatches should be handled: Should test mode also check for
event.livemode === trueand switch to live? Similarly, should sandbox mode validate againstevent.livemode? If these scenarios are invalid or won't occur in practice, the current one-directional check is sufficient.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/stripe/integration/webhook/route.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
Summary by CodeRabbit