[PR #6915] [CLOSED] feat(stripe): add customerLookupFilter option for multi-app support #6964

Closed
opened 2026-03-13 13:19:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6915
Author: @aryasaatvik
Created: 12/20/2025
Status: Closed

Base: canaryHead: feat/customer-lookup-filter


📝 Commits (1)

  • 281f321 feat(stripe): add customerLookupFilter option for multi-app support

📊 Changes

5 files changed (+358 additions, -21 deletions)

View changed files

📝 packages/stripe/src/index.ts (+8 -6)
📝 packages/stripe/src/routes.ts (+37 -15)
📝 packages/stripe/src/stripe.test.ts (+236 -0)
📝 packages/stripe/src/types.ts (+33 -0)
📝 packages/stripe/src/utils.ts (+44 -0)

📄 Description

Summary

Adds a new customerLookupFilter option to the Stripe plugin that allows filtering existing customers by metadata when multiple apps share the same Stripe account.

This is useful when:

  • Multiple applications share the same Stripe account
  • Each app stamps customers with metadata (e.g., app_id)
  • You want to prevent cross-app customer conflicts

Changes

  • Add customerLookupFilter option to StripeOptions interface
  • Add shared findExistingStripeCustomer() utility function
  • Update signup hook to use shared utility
  • Update upgrade flow to use shared utility + add getCustomerCreateParams support for consistency
  • Add tests for filter scenarios

Usage Example

stripe({
  createCustomerOnSignUp: true,
  
  // Filter customers by app-specific metadata
  customerLookupFilter: async ({ customers, user }, ctx) => {
    return customers.find(c => c.metadata?.app_id === "my-app");
  },
  
  // Ensure new customers get the app_id metadata
  getCustomerCreateParams: async (user, ctx) => ({
    metadata: {
      app_id: "my-app",
    },
  }),
})

Test plan

  • Filter selects correct customer by metadata
  • Filter returns undefined → creates new customer
  • Backward compatible without filter (limit: 1, first match)
  • All existing tests pass (37/37)

Summary by cubic

Adds customerLookupFilter to the Stripe plugin to safely find app-specific customers when multiple apps share a Stripe account. Sign-up and upgrade flows now use a shared customer lookup and consistently apply metadata.

  • New Features

    • Stripe: Added customerLookupFilter to StripeOptions to select the correct customer (e.g., by metadata like app_id).
    • Introduced findExistingStripeCustomer and wired it into sign-up and upgrade paths.
    • Upgrade flow now respects getCustomerCreateParams for consistent customer metadata.
    • Added tests covering filter selection, undefined → create behavior, and backward compatibility.
  • Migration

    • For multi-app setups, set customerLookupFilter to pick the right customer and use getCustomerCreateParams to stamp app-specific metadata.
    • Single-app setups require no changes; default behavior remains first match.
    • Make your filter return undefined when no match exists to create a new customer.

Written for commit 281f32116d. Summary will update automatically on new commits.


🔄 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/6915 **Author:** [@aryasaatvik](https://github.com/aryasaatvik) **Created:** 12/20/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/customer-lookup-filter` --- ### 📝 Commits (1) - [`281f321`](https://github.com/better-auth/better-auth/commit/281f32116d236682dfab4adfb1e4541ba53a7962) feat(stripe): add customerLookupFilter option for multi-app support ### 📊 Changes **5 files changed** (+358 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/index.ts` (+8 -6) 📝 `packages/stripe/src/routes.ts` (+37 -15) 📝 `packages/stripe/src/stripe.test.ts` (+236 -0) 📝 `packages/stripe/src/types.ts` (+33 -0) 📝 `packages/stripe/src/utils.ts` (+44 -0) </details> ### 📄 Description ## Summary Adds a new `customerLookupFilter` option to the Stripe plugin that allows filtering existing customers by metadata when multiple apps share the same Stripe account. This is useful when: - Multiple applications share the same Stripe account - Each app stamps customers with metadata (e.g., `app_id`) - You want to prevent cross-app customer conflicts ## Changes - Add `customerLookupFilter` option to `StripeOptions` interface - Add shared `findExistingStripeCustomer()` utility function - Update signup hook to use shared utility - Update upgrade flow to use shared utility + add `getCustomerCreateParams` support for consistency - Add tests for filter scenarios ## Usage Example ```typescript stripe({ createCustomerOnSignUp: true, // Filter customers by app-specific metadata customerLookupFilter: async ({ customers, user }, ctx) => { return customers.find(c => c.metadata?.app_id === "my-app"); }, // Ensure new customers get the app_id metadata getCustomerCreateParams: async (user, ctx) => ({ metadata: { app_id: "my-app", }, }), }) ``` ## Test plan - [x] Filter selects correct customer by metadata - [x] Filter returns undefined → creates new customer - [x] Backward compatible without filter (limit: 1, first match) - [x] All existing tests pass (37/37) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds customerLookupFilter to the Stripe plugin to safely find app-specific customers when multiple apps share a Stripe account. Sign-up and upgrade flows now use a shared customer lookup and consistently apply metadata. - **New Features** - Stripe: Added customerLookupFilter to StripeOptions to select the correct customer (e.g., by metadata like app_id). - Introduced findExistingStripeCustomer and wired it into sign-up and upgrade paths. - Upgrade flow now respects getCustomerCreateParams for consistent customer metadata. - Added tests covering filter selection, undefined → create behavior, and backward compatibility. - **Migration** - For multi-app setups, set customerLookupFilter to pick the right customer and use getCustomerCreateParams to stamp app-specific metadata. - Single-app setups require no changes; default behavior remains first match. - Make your filter return undefined when no match exists to create a new customer. <sup>Written for commit 281f32116d236682dfab4adfb1e4541ba53a7962. Summary will update automatically on new commits.</sup> <!-- 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-03-13 13:19:19 -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#6964