Skip to content

fix(api): avoid duplicate customer creation on lookup errors#29769

Open
Adarsh9977 wants to merge 2 commits into
calcom:mainfrom
Adarsh9977:stripe-duplicate
Open

fix(api): avoid duplicate customer creation on lookup errors#29769
Adarsh9977 wants to merge 2 commits into
calcom:mainfrom
Adarsh9977:stripe-duplicate

Conversation

@Adarsh9977

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Fix createStripeCustomerId in API v2 so Stripe customer lookup failures no longer silently create duplicate customers.
  • Only create a new Stripe customer when the email lookup succeeds and returns an empty list.
  • Surface Stripe lookup/create failures as InternalServerErrorException instead of masking them with a fallback create.

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended for both the original and new change (video/image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • [N/A] I have updated the developer docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @Adarsh9977! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7f72191-7396-47ad-9145-970a394d3989

📥 Commits

Reviewing files that changed from the base of the PR and between 92ad7f5 and fb30c52.

📒 Files selected for processing (1)
  • apps/api/v2/src/modules/stripe/stripe.service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/v2/src/modules/stripe/stripe.service.ts

📝 Walkthrough

Walkthrough

createStripeCustomerId now validates that the first Stripe customer exists and has an identifier before reusing it. Otherwise, it creates a customer with an idempotency key based on the lowercased email. The error handler still throws InternalServerErrorException without binding an unused error variable.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preventing duplicate Stripe customer creation on lookup errors.
Description check ✅ Passed The description is directly related to the Stripe customer lookup and fallback behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/api/v2/src/modules/stripe/stripe.service.ts`:
- Around line 245-250: Serialize the customers.list and stripe.customers.create
flow in the surrounding customer lookup method per user, or supply a stable
per-user idempotency key to creation, so concurrent requests cannot create
duplicate Stripe customers before stripeCustomerId is persisted. Preserve the
existing reuse of customersResponse.data[0].id and assignment of customerId for
both existing and newly created customers.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a08def53-c924-465a-8321-c0dd70d21cfb

📥 Commits

Reviewing files that changed from the base of the PR and between f004349 and 92ad7f5.

📒 Files selected for processing (1)
  • apps/api/v2/src/modules/stripe/stripe.service.ts

Comment thread apps/api/v2/src/modules/stripe/stripe.service.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant