[GH-ISSUE #2079] feat: Attach stripe subscription to organization instead of user #9041

Closed
opened 2026-04-13 04:19:45 -05:00 by GiteaMirror · 12 comments
Owner

Originally created by @saturnonearth on GitHub (Apr 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2079

At the moment it is not possible to associate stripe customers to organizations, and only is it possible to use the "referenceId"

Describe the solution you'd like

At the moment, subscriptions and stripe customers are always created with the user_id. For organizations, this can be a bit messy, as you can end up with multiple active subscription that "reference" a single organization.

I am not sure if this was intentional to have a different flow, but it makes more sense to me to associate the stripe_customer with an organization, if you are going that route.

So it would be cool to add the ability to have a column for stripe_customer to the organization and maybe even add the ability to auto-create the stripe customer upon organization creation.

Let me know if this makes sense.

Describe alternatives you've considered

Not sure

Additional context

No response

Originally created by @saturnonearth on GitHub (Apr 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2079 ### Is your feature request related to a problem? Please describe. At the moment it is not possible to associate stripe customers to organizations, and only is it possible to use the "referenceId" ### Describe the solution you'd like At the moment, subscriptions and stripe customers are always created with the `user_id`. For organizations, this can be a bit messy, as you can end up with multiple active subscription that "reference" a single organization. I am not sure if this was intentional to have a different flow, but it makes more sense to me to associate the stripe_customer with an organization, if you are going that route. So it would be cool to add the ability to have a column for `stripe_customer` to the organization and maybe even add the ability to auto-create the stripe customer upon organization creation. Let me know if this makes sense. ### Describe alternatives you've considered Not sure ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:19:45 -05:00
Author
Owner

@Zai commented on GitHub (May 15, 2025):

Same request on discord : https://discord.com/channels/1288403910284935179/1357127060555829482

<!-- gh-comment-id:2883327555 --> @Zai commented on GitHub (May 15, 2025): Same request on discord : https://discord.com/channels/1288403910284935179/1357127060555829482
Author
Owner

@Cmion commented on GitHub (May 26, 2025):

I opened a PR for this: https://github.com/better-auth/better-auth/pull/2794

<!-- gh-comment-id:2909275220 --> @Cmion commented on GitHub (May 26, 2025): I opened a PR for this: https://github.com/better-auth/better-auth/pull/2794
Author
Owner

@saturnonearth commented on GitHub (May 27, 2025):

I opened a PR for this: #2794

Nice!!

A bit confused, as I was told this was being worked on already - does this differ from the internal implementation that may be being worked on, @Bekacru, or can this be merged?

<!-- gh-comment-id:2913587029 --> @saturnonearth commented on GitHub (May 27, 2025): > I opened a PR for this: [#2794](https://github.com/better-auth/better-auth/pull/2794) Nice!! A bit confused, as I was told this was [being worked on already](https://discord.com/channels/1288403910284935179/1288403910284935182/1364700507410796636) - does this differ from the internal implementation that may be being worked on, @Bekacru, or can this be merged?
Author
Owner

@Cmion commented on GitHub (May 28, 2025):

I opened a PR for this: #2794

Nice!!

A bit confused, as I was told this was being worked on already - does this differ from the internal implementation that may be being worked on, @Bekacru, or can this be merged?

Not sure, it may differ tho

I run better-auth in production and needed the feature as soon as possible. For now I use my own branch of better-auth. I hope it get merged

<!-- gh-comment-id:2914504334 --> @Cmion commented on GitHub (May 28, 2025): > > I opened a PR for this: [#2794](https://github.com/better-auth/better-auth/pull/2794) > > Nice!! > > A bit confused, as I was told this was [being worked on already](https://discord.com/channels/1288403910284935179/1288403910284935182/1364700507410796636) - does this differ from the internal implementation that may be being worked on, [@Bekacru](https://github.com/Bekacru), or can this be merged? Not sure, it may differ tho I run better-auth in production and needed the feature as soon as possible. For now I use my own branch of better-auth. I hope it get merged
Author
Owner

@kchasedevelopment commented on GitHub (Jun 1, 2025):

I 100% agree that this is currently an annoying process. My current problem is finding the organization that the user wants to pay for. Since we need to create the organization before a subscription is created so that we can use the org id as the subscriptions reference id. The current process to actually find which org they want to pay for isn't straight cut because the user can belong to many organizations before they have created there own so the only way i currently see is to use the users stripe customer id to then find the subscription by its stripe customer id and then get that subscriptions reference id which would be the org they are wanting to pay for. The way i handle this is by creating the org on create checkout session and i use that org id as the reference id. The problem then becomes abandoned sessions because better-auth creates a subscription row on checkout session created which they then update on checkout session complete. To combat this, before i create the org i first check if that user has an existing incomplete subscription, if they do i reuse that same reference id again for the checkout session so that a new org isnt created each time. Once they have an active subscription the checkout session shows the manage button so im confused when the OP says that an organization can have multiple active subscriptions as this hasnt been my experience. The docs say that only 1 organization can have 1 active subscription which is what i have experienced so far.

Is this the kind of mess this issue is talking about?

<!-- gh-comment-id:2927054984 --> @kchasedevelopment commented on GitHub (Jun 1, 2025): I 100% agree that this is currently an annoying process. My current problem is finding the organization that the user wants to pay for. Since we need to create the organization before a subscription is created so that we can use the org id as the subscriptions reference id. The current process to actually find which org they want to pay for isn't straight cut because the user can belong to many organizations before they have created there own so the only way i currently see is to use the users stripe customer id to then find the subscription by its stripe customer id and then get that subscriptions reference id which would be the org they are wanting to pay for. The way i handle this is by creating the org on create checkout session and i use that org id as the reference id. The problem then becomes abandoned sessions because better-auth creates a subscription row on checkout session created which they then update on checkout session complete. To combat this, before i create the org i first check if that user has an existing incomplete subscription, if they do i reuse that same reference id again for the checkout session so that a new org isnt created each time. Once they have an active subscription the checkout session shows the manage button so im confused when the OP says that an organization can have multiple active subscriptions as this hasnt been my experience. The docs say that only 1 organization can have 1 active subscription which is what i have experienced so far. Is this the kind of mess this issue is talking about?
Author
Owner

@Cmion commented on GitHub (Jun 1, 2025):

talking

This pr (https://github.com/better-auth/better-auth/pull/2794) I made looks for an active organization and uses that as the reference id. You do not have to manually pass the reference id, it defaults to the user id (if no active organization is found).

Also to ensure a user always belong to an organization you can use a database hook on the session to find/create and pre-populate the active organization.


export const auth = betterAuth({
  databaseHooks: {
      session: {
          create: {
              before: async(session)=>{
                  const organization = await getActiveOrganization(session.userId)
                  return {
                    data: {
                      ...session,
                      activeOrganizationId: organization.id
                    }
                  }
              }
          }
      }
  }
})

<!-- gh-comment-id:2927073984 --> @Cmion commented on GitHub (Jun 1, 2025): > talking This pr (https://github.com/better-auth/better-auth/pull/2794) I made looks for an active organization and uses that as the reference id. You do not have to manually pass the reference id, it defaults to the user id (if no active organization is found). Also to ensure a user always belong to an organization you can use a database hook on the session to find/create and pre-populate the active organization. ```ts export const auth = betterAuth({ databaseHooks: { session: { create: { before: async(session)=>{ const organization = await getActiveOrganization(session.userId) return { data: { ...session, activeOrganizationId: organization.id } } } } } } }) ```
Author
Owner

@kchasedevelopment commented on GitHub (Jun 1, 2025):

This pr (#2794) I made looks for an active organization and uses that as the reference id. You do not have to manually pass the reference id, it defaults to the user id (if no active organization is found).

The question then becomes what defines the users active organization? is it there currently active organization in session? The problem is though the user can be a part of many organizations and there active org could be someone elses organization so youd be using someone elses organization as the reference Id (unless your implementation accounts for this?). This kind of comes back to my question of how do we know what organization the user wants to pay for. The only solution ive seen using what better-auth has provided is to create the organization on checkout session created so that it automatically creates the subscription row with the users stripeCustomerId which creates a direct link between the user and subscription which can then be used.

<!-- gh-comment-id:2927112742 --> @kchasedevelopment commented on GitHub (Jun 1, 2025): > This pr ([#2794](https://github.com/better-auth/better-auth/pull/2794)) I made looks for an active organization and uses that as the reference id. You do not have to manually pass the reference id, it defaults to the user id (if no active organization is found). The question then becomes what defines the users active organization? is it there currently active organization in session? The problem is though the user can be a part of many organizations and there active org could be someone elses organization so youd be using someone elses organization as the reference Id (unless your implementation accounts for this?). This kind of comes back to my question of how do we know what organization the user wants to pay for. The only solution ive seen using what better-auth has provided is to create the organization on checkout session created so that it automatically creates the subscription row with the users stripeCustomerId which creates a direct link between the user and subscription which can then be used.
Author
Owner

@JPustkuchen commented on GitHub (Aug 11, 2025):

Related: https://github.com/better-auth/better-auth/issues/3772

<!-- gh-comment-id:3173905165 --> @JPustkuchen commented on GitHub (Aug 11, 2025): Related: https://github.com/better-auth/better-auth/issues/3772
Author
Owner

@dosubot[bot] commented on GitHub (Nov 10, 2025):

Hi, @saturnonearth. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary

  • You requested a feature to link Stripe subscriptions and customers directly to organizations instead of individual users to prevent multiple active subscriptions per organization.
  • A PR (#2794) was submitted addressing this, receiving positive feedback but also some confusion about its alignment with ongoing internal work.
  • The discussion highlighted challenges in determining which organization a user intends to pay for when they belong to multiple organizations.
  • Another related issue (#3772) was referenced for additional context.
  • The issue remains unresolved with no recent updates.

Next Steps

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3512648983 --> @dosubot[bot] commented on GitHub (Nov 10, 2025): Hi, @saturnonearth. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary** - You requested a feature to link Stripe subscriptions and customers directly to organizations instead of individual users to prevent multiple active subscriptions per organization. - A PR (#2794) was submitted addressing this, receiving positive feedback but also some confusion about its alignment with ongoing internal work. - The discussion highlighted challenges in determining which organization a user intends to pay for when they belong to multiple organizations. - Another related issue (#3772) was referenced for additional context. - The issue remains unresolved with no recent updates. **Next Steps** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@JPustkuchen commented on GitHub (Nov 10, 2025):

Definitely still relevant with several upvotes! :)

<!-- gh-comment-id:3512818957 --> @JPustkuchen commented on GitHub (Nov 10, 2025): Definitely still relevant with several upvotes! :)
Author
Owner

@SawkaDev commented on GitHub (Nov 11, 2025):

Agreed, in a multi tenant app with team members in each organization, it would make more sense for the organization to own the subscription. Also will make transferring ownership of organization to another team member easier.

<!-- gh-comment-id:3514756658 --> @SawkaDev commented on GitHub (Nov 11, 2025): Agreed, in a multi tenant app with team members in each organization, it would make more sense for the organization to own the subscription. Also will make transferring ownership of organization to another team member easier.
Author
Owner

@nathaliedpuc commented on GitHub (Jan 7, 2026):

Thank you @bytaesu ill play with it!

<!-- gh-comment-id:3721081575 --> @nathaliedpuc commented on GitHub (Jan 7, 2026): Thank you @bytaesu ill play with it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9041