@better-auth/stripe 1.5.5 → 1.5.7-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as stripe, s as StripePlan } from "./index-Dnto1ft4.mjs";
1
+ import { n as stripe, s as StripePlan } from "./index-DDwLbqpK.mjs";
2
2
  import * as better_auth0 from "better-auth";
3
3
 
4
4
  //#region src/error-codes.d.ts
package/dist/client.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { t as STRIPE_ERROR_CODES } from "./error-codes-CCosYkXx.mjs";
2
-
1
+ import { t as STRIPE_ERROR_CODES } from "./error-codes-DFj-5pDu.mjs";
3
2
  //#region src/client.ts
4
3
  const stripeClient = (options) => {
5
4
  return {
@@ -12,7 +11,7 @@ const stripeClient = (options) => {
12
11
  $ERROR_CODES: STRIPE_ERROR_CODES
13
12
  };
14
13
  };
15
-
16
14
  //#endregion
17
15
  export { STRIPE_ERROR_CODES, stripeClient };
16
+
18
17
  //# sourceMappingURL=client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport { STRIPE_ERROR_CODES } from \"./error-codes\";\nimport type { StripePlan, stripe } from \"./index\";\nexport const stripeClient = <\n\tO extends {\n\t\tsubscription: boolean;\n\t},\n>(\n\toptions?: O | undefined,\n) => {\n\treturn {\n\t\tid: \"stripe-client\",\n\t\t$InferServerPlugin: {} as ReturnType<\n\t\t\ttypeof stripe<\n\t\t\t\tO[\"subscription\"] extends true\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstripeClient: any;\n\t\t\t\t\t\t\tstripeWebhookSecret: string;\n\t\t\t\t\t\t\tsubscription: {\n\t\t\t\t\t\t\t\tenabled: true;\n\t\t\t\t\t\t\t\tplans: StripePlan[];\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tstripeClient: any;\n\t\t\t\t\t\t\tstripeWebhookSecret: string;\n\t\t\t\t\t\t}\n\t\t\t>\n\t\t>,\n\t\tpathMethods: {\n\t\t\t\"/subscription/billing-portal\": \"POST\",\n\t\t\t\"/subscription/restore\": \"POST\",\n\t\t},\n\t\t$ERROR_CODES: STRIPE_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\nexport * from \"./error-codes\";\n"],"mappings":";;;AAGA,MAAa,gBAKZ,YACI;AACJ,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EAiBtB,aAAa;GACZ,gCAAgC;GAChC,yBAAyB;GACzB;EACD,cAAc;EACd"}
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport { STRIPE_ERROR_CODES } from \"./error-codes\";\nimport type { StripePlan, stripe } from \"./index\";\nexport const stripeClient = <\n\tO extends {\n\t\tsubscription: boolean;\n\t},\n>(\n\toptions?: O | undefined,\n) => {\n\treturn {\n\t\tid: \"stripe-client\",\n\t\t$InferServerPlugin: {} as ReturnType<\n\t\t\ttypeof stripe<\n\t\t\t\tO[\"subscription\"] extends true\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstripeClient: any;\n\t\t\t\t\t\t\tstripeWebhookSecret: string;\n\t\t\t\t\t\t\tsubscription: {\n\t\t\t\t\t\t\t\tenabled: true;\n\t\t\t\t\t\t\t\tplans: StripePlan[];\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tstripeClient: any;\n\t\t\t\t\t\t\tstripeWebhookSecret: string;\n\t\t\t\t\t\t}\n\t\t\t>\n\t\t>,\n\t\tpathMethods: {\n\t\t\t\"/subscription/billing-portal\": \"POST\",\n\t\t\t\"/subscription/restore\": \"POST\",\n\t\t},\n\t\t$ERROR_CODES: STRIPE_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\nexport * from \"./error-codes\";\n"],"mappings":";;AAGA,MAAa,gBAKZ,YACI;AACJ,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EAiBtB,aAAa;GACZ,gCAAgC;GAChC,yBAAyB;GACzB;EACD,cAAc;EACd"}
@@ -1,5 +1,4 @@
1
1
  import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
-
3
2
  //#region src/error-codes.ts
4
3
  const STRIPE_ERROR_CODES = defineErrorCodes({
5
4
  UNAUTHORIZED: "Unauthorized access",
@@ -26,7 +25,7 @@ const STRIPE_ERROR_CODES = defineErrorCodes({
26
25
  ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: "Cannot delete organization with active subscription",
27
26
  ORGANIZATION_REFERENCE_ID_REQUIRED: "Reference ID is required. Provide referenceId or set activeOrganizationId in session"
28
27
  });
29
-
30
28
  //#endregion
31
29
  export { STRIPE_ERROR_CODES as t };
32
- //# sourceMappingURL=error-codes-CCosYkXx.mjs.map
30
+
31
+ //# sourceMappingURL=error-codes-DFj-5pDu.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-codes-CCosYkXx.mjs","names":[],"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const STRIPE_ERROR_CODES = defineErrorCodes({\n\tUNAUTHORIZED: \"Unauthorized access\",\n\tINVALID_REQUEST_BODY: \"Invalid request body\",\n\tSUBSCRIPTION_NOT_FOUND: \"Subscription not found\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"Subscription plan not found\",\n\tALREADY_SUBSCRIBED_PLAN: \"You're already subscribed to this plan\",\n\tREFERENCE_ID_NOT_ALLOWED: \"Reference id is not allowed\",\n\tCUSTOMER_NOT_FOUND: \"Stripe customer not found for this user\",\n\tUNABLE_TO_CREATE_CUSTOMER: \"Unable to create customer\",\n\tUNABLE_TO_CREATE_BILLING_PORTAL: \"Unable to create billing portal session\",\n\tSTRIPE_SIGNATURE_NOT_FOUND: \"Stripe signature not found\",\n\tSTRIPE_WEBHOOK_SECRET_NOT_FOUND: \"Stripe webhook secret not found\",\n\tSTRIPE_WEBHOOK_ERROR: \"Stripe webhook error\",\n\tFAILED_TO_CONSTRUCT_STRIPE_EVENT: \"Failed to construct Stripe event\",\n\tFAILED_TO_FETCH_PLANS: \"Failed to fetch plans\",\n\tEMAIL_VERIFICATION_REQUIRED:\n\t\t\"Email verification is required before you can subscribe to a plan\",\n\tSUBSCRIPTION_NOT_ACTIVE: \"Subscription is not active\",\n\t/**\n\t * @deprecated Use `SUBSCRIPTION_NOT_PENDING_CHANGE` instead.\n\t */\n\tSUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION:\n\t\t\"Subscription is not scheduled for cancellation\",\n\tSUBSCRIPTION_NOT_PENDING_CHANGE:\n\t\t\"Subscription has no pending cancellation or scheduled plan change\",\n\tORGANIZATION_NOT_FOUND: \"Organization not found\",\n\tORGANIZATION_SUBSCRIPTION_NOT_ENABLED:\n\t\t\"Organization subscription is not enabled\",\n\tAUTHORIZE_REFERENCE_REQUIRED:\n\t\t\"Organization subscriptions require authorizeReference callback to be configured\",\n\tORGANIZATION_HAS_ACTIVE_SUBSCRIPTION:\n\t\t\"Cannot delete organization with active subscription\",\n\tORGANIZATION_REFERENCE_ID_REQUIRED:\n\t\t\"Reference ID is required. Provide referenceId or set activeOrganizationId in session\",\n});\n"],"mappings":";;;AAEA,MAAa,qBAAqB,iBAAiB;CAClD,cAAc;CACd,sBAAsB;CACtB,wBAAwB;CACxB,6BAA6B;CAC7B,yBAAyB;CACzB,0BAA0B;CAC1B,oBAAoB;CACpB,2BAA2B;CAC3B,iCAAiC;CACjC,4BAA4B;CAC5B,iCAAiC;CACjC,sBAAsB;CACtB,kCAAkC;CAClC,uBAAuB;CACvB,6BACC;CACD,yBAAyB;CAIzB,6CACC;CACD,iCACC;CACD,wBAAwB;CACxB,uCACC;CACD,8BACC;CACD,sCACC;CACD,oCACC;CACD,CAAC"}
1
+ {"version":3,"file":"error-codes-DFj-5pDu.mjs","names":[],"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const STRIPE_ERROR_CODES = defineErrorCodes({\n\tUNAUTHORIZED: \"Unauthorized access\",\n\tINVALID_REQUEST_BODY: \"Invalid request body\",\n\tSUBSCRIPTION_NOT_FOUND: \"Subscription not found\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"Subscription plan not found\",\n\tALREADY_SUBSCRIBED_PLAN: \"You're already subscribed to this plan\",\n\tREFERENCE_ID_NOT_ALLOWED: \"Reference id is not allowed\",\n\tCUSTOMER_NOT_FOUND: \"Stripe customer not found for this user\",\n\tUNABLE_TO_CREATE_CUSTOMER: \"Unable to create customer\",\n\tUNABLE_TO_CREATE_BILLING_PORTAL: \"Unable to create billing portal session\",\n\tSTRIPE_SIGNATURE_NOT_FOUND: \"Stripe signature not found\",\n\tSTRIPE_WEBHOOK_SECRET_NOT_FOUND: \"Stripe webhook secret not found\",\n\tSTRIPE_WEBHOOK_ERROR: \"Stripe webhook error\",\n\tFAILED_TO_CONSTRUCT_STRIPE_EVENT: \"Failed to construct Stripe event\",\n\tFAILED_TO_FETCH_PLANS: \"Failed to fetch plans\",\n\tEMAIL_VERIFICATION_REQUIRED:\n\t\t\"Email verification is required before you can subscribe to a plan\",\n\tSUBSCRIPTION_NOT_ACTIVE: \"Subscription is not active\",\n\t/**\n\t * @deprecated Use `SUBSCRIPTION_NOT_PENDING_CHANGE` instead.\n\t */\n\tSUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION:\n\t\t\"Subscription is not scheduled for cancellation\",\n\tSUBSCRIPTION_NOT_PENDING_CHANGE:\n\t\t\"Subscription has no pending cancellation or scheduled plan change\",\n\tORGANIZATION_NOT_FOUND: \"Organization not found\",\n\tORGANIZATION_SUBSCRIPTION_NOT_ENABLED:\n\t\t\"Organization subscription is not enabled\",\n\tAUTHORIZE_REFERENCE_REQUIRED:\n\t\t\"Organization subscriptions require authorizeReference callback to be configured\",\n\tORGANIZATION_HAS_ACTIVE_SUBSCRIPTION:\n\t\t\"Cannot delete organization with active subscription\",\n\tORGANIZATION_REFERENCE_ID_REQUIRED:\n\t\t\"Reference ID is required. Provide referenceId or set activeOrganizationId in session\",\n});\n"],"mappings":";;AAEA,MAAa,qBAAqB,iBAAiB;CAClD,cAAc;CACd,sBAAsB;CACtB,wBAAwB;CACxB,6BAA6B;CAC7B,yBAAyB;CACzB,0BAA0B;CAC1B,oBAAoB;CACpB,2BAA2B;CAC3B,iCAAiC;CACjC,4BAA4B;CAC5B,iCAAiC;CACjC,sBAAsB;CACtB,kCAAkC;CAClC,uBAAuB;CACvB,6BACC;CACD,yBAAyB;CAIzB,6CACC;CACD,iCACC;CACD,wBAAwB;CACxB,uCACC;CACD,8BACC;CACD,sCACC;CACD,oCACC;CACD,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import * as better_auth0 from "better-auth";
2
2
  import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
3
3
  import * as better_call0 from "better-call";
4
- import * as zod from "zod";
5
4
  import { Organization } from "better-auth/plugins/organization";
6
5
  import Stripe from "stripe";
7
6
 
@@ -161,6 +160,18 @@ type StripePlan = {
161
160
  * automatically sync the seat quantity in Stripe.
162
161
  */
163
162
  seatPriceId?: string | undefined;
163
+ /**
164
+ * Proration behavior when updating this plan's subscription.
165
+ *
166
+ * Controls how Stripe handles mid-cycle price changes.
167
+ * - `create_prorations`: Add proration line items to the next invoice (default)
168
+ * - `always_invoice`: Create prorations and immediately invoice
169
+ * - `none`: No proration; new price applies at next billing cycle
170
+ *
171
+ * @default "create_prorations"
172
+ * @see https://docs.stripe.com/billing/subscriptions/prorations
173
+ */
174
+ prorationBehavior?: Stripe.SubscriptionUpdateParams.ProrationBehavior | undefined;
164
175
  /**
165
176
  * Additional line items to include in the checkout session.
166
177
  *
@@ -490,75 +501,34 @@ declare module "@better-auth/core" {
490
501
  declare const stripe: <O extends StripeOptions>(options: O) => {
491
502
  id: "stripe";
492
503
  endpoints: {
493
- stripeWebhook: better_call0.StrictEndpoint<"/stripe/webhook", {
494
- method: "POST";
495
- metadata: {
496
- openapi: {
497
- operationId: string;
498
- };
499
- scope: "server";
500
- };
501
- cloneRequest: true;
502
- disableBody: true;
503
- }, {
504
+ stripeWebhook: better_call0.Endpoint<"/stripe/webhook", "POST", undefined, Record<string, any> | undefined, [], {
504
505
  success: boolean;
505
- }>;
506
+ }, {
507
+ openapi: {
508
+ operationId: string;
509
+ };
510
+ scope: "server";
511
+ }, undefined>;
506
512
  } & (O["subscription"] extends {
507
513
  enabled: true;
508
514
  } ? {
509
- upgradeSubscription: better_call0.StrictEndpoint<"/subscription/upgrade", {
510
- method: "POST";
511
- body: zod.ZodObject<{
512
- plan: zod.ZodString;
513
- annual: zod.ZodOptional<zod.ZodBoolean>;
514
- referenceId: zod.ZodOptional<zod.ZodString>;
515
- subscriptionId: zod.ZodOptional<zod.ZodString>;
516
- customerType: zod.ZodOptional<zod.ZodEnum<{
517
- user: "user";
518
- organization: "organization";
519
- }>>;
520
- metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
521
- seats: zod.ZodOptional<zod.ZodNumber>;
522
- locale: zod.ZodOptional<zod.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
523
- successUrl: zod.ZodDefault<zod.ZodString>;
524
- cancelUrl: zod.ZodDefault<zod.ZodString>;
525
- returnUrl: zod.ZodOptional<zod.ZodString>;
526
- scheduleAtPeriodEnd: zod.ZodDefault<zod.ZodBoolean>;
527
- disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
528
- }, better_auth0.$strip>;
529
- metadata: {
530
- openapi: {
531
- operationId: string;
532
- };
533
- };
534
- use: (((inputContext: better_call0.MiddlewareInputContext<{
535
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
536
- session: {
537
- session: Record<string, any> & {
538
- id: string;
539
- createdAt: Date;
540
- updatedAt: Date;
541
- userId: string;
542
- expiresAt: Date;
543
- token: string;
544
- ipAddress?: string | null | undefined;
545
- userAgent?: string | null | undefined;
546
- };
547
- user: Record<string, any> & {
548
- id: string;
549
- createdAt: Date;
550
- updatedAt: Date;
551
- email: string;
552
- emailVerified: boolean;
553
- name: string;
554
- image?: string | null | undefined;
555
- };
556
- };
557
- }>)[];
558
- }>) => Promise<{
559
- session: StripeCtxSession;
560
- }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
561
- }, {
515
+ upgradeSubscription: better_call0.Endpoint<"/subscription/upgrade", "POST", {
516
+ plan: string;
517
+ annual?: boolean | undefined;
518
+ referenceId?: string | undefined;
519
+ subscriptionId?: string | undefined;
520
+ customerType?: "user" | "organization" | undefined;
521
+ metadata?: Record<string, any> | undefined;
522
+ seats?: number | undefined;
523
+ locale?: Stripe.Checkout.Session.Locale | undefined;
524
+ successUrl?: string | undefined;
525
+ cancelUrl?: string | undefined;
526
+ returnUrl?: string | undefined;
527
+ scheduleAtPeriodEnd?: boolean | undefined;
528
+ disableRedirect?: boolean | undefined;
529
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
530
+ session: StripeCtxSession;
531
+ }>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], {
562
532
  url: string;
563
533
  redirect: boolean;
564
534
  } | {
@@ -639,140 +609,44 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
639
609
  idempotencyKey?: string;
640
610
  stripeAccount?: string;
641
611
  };
642
- }>;
643
- cancelSubscription: better_call0.StrictEndpoint<"/subscription/cancel", {
644
- method: "POST";
645
- body: zod.ZodObject<{
646
- referenceId: zod.ZodOptional<zod.ZodString>;
647
- subscriptionId: zod.ZodOptional<zod.ZodString>;
648
- customerType: zod.ZodOptional<zod.ZodEnum<{
649
- user: "user";
650
- organization: "organization";
651
- }>>;
652
- returnUrl: zod.ZodString;
653
- disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
654
- }, better_auth0.$strip>;
655
- metadata: {
656
- openapi: {
657
- operationId: string;
658
- };
659
- };
660
- use: (((inputContext: better_call0.MiddlewareInputContext<{
661
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
662
- session: {
663
- session: Record<string, any> & {
664
- id: string;
665
- createdAt: Date;
666
- updatedAt: Date;
667
- userId: string;
668
- expiresAt: Date;
669
- token: string;
670
- ipAddress?: string | null | undefined;
671
- userAgent?: string | null | undefined;
672
- };
673
- user: Record<string, any> & {
674
- id: string;
675
- createdAt: Date;
676
- updatedAt: Date;
677
- email: string;
678
- emailVerified: boolean;
679
- name: string;
680
- image?: string | null | undefined;
681
- };
682
- };
683
- }>)[];
684
- }>) => Promise<{
685
- session: StripeCtxSession;
686
- }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
687
612
  }, {
613
+ openapi: {
614
+ operationId: string;
615
+ };
616
+ }, undefined>;
617
+ cancelSubscription: better_call0.Endpoint<"/subscription/cancel", "POST", {
618
+ returnUrl: string;
619
+ referenceId?: string | undefined;
620
+ subscriptionId?: string | undefined;
621
+ customerType?: "user" | "organization" | undefined;
622
+ disableRedirect?: boolean | undefined;
623
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
624
+ session: StripeCtxSession;
625
+ }>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], {
688
626
  url: string;
689
627
  redirect: boolean;
690
- }>;
691
- restoreSubscription: better_call0.StrictEndpoint<"/subscription/restore", {
692
- method: "POST";
693
- body: zod.ZodObject<{
694
- referenceId: zod.ZodOptional<zod.ZodString>;
695
- subscriptionId: zod.ZodOptional<zod.ZodString>;
696
- customerType: zod.ZodOptional<zod.ZodEnum<{
697
- user: "user";
698
- organization: "organization";
699
- }>>;
700
- }, better_auth0.$strip>;
701
- metadata: {
702
- openapi: {
703
- operationId: string;
704
- };
628
+ }, {
629
+ openapi: {
630
+ operationId: string;
705
631
  };
706
- use: (((inputContext: better_call0.MiddlewareInputContext<{
707
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
708
- session: {
709
- session: Record<string, any> & {
710
- id: string;
711
- createdAt: Date;
712
- updatedAt: Date;
713
- userId: string;
714
- expiresAt: Date;
715
- token: string;
716
- ipAddress?: string | null | undefined;
717
- userAgent?: string | null | undefined;
718
- };
719
- user: Record<string, any> & {
720
- id: string;
721
- createdAt: Date;
722
- updatedAt: Date;
723
- email: string;
724
- emailVerified: boolean;
725
- name: string;
726
- image?: string | null | undefined;
727
- };
728
- };
729
- }>)[];
730
- }>) => Promise<{
731
- session: StripeCtxSession;
732
- }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
733
- }, Stripe.Response<Stripe.Subscription>>;
734
- listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
735
- method: "GET";
736
- query: zod.ZodOptional<zod.ZodObject<{
737
- referenceId: zod.ZodOptional<zod.ZodString>;
738
- customerType: zod.ZodOptional<zod.ZodEnum<{
739
- user: "user";
740
- organization: "organization";
741
- }>>;
742
- }, better_auth0.$strip>>;
743
- metadata: {
744
- openapi: {
745
- operationId: string;
746
- };
632
+ }, undefined>;
633
+ restoreSubscription: better_call0.Endpoint<"/subscription/restore", "POST", {
634
+ referenceId?: string | undefined;
635
+ subscriptionId?: string | undefined;
636
+ customerType?: "user" | "organization" | undefined;
637
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
638
+ session: StripeCtxSession;
639
+ }>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], Stripe.Response<Stripe.Subscription>, {
640
+ openapi: {
641
+ operationId: string;
747
642
  };
748
- use: (((inputContext: better_call0.MiddlewareInputContext<{
749
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
750
- session: {
751
- session: Record<string, any> & {
752
- id: string;
753
- createdAt: Date;
754
- updatedAt: Date;
755
- userId: string;
756
- expiresAt: Date;
757
- token: string;
758
- ipAddress?: string | null | undefined;
759
- userAgent?: string | null | undefined;
760
- };
761
- user: Record<string, any> & {
762
- id: string;
763
- createdAt: Date;
764
- updatedAt: Date;
765
- email: string;
766
- emailVerified: boolean;
767
- name: string;
768
- image?: string | null | undefined;
769
- };
770
- };
771
- }>)[];
772
- }>) => Promise<{
773
- session: StripeCtxSession;
774
- }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
775
- }, {
643
+ }, undefined>;
644
+ listActiveSubscriptions: better_call0.Endpoint<"/subscription/list", "GET", undefined, {
645
+ referenceId?: string | undefined;
646
+ customerType?: "user" | "organization" | undefined;
647
+ } | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
648
+ session: StripeCtxSession;
649
+ }>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], {
776
650
  limits: Record<string, unknown> | undefined;
777
651
  priceId: string | undefined;
778
652
  id: string;
@@ -793,65 +667,32 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
793
667
  seats?: number | undefined;
794
668
  billingInterval?: "day" | "week" | "month" | "year" | undefined;
795
669
  stripeScheduleId?: string | undefined;
796
- }[]>;
797
- subscriptionSuccess: better_call0.StrictEndpoint<"/subscription/success", {
798
- method: "GET";
799
- query: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
800
- metadata: {
801
- openapi: {
802
- operationId: string;
803
- };
670
+ }[], {
671
+ openapi: {
672
+ operationId: string;
804
673
  };
805
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
806
- }, never>;
807
- createBillingPortal: better_call0.StrictEndpoint<"/subscription/billing-portal", {
808
- method: "POST";
809
- body: zod.ZodObject<{
810
- locale: zod.ZodOptional<zod.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
811
- referenceId: zod.ZodOptional<zod.ZodString>;
812
- customerType: zod.ZodOptional<zod.ZodEnum<{
813
- user: "user";
814
- organization: "organization";
815
- }>>;
816
- returnUrl: zod.ZodDefault<zod.ZodString>;
817
- disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
818
- }, better_auth0.$strip>;
819
- metadata: {
820
- openapi: {
821
- operationId: string;
822
- };
674
+ }, undefined>;
675
+ subscriptionSuccess: better_call0.Endpoint<"/subscription/success", "GET", undefined, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], never, {
676
+ openapi: {
677
+ operationId: string;
823
678
  };
824
- use: (((inputContext: better_call0.MiddlewareInputContext<{
825
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
826
- session: {
827
- session: Record<string, any> & {
828
- id: string;
829
- createdAt: Date;
830
- updatedAt: Date;
831
- userId: string;
832
- expiresAt: Date;
833
- token: string;
834
- ipAddress?: string | null | undefined;
835
- userAgent?: string | null | undefined;
836
- };
837
- user: Record<string, any> & {
838
- id: string;
839
- createdAt: Date;
840
- updatedAt: Date;
841
- email: string;
842
- emailVerified: boolean;
843
- name: string;
844
- image?: string | null | undefined;
845
- };
846
- };
847
- }>)[];
848
- }>) => Promise<{
849
- session: StripeCtxSession;
850
- }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
851
- }, {
679
+ }, undefined>;
680
+ createBillingPortal: better_call0.Endpoint<"/subscription/billing-portal", "POST", {
681
+ locale?: Stripe.Checkout.Session.Locale | undefined;
682
+ referenceId?: string | undefined;
683
+ customerType?: "user" | "organization" | undefined;
684
+ returnUrl?: string | undefined;
685
+ disableRedirect?: boolean | undefined;
686
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
687
+ session: StripeCtxSession;
688
+ }>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>, better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>], {
852
689
  url: string;
853
690
  redirect: boolean;
854
- }>;
691
+ }, {
692
+ openapi: {
693
+ operationId: string;
694
+ };
695
+ }, undefined>;
855
696
  } : {});
856
697
  init(ctx: better_auth0.AuthContext): {
857
698
  options: {
@@ -990,4 +831,4 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
990
831
  type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
991
832
  //#endregion
992
833
  export { StripeCtxSession as a, Subscription as c, WithStripeCustomerId as d, CustomerType as i, SubscriptionOptions as l, stripe as n, StripeOptions as o, AuthorizeReferenceAction as r, StripePlan as s, StripePlugin as t, WithActiveOrganizationId as u };
993
- //# sourceMappingURL=index-Dnto1ft4.d.mts.map
834
+ //# sourceMappingURL=index-DDwLbqpK.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as StripeCtxSession, c as Subscription, d as WithStripeCustomerId, i as CustomerType, l as SubscriptionOptions, n as stripe, o as StripeOptions, r as AuthorizeReferenceAction, s as StripePlan, t as StripePlugin, u as WithActiveOrganizationId } from "./index-Dnto1ft4.mjs";
1
+ import { a as StripeCtxSession, c as Subscription, d as WithStripeCustomerId, i as CustomerType, l as SubscriptionOptions, n as stripe, o as StripeOptions, r as AuthorizeReferenceAction, s as StripePlan, t as StripePlugin, u as WithActiveOrganizationId } from "./index-DDwLbqpK.mjs";
2
2
  export { AuthorizeReferenceAction, CustomerType, StripeCtxSession, StripeOptions, StripePlan, StripePlugin, Subscription, SubscriptionOptions, WithActiveOrganizationId, WithStripeCustomerId, stripe };
package/dist/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
- import { t as STRIPE_ERROR_CODES } from "./error-codes-CCosYkXx.mjs";
1
+ import { t as STRIPE_ERROR_CODES } from "./error-codes-DFj-5pDu.mjs";
2
2
  import { APIError, HIDE_METADATA } from "better-auth";
3
3
  import { defu } from "defu";
4
4
  import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
5
5
  import { APIError as APIError$1 } from "@better-auth/core/error";
6
6
  import { getSessionFromCtx, originCheck, sessionMiddleware } from "better-auth/api";
7
- import * as z from "zod/v4";
7
+ import * as z from "zod";
8
8
  import { mergeSchema } from "better-auth/db";
9
-
10
9
  //#region src/metadata.ts
11
10
  /**
12
11
  * Customer metadata - set internal fields and extract typed fields.
@@ -48,7 +47,6 @@ const subscriptionMetadata = {
48
47
  };
49
48
  }
50
49
  };
51
-
52
50
  //#endregion
53
51
  //#region src/utils.ts
54
52
  async function getPlans(subscriptionOptions) {
@@ -120,7 +118,6 @@ async function resolvePlanItem(options, items) {
120
118
  plan: void 0
121
119
  } : void 0;
122
120
  }
123
-
124
121
  //#endregion
125
122
  //#region src/hooks.ts
126
123
  /**
@@ -425,7 +422,6 @@ async function onSubscriptionDeleted(ctx, options, event) {
425
422
  ctx.context.logger.error(`Stripe webhook failed. Error: ${error}`);
426
423
  }
427
424
  }
428
-
429
425
  //#endregion
430
426
  //#region src/middleware.ts
431
427
  const stripeSessionMiddleware = createAuthMiddleware({ use: [sessionMiddleware] }, async (ctx) => {
@@ -464,7 +460,6 @@ const referenceMiddleware = (subscriptionOptions, action) => createAuthMiddlewar
464
460
  action
465
461
  }, ctx)) throw APIError$1.from("UNAUTHORIZED", STRIPE_ERROR_CODES.UNAUTHORIZED);
466
462
  });
467
-
468
463
  //#endregion
469
464
  //#region src/routes.ts
470
465
  /**
@@ -581,12 +576,12 @@ const upgradeSubscription = (options) => {
581
576
  let stripeCustomer;
582
577
  try {
583
578
  stripeCustomer = (await client.customers.search({
584
- query: `metadata["${customerMetadata.keys.organizationId}"]:"${org.id}"`,
579
+ query: `metadata["${customerMetadata.keys.organizationId}"]:"${org.id}" AND metadata["${customerMetadata.keys.customerType}"]:"organization"`,
585
580
  limit: 1
586
581
  })).data[0];
587
582
  } catch {
588
583
  ctx.context.logger.warn("Stripe customers.search failed, falling back to customers.list");
589
- for await (const customer of client.customers.list({ limit: 100 })) if (customer.metadata?.[customerMetadata.keys.organizationId] === org.id) {
584
+ for await (const customer of client.customers.list({ limit: 100 })) if (customer.metadata?.[customerMetadata.keys.organizationId] === org.id && customer.metadata?.[customerMetadata.keys.customerType] === "organization") {
590
585
  stripeCustomer = customer;
591
586
  break;
592
587
  }
@@ -869,7 +864,7 @@ const upgradeSubscription = (options) => {
869
864
  for (const [price, delta] of lineItemDelta) for (let i = 0; i < delta; i++) itemUpdates.push({ price });
870
865
  await client.subscriptions.update(activeSubscription.id, {
871
866
  items: itemUpdates,
872
- proration_behavior: "create_prorations"
867
+ proration_behavior: plan.prorationBehavior ?? "create_prorations"
873
868
  }).catch(async (e) => {
874
869
  throw ctx.error("BAD_REQUEST", {
875
870
  message: e.message,
@@ -1267,10 +1262,15 @@ const subscriptionSuccess = (options) => {
1267
1262
  metadata: { openapi: { operationId: "handleSubscriptionSuccess" } },
1268
1263
  use: [originCheck((ctx) => ctx.query.callbackURL)]
1269
1264
  }, async (ctx) => {
1270
- const callbackURL = ctx.query?.callbackURL || "/";
1265
+ let callbackURL = ctx.query?.callbackURL || "/";
1271
1266
  const session = await getSessionFromCtx(ctx);
1272
1267
  if (!session) throw ctx.redirect(getUrl(ctx, callbackURL));
1273
1268
  if (!ctx.query?.checkoutSessionId) throw ctx.redirect(getUrl(ctx, callbackURL));
1269
+ /**
1270
+ * Replace the Stripe {CHECKOUT_SESSION_ID} template variable in callbackURL.
1271
+ * @see https://docs.stripe.com/payments/checkout/custom-success-page?payment-ui=stripe-hosted#modify-the-success-url
1272
+ */
1273
+ callbackURL = callbackURL.replaceAll("{CHECKOUT_SESSION_ID}", ctx.query.checkoutSessionId);
1274
1274
  const checkoutSession = await client.checkout.sessions.retrieve(ctx.query.checkoutSessionId).catch((error) => {
1275
1275
  ctx.context.logger.error("Error retrieving checkout session from Stripe", error);
1276
1276
  return null;
@@ -1463,7 +1463,6 @@ const stripeWebhook = (options) => {
1463
1463
  return ctx.json({ success: true });
1464
1464
  });
1465
1465
  };
1466
-
1467
1466
  //#endregion
1468
1467
  //#region src/schema.ts
1469
1468
  const subscriptions = { subscription: { fields: {
@@ -1558,7 +1557,6 @@ const getSchema = (options) => {
1558
1557
  }
1559
1558
  return mergeSchema(baseSchema, options.schema);
1560
1559
  };
1561
-
1562
1560
  //#endregion
1563
1561
  //#region src/index.ts
1564
1562
  const stripe = (options) => {
@@ -1659,7 +1657,8 @@ const stripe = (options) => {
1659
1657
  }]
1660
1658
  });
1661
1659
  if (!dbSub?.stripeSubscriptionId || !isActiveOrTrialing(dbSub) || !seatPlanNames.has(dbSub.plan)) return;
1662
- const { seatPriceId } = seatPlans.find((p) => p.name.toLowerCase() === dbSub.plan);
1660
+ const plan = seatPlans.find((p) => p.name.toLowerCase() === dbSub.plan);
1661
+ const { seatPriceId } = plan;
1663
1662
  const stripeSub = await client.subscriptions.retrieve(dbSub.stripeSubscriptionId);
1664
1663
  if (!isActiveOrTrialing(stripeSub)) return;
1665
1664
  const seatItem = stripeSub.items.data.find((item) => item.price.id === seatPriceId);
@@ -1673,7 +1672,7 @@ const stripe = (options) => {
1673
1672
  }];
1674
1673
  await client.subscriptions.update(stripeSub.id, {
1675
1674
  items,
1676
- proration_behavior: "create_prorations"
1675
+ proration_behavior: plan.prorationBehavior ?? "create_prorations"
1677
1676
  });
1678
1677
  await ctx.adapter.update({
1679
1678
  model: "subscription",
@@ -1790,7 +1789,7 @@ const stripe = (options) => {
1790
1789
  $ERROR_CODES: STRIPE_ERROR_CODES
1791
1790
  };
1792
1791
  };
1793
-
1794
1792
  //#endregion
1795
1793
  export { stripe };
1794
+
1796
1795
  //# sourceMappingURL=index.mjs.map