[PR #3459] [MERGED] Prevent Duplicate Customers #30436

Closed
opened 2026-04-17 21:31:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3459
Author: @dagmawibabi
Created: 7/19/2025
Status: Merged
Merged: 7/19/2025
Merged by: @Bekacru

Base: mainHead: preventDuplicateCustomer


📝 Commits (2)

  • 58c0584 prevent duplicate stripe customer
  • 76301cb prevent duplicate stripe customer

📊 Changes

2 files changed (+38 additions, -7 deletions)

View changed files

📝 packages/stripe/src/index.ts (+15 -7)
📝 packages/stripe/src/stripe.test.ts (+23 -0)

📄 Description

Closes https://github.com/better-auth/better-auth/issues/2495


This pull request improves the Stripe integration by enhancing customer creation logic and adding a new test case to ensure correct behavior. The changes focus on optimizing how Stripe customers are handled and verifying the functionality through testing.

Stripe customer creation improvements:

  • packages/stripe/src/index.ts: Updated the customer creation logic to first check for existing customers by email before creating a new Stripe customer. This prevents duplicate customer records and ensures efficient handling of customer data.

  • packages/stripe/src/index.ts: Ensured the customerId is properly updated with the Stripe customer ID after creation or lookup.

Testing enhancements:

  • packages/stripe/src/stripe.test.ts: Added a new test case to verify that Stripe.customers.create is only called once during signup and upgrade processes, ensuring the logic avoids redundant customer creation.

Summary by cubic

Improved Stripe integration to prevent duplicate customer records by checking for existing customers before creating new ones.

  • Bug Fixes
    • Updated customer creation logic to look up customers by email first.
    • Added a test to ensure Stripe only creates a customer once during signup and upgrade.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3459 **Author:** [@dagmawibabi](https://github.com/dagmawibabi) **Created:** 7/19/2025 **Status:** ✅ Merged **Merged:** 7/19/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `preventDuplicateCustomer` --- ### 📝 Commits (2) - [`58c0584`](https://github.com/better-auth/better-auth/commit/58c05849b300b9648e7008a53e9909fefbd10d13) prevent duplicate stripe customer - [`76301cb`](https://github.com/better-auth/better-auth/commit/76301cbb5e91f7aa403f80b988d6464d87fed9cf) prevent duplicate stripe customer ### 📊 Changes **2 files changed** (+38 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/index.ts` (+15 -7) 📝 `packages/stripe/src/stripe.test.ts` (+23 -0) </details> ### 📄 Description Closes https://github.com/better-auth/better-auth/issues/2495 --- This pull request improves the Stripe integration by enhancing customer creation logic and adding a new test case to ensure correct behavior. The changes focus on optimizing how Stripe customers are handled and verifying the functionality through testing. ### Stripe customer creation improvements: * [`packages/stripe/src/index.ts`](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08L242-R261): Updated the customer creation logic to first check for existing customers by email before creating a new Stripe customer. This prevents duplicate customer records and ensures efficient handling of customer data. * [`packages/stripe/src/index.ts`](diffhunk://#diff-ccb5282d4490ceec8e8c99f978be2383dd1915db21316f3baba6066420070b08R274): Ensured the `customerId` is properly updated with the Stripe customer ID after creation or lookup. ### Testing enhancements: * [`packages/stripe/src/stripe.test.ts`](diffhunk://#diff-0719c098a988c165e85048b409548dcfabd9e0ab39916077a54889f860cb9769R820-R842): Added a new test case to verify that `Stripe.customers.create` is only called once during signup and upgrade processes, ensuring the logic avoids redundant customer creation. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Improved Stripe integration to prevent duplicate customer records by checking for existing customers before creating new ones. - **Bug Fixes** - Updated customer creation logic to look up customers by email first. - Added a test to ensure Stripe only creates a customer once during signup and upgrade. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:31:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#30436