Reference Id sometimes ignored for Stripe #821

Closed
opened 2026-03-13 08:05:42 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Chubbyduck1 on GitHub (Mar 10, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use Stripe (Subscription) with Organizations Plugin
  2. Create Two Organizations (Org-A, Org-B)
  3. Subscribe to "Basic" plan on Org-A (With reference id of Org-A)
  4. Attempt to subscribe to "Premium" plan on Org-B (With reference id of Org-B)

You'll see that it's upgrading Org-A, instead of Org-B, including using pricing of Org-A

Current vs. Expected behavior

I expected Org-B to be attempted to upgrade, as I'm using reference id, but instead it goes to upgrade Org-A, as it had been upgraded first, and was in the database.

What version of Better Auth are you using?

1.2.3

Provide environment information

- OS: Windows 10
- Browser: Brave
- DB: Prisma

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

export const auth = betterAuth({
  database: prismaAdapter(database, {
    provider: "sqlite",
  }),
  plugins: [
    username(),
    organization(),
    stripe({
      stripeClient,
      stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
      createCustomerOnSignUp: true,
      subscription: {
        enabled: true,
        plans: [
          {
            name: "basic",
            priceId: process.env.STRIPE_PLAN_BASIC_ID!,
            limits: {
              seats: 5,
            },
          },
          {
            name: "premium",
            priceId: process.env.STRIPE_PLAN_PREMIUM_ID!,
            limits: {
              seats: 10,
            },
          },
        ],
      },
    }),
  ],
  emailAndPassword: {
    enabled: true,
  },
});

Additional context

The exact problem line appears to be here, as it's always returning the first, if nothing else, instead of creating a new subscription for the reference id.
f90581d7ab/packages/stripe/src/index.ts (L239-L243)

Originally created by @Chubbyduck1 on GitHub (Mar 10, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use Stripe (Subscription) with Organizations Plugin 2. Create Two Organizations (Org-A, Org-B) 3. Subscribe to "Basic" plan on Org-A (With reference id of Org-A) 4. Attempt to subscribe to "Premium" plan on Org-B (With reference id of Org-B) You'll see that it's upgrading Org-A, instead of Org-B, including using pricing of Org-A ### Current vs. Expected behavior I expected Org-B to be attempted to upgrade, as I'm using reference id, but instead it goes to upgrade Org-A, as it had been upgraded first, and was in the database. ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash - OS: Windows 10 - Browser: Brave - DB: Prisma ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: prismaAdapter(database, { provider: "sqlite", }), plugins: [ username(), organization(), stripe({ stripeClient, stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET!, createCustomerOnSignUp: true, subscription: { enabled: true, plans: [ { name: "basic", priceId: process.env.STRIPE_PLAN_BASIC_ID!, limits: { seats: 5, }, }, { name: "premium", priceId: process.env.STRIPE_PLAN_PREMIUM_ID!, limits: { seats: 10, }, }, ], }, }), ], emailAndPassword: { enabled: true, }, }); ``` ### Additional context The exact problem line appears to be here, as it's always returning the first, if nothing else, instead of creating a new subscription for the reference id. https://github.com/better-auth/better-auth/blob/f90581d7ab0493fb58d3c2654c326f6f28a684b3/packages/stripe/src/index.ts#L239-L243
GiteaMirror added the bug label 2026-03-13 08:05:42 -05:00
Author
Owner

@x751685875 commented on GitHub (Mar 11, 2025):

I also care about this problem.

@x751685875 commented on GitHub (Mar 11, 2025): I also care about this problem.
Author
Owner

@Smidge commented on GitHub (May 2, 2025):

@Chubbyduck1 Could you repeat your test? I don't think this is a problem anymore as it passes subscriptionToUpdate instead so I think gets the right one?

@Smidge commented on GitHub (May 2, 2025): @Chubbyduck1 Could you repeat your test? I don't think this is a problem anymore as it passes `subscriptionToUpdate` instead so I think gets the right one?
Author
Owner

@Kinfe123 commented on GitHub (May 29, 2025):

closing for now. if this is an issue. let us know.

@Kinfe123 commented on GitHub (May 29, 2025): closing for now. if this is an issue. let us know.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#821