Skip to content

Include partner info in "New customer" lead webhook#3875

Open
pepeladeira wants to merge 3 commits into
mainfrom
stripe-webhook-new-customer-partner-slack
Open

Include partner info in "New customer" lead webhook#3875
pepeladeira wants to merge 3 commits into
mainfrom
stripe-webhook-new-customer-partner-slack

Conversation

@pepeladeira
Copy link
Copy Markdown
Collaborator

@pepeladeira pepeladeira commented May 8, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved customer name resolution by implementing fallback logic for incomplete Stripe data.
    • Enhanced lead event webhooks to include additional partner information when applicable.

Review Change Stack

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview May 19, 2026 9:52pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3cddd70f-ce70-49c1-86c3-6cefe9ffb9fc

📥 Commits

Reviewing files that changed from the base of the PR and between 56b02ee and e5b3e2f.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts

📝 Walkthrough

Walkthrough

The Stripe webhook handler enriches customer creation with improved naming and enhances lead.created webhook dispatch by attaching partner context from program enrollments, enabling richer event payloads for postback delivery.

Changes

Webhook Handler and Customer Creation Enhancement

Layer / File(s) Summary
Customer Name Fallback Enhancement
apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
Customer creation derives name from stripeCustomer.name, then stripeCustomer.email, before falling back to generateRandomName().
Lead Webhook Partner Context
apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
Imports constructWebhookPartner and refactors lead.created dispatch to conditionally fetch program enrollment, build partner context, and pass it into event transformation within an async IIFE delivered via waitUntil.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A partner now joins the webhook's keen sight,
With names from emails and merchants made bright,
Lead events enriched with enrollment's sweet grace—
The dispatch now carries each program's true place!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: including partner information in the webhook that fires when a new customer is created via Stripe.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stripe-webhook-new-customer-partner-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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/lib/partners/create-partner-commission.ts (1)

48-62: ⚡ Quick win

Extract constructWebhookPartner into a standalone helper.

Making this mapper public from create-partner-commission.ts means 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

📥 Commits

Reviewing files that changed from the base of the PR and between a5fa025 and 56b02ee.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
  • apps/web/lib/partners/create-partner-commission.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant