fix(stripe): accept snake_case dub_customer_id as fallback
This PR adds support for using dub_customer_id as a fallback when processing events from the Stripe webhook integration.
This is useful for libraries that normalize checkoutSessionParams to follow Stripe’s snake_case convention.
Summary by CodeRabbit
-
New Features
- None
-
Bug Fixes
- Improved Stripe integration compatibility by recognizing both dubCustomerId and dub_customer_id in metadata.
- Ensures reliable customer identification during checkout completion, customer creation, and customer updates.
- Reduces missed customer associations and improves sync accuracy across connected projects.
-
Chores
- No user-facing changes beyond reliability improvements.
Walkthrough
Adds a fallback to read Stripe metadata key dub_customer_id wherever dubCustomerId was previously used for identifying the external/dub customer ID across checkout session completed, customer created/updated webhooks, and shared utils. No exported signatures changed; primary flows otherwise unchanged.
Changes
| Cohort / File(s) | Summary |
|---|---|
Stripe webhook metadata fallbackapps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts, apps/web/app/(ee)/api/stripe/integration/webhook/customer-created.ts, apps/web/app/(ee)/api/stripe/integration/webhook/customer-updated.ts, apps/web/app/(ee)/api/stripe/integration/webhook/utils.ts |
Add fallback to metadata.dub_customer_id when metadata.dubCustomerId is absent for external/dub customer ID extraction; no other logic or signatures changed. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Stripe as Stripe
participant Webhook as Webhook Endpoint
participant Handler as Handler (checkout/customer/*)
participant Utils as Utils.createNewCustomer
participant DB as Database
Stripe->>Webhook: Event (checkout.completed / customer.created / customer.updated)
Webhook->>Handler: Parse event
alt Extract external/dub customer ID
Handler->>Handler: Read metadata.dubCustomerId
opt Fallback
Handler->>Handler: If missing, read metadata.dub_customer_id
end
end
alt Customer exists
Handler->>DB: Lookup/update by projectConnectId / stripeCustomerId
DB-->>Handler: Match found / updated
else Not found
Handler->>Utils: createNewCustomer(event, extracted externalId)
Utils->>DB: Insert customer and related records
DB-->>Utils: Created
Utils-->>Handler: Result
end
Handler-->>Stripe: 200 OK
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
- steven-tey
- devkiran
Poem
A twitch of whiskers, swift and spry,
I nosed two keys where one ran dry—
dubCustomerId? If not, I try
dub_customer_id (oh my!).
With metadata tidied, I hop with glee,
Webhooks aligned—carrots for me! 🥕🐇
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
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.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreor@coderabbit ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@Velka-DEV is attempting to deploy a commit to the Dub Team on Vercel.
A member of the Team first needs to authorize it.