Fix checkout.session.completed webhook#3885
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughWebhook onboarding and email flow moved to use Stripe subscription.status; program creation and saved-domain claiming logic updated accordingly. Domain-claim utility parameter types narrowed to Pick<Project,...>. ChangesSubscription-Status Domain Claiming
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts (1)
219-241:⚠️ Potential issue | 🟠 MajorConfirm: saved domains remain unclaimed when trial subscriptions complete checkout.
The concern is valid. When a trial subscription completes checkout,
subscription.statusis"trialing"(not"active"), so the saved domain claiming at line 220 won't execute. Thecustomer-subscription-updatedwebhook fires later when the trial converts to active status, but it doesn't claim saved domains. Add domain claiming logic tocustomer-subscription-updatedwhensubscription.statustransitions to"active", or remove thesubscription.status === "active"gate to allow trials.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/app/`(ee)/api/stripe/webhook/checkout-session-completed.ts around lines 219 - 241, The saved-domain claim is gated by subscription.status === "active" in the checkout-session-completed flow so trialing subscriptions never trigger claimDotLinkDomain; update the customer-subscription-updated webhook handler to perform the same domain-claiming logic when a subscription transitions to "active" (i.e., detect previous status vs current status or check current === "active" if previous was "trialing"), reusing the same redis key `onboarding-domain:${workspaceId}` and calling claimDotLinkDomain({ domain, userId, workspace }) with identical error handling; alternatively, if you prefer claiming at checkout, remove the strict subscription.status === "active" guard (or allow "trialing") in the checkout-session-completed block so trials also trigger the claim.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/app/`(ee)/api/stripe/webhook/checkout-session-completed.ts:
- Around line 148-167: The code sends the 14-day trial email whenever
programOnboarding is missing, which incorrectly mails paying customers; update
the guard around sendBatchEmail so it only fires when the Stripe
checkout/subscription actually includes an active trial. Concretely, before
calling sendBatchEmail/TrialStartedEmail, check the Stripe session/subscription
trial fields (e.g., subscription.trial_end exists and is a future timestamp or
the checkout session indicates a trial) and only send when that condition is
true; keep the existing programOnboarding check
(updatedWorkspace.store?.["programOnboarding"]) and use symbols sendBatchEmail,
TrialStartedEmail, updatedWorkspace, and plan.name to locate and modify the
logic.
---
Outside diff comments:
In `@apps/web/app/`(ee)/api/stripe/webhook/checkout-session-completed.ts:
- Around line 219-241: The saved-domain claim is gated by subscription.status
=== "active" in the checkout-session-completed flow so trialing subscriptions
never trigger claimDotLinkDomain; update the customer-subscription-updated
webhook handler to perform the same domain-claiming logic when a subscription
transitions to "active" (i.e., detect previous status vs current status or check
current === "active" if previous was "trialing"), reusing the same redis key
`onboarding-domain:${workspaceId}` and calling claimDotLinkDomain({ domain,
userId, workspace }) with identical error handling; alternatively, if you prefer
claiming at checkout, remove the strict subscription.status === "active" guard
(or allow "trialing") in the checkout-session-completed block so trials also
trigger the claim.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e74e05de-7c97-4f5b-b463-4905ec0e0f0c
📒 Files selected for processing (2)
apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.tsapps/web/lib/api/domains/claim-dot-link-domain.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts (1)
219-241:⚠️ Potential issue | 🔴 CriticalSaved domains for trial signups will never be claimed.
The
subscription.status === "active"guard at line 220 causescheckout.session.completedto skip the domain claim for trial subscriptions. When the trial later converts to active, thecustomer.subscription.updatedwebhook does not read theonboarding-domain:${workspaceId}cache key or callclaimDotLinkDomain. As a result, saved domains from trial signups are permanently abandoned and never registered.Add domain claiming logic to
customer.subscription.updatedto handle trial-to-active conversions, or remove thesubscription.status === "active"guard so all successful checkouts attempt to claim the domain regardless of subscription status.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/app/`(ee)/api/stripe/webhook/checkout-session-completed.ts around lines 219 - 241, The current checkout.session.completed handler only calls claimDotLinkDomain when subscription.status === "active", so trial checkouts never register saved domains; either remove that status guard in the checkout.session.completed flow (so the async block that reads redis.get(`onboarding-domain:${workspaceId}`) and calls claimDotLinkDomain({ domain, userId, workspace }) runs for all successful checkouts) or also add equivalent logic to the customer.subscription.updated webhook to detect transitions from trial (or non-active) to active and perform the same redis lookup and claimDotLinkDomain call (use the same onboarding-domain:${workspaceId} key and error handling). Ensure you reference and reuse the existing claimDotLinkDomain invocation/params and workspaceId lookup so saved domains are claimed when the subscription becomes active.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/web/app/`(ee)/api/stripe/webhook/checkout-session-completed.ts:
- Around line 219-241: The current checkout.session.completed handler only calls
claimDotLinkDomain when subscription.status === "active", so trial checkouts
never register saved domains; either remove that status guard in the
checkout.session.completed flow (so the async block that reads
redis.get(`onboarding-domain:${workspaceId}`) and calls claimDotLinkDomain({
domain, userId, workspace }) runs for all successful checkouts) or also add
equivalent logic to the customer.subscription.updated webhook to detect
transitions from trial (or non-active) to active and perform the same redis
lookup and claimDotLinkDomain call (use the same
onboarding-domain:${workspaceId} key and error handling). Ensure you reference
and reuse the existing claimDotLinkDomain invocation/params and workspaceId
lookup so saved domains are claimed when the subscription becomes active.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 09601f5e-6832-41d7-b274-389a200c2001
📒 Files selected for processing (2)
apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.tsapps/web/lib/api/domains/claim-dot-link-domain.ts
Summary by CodeRabbit