Include partner info in "New customer" lead webhook#3875
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR enhances Stripe webhook handling to include partner context in lead events. A utility function for constructing partner objects is exported, imported into the webhook handler, and integrated into the "lead.created" event dispatch flow. Customer naming fallback logic is also refined to prefer email before random name generation. ChangesLead Webhook Partner Context Enhancement
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 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)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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
🧹 Nitpick comments (1)
apps/web/lib/partners/create-partner-commission.ts (1)
48-62: ⚡ Quick winExtract
constructWebhookPartnerinto a standalone helper.Making this mapper public from
create-partner-commission.tsmeans the Stripe webhook path now depends on the entire commission-creation module. A small shared helper file would avoid pulling audit/workflow/commission-only imports into that path and keep the boundary cleaner.🤖 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/lib/partners/create-partner-commission.ts` around lines 48 - 62, The constructWebhookPartner mapper is currently exported from create-partner-commission.ts which pulls heavy commission/audit/workflow imports into the Stripe webhook path; extract constructWebhookPartner into a small standalone helper module (e.g., a new file exporting a named function constructWebhookPartner) that only depends on ProgramEnrollment, Partner, Link, aggregatePartnerLinksStats and toCentsNumber types/utilities, move the implementation there, export it, then update all callers (including the Stripe webhook handler) to import constructWebhookPartner from the new helper instead of create-partner-commission; preserve the exact function signature and behavior (including totalCommissionsParam handling) and ensure the helper has no commission/audit/workflow imports so the webhook path no longer pulls those modules.
🤖 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/integration/webhook/utils/create-new-customer.ts:
- Around line 149-168: The prisma.programEnrollment.findUnique lookup used to
build webhookPartner can reject and block the Promise.allSettled that runs
sendWorkspaceWebhook and sendPartnerPostback; change the programEnrollment fetch
(the call to prisma.programEnrollment.findUnique) to handle errors (e.g., append
.catch(() => null) or try/catch) so it returns null on failure, then pass the
possibly-null result into constructWebhookPartner as before; this ensures
webhookPartner resolution won't throw and allows Promise.allSettled (which calls
sendWorkspaceWebhook and sendPartnerPostback) to run regardless of enrichment
failures.
---
Nitpick comments:
In `@apps/web/lib/partners/create-partner-commission.ts`:
- Around line 48-62: The constructWebhookPartner mapper is currently exported
from create-partner-commission.ts which pulls heavy commission/audit/workflow
imports into the Stripe webhook path; extract constructWebhookPartner into a
small standalone helper module (e.g., a new file exporting a named function
constructWebhookPartner) that only depends on ProgramEnrollment, Partner, Link,
aggregatePartnerLinksStats and toCentsNumber types/utilities, move the
implementation there, export it, then update all callers (including the Stripe
webhook handler) to import constructWebhookPartner from the new helper instead
of create-partner-commission; preserve the exact function signature and behavior
(including totalCommissionsParam handling) and ensure the helper has no
commission/audit/workflow imports so the webhook path no longer pulls those
modules.
🪄 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: 025e982c-ccd2-4c9f-b2f7-60a2e989ecc3
📒 Files selected for processing (2)
apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.tsapps/web/lib/partners/create-partner-commission.ts
| (async () => { | ||
| const programEnrollment = | ||
| link.programId && link.partnerId | ||
| ? await prisma.programEnrollment.findUnique({ | ||
| where: { | ||
| partnerId_programId: { | ||
| partnerId: link.partnerId, | ||
| programId: link.programId, | ||
| }, | ||
| }, | ||
| include: { | ||
| partner: true, | ||
| links: true, | ||
| }, | ||
| }), | ||
| ] | ||
| : []), | ||
| ]), | ||
| }) | ||
| : null; | ||
|
|
||
| const webhookPartner = programEnrollment | ||
| ? constructWebhookPartner(programEnrollment) | ||
| : undefined; |
There was a problem hiding this comment.
Don't let partner enrichment block lead webhooks.
The await prisma.programEnrollment.findUnique(...) call at lines 150–167 lacks error handling and blocks the Promise.allSettled(...) block containing both sendWorkspaceWebhook() and sendPartnerPostback(). If the lookup rejects, neither webhook runs, turning optional partner enrichment into a hard dependency for all lead notifications on partner links.
Wrap the lookup in .catch() to return null on failure and let the webhooks proceed:
Suggested fix
const programEnrollment =
link.programId && link.partnerId
? await prisma.programEnrollment
+ .findUnique(...)
+ .catch((error) => {
+ console.error(
+ "Failed to load program enrollment for lead webhook partner context",
+ error,
+ );
+ return null;
+ })
- .findUnique(...)
: null;🤖 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/integration/webhook/utils/create-new-customer.ts
around lines 149 - 168, The prisma.programEnrollment.findUnique lookup used to
build webhookPartner can reject and block the Promise.allSettled that runs
sendWorkspaceWebhook and sendPartnerPostback; change the programEnrollment fetch
(the call to prisma.programEnrollment.findUnique) to handle errors (e.g., append
.catch(() => null) or try/catch) so it returns null on failure, then pass the
possibly-null result into constructWebhookPartner as before; this ensures
webhookPartner resolution won't throw and allows Promise.allSettled (which calls
sendWorkspaceWebhook and sendPartnerPostback) to run regardless of enrichment
failures.
Summary by CodeRabbit
Bug Fixes
Chores