[PR #6916] feat(stripe): add customerLookupFilter option for multi-app support #6965

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

📋 Pull Request Information

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

Base: canaryHead: feat/stripe-customer-lookup-filter


📝 Commits (3)

  • 281f321 feat(stripe): add customerLookupFilter option for multi-app support
  • 48bda2c Merge branch 'canary' into feat/stripe-customer-lookup-filter
  • 1237701 Merge branch 'canary' into feat/stripe-customer-lookup-filter

📊 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 a customerLookupFilter option to the Stripe plugin to select the right customer when multiple apps share a Stripe account. Also unifies customer lookup with a shared utility and adds support for custom customer create params in upgrade.

  • New Features
    • customerLookupFilter in StripeOptions to filter existing customers (e.g., by metadata) for multi-app setups; defaults to first match when not provided.
    • Shared findExistingStripeCustomer utility used in signup and upgrade; fetches more customers when a filter is present.
    • Upgrade flow supports getCustomerCreateParams for consistent customer metadata.
    • Tests added for filter selection, creation fallback, and backward compatibility.

Written for commit 1237701e9f. 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/6916 **Author:** [@aryasaatvik](https://github.com/aryasaatvik) **Created:** 12/20/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/stripe-customer-lookup-filter` --- ### 📝 Commits (3) - [`281f321`](https://github.com/better-auth/better-auth/commit/281f32116d236682dfab4adfb1e4541ba53a7962) feat(stripe): add customerLookupFilter option for multi-app support - [`48bda2c`](https://github.com/better-auth/better-auth/commit/48bda2cf7860a69ec2fb33d6c82d463509dc78a6) Merge branch 'canary' into feat/stripe-customer-lookup-filter - [`1237701`](https://github.com/better-auth/better-auth/commit/1237701e9fdaf1e454dc9e3035f2489dee39d5d0) Merge branch 'canary' into feat/stripe-customer-lookup-filter ### 📊 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 a customerLookupFilter option to the Stripe plugin to select the right customer when multiple apps share a Stripe account. Also unifies customer lookup with a shared utility and adds support for custom customer create params in upgrade. - **New Features** - customerLookupFilter in StripeOptions to filter existing customers (e.g., by metadata) for multi-app setups; defaults to first match when not provided. - Shared findExistingStripeCustomer utility used in signup and upgrade; fetches more customers when a filter is present. - Upgrade flow supports getCustomerCreateParams for consistent customer metadata. - Tests added for filter selection, creation fallback, and backward compatibility. <sup>Written for commit 1237701e9fdaf1e454dc9e3035f2489dee39d5d0. 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:22 -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#6965