@better-auth/stripe 1.2.3 → 1.2.4-beta.10

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/index.d.mts CHANGED
@@ -5,7 +5,7 @@ import Stripe from 'stripe';
5
5
  import { z } from 'zod';
6
6
  import { APIError } from 'better-auth/api';
7
7
 
8
- type Plan = {
8
+ type StripePlan = {
9
9
  /**
10
10
  * Monthly price id
11
11
  */
@@ -24,6 +24,13 @@ type Plan = {
24
24
  * yearly subscription
25
25
  */
26
26
  annualDiscountPriceId?: string;
27
+ /**
28
+ * To use lookup key instead of price id
29
+ *
30
+ * https://docs.stripe.com/products-prices/
31
+ * manage-prices#lookup-keys
32
+ */
33
+ annualDiscountLookupKey?: string;
27
34
  /**
28
35
  * Plan name
29
36
  */
@@ -186,7 +193,7 @@ interface StripeOptions {
186
193
  /**
187
194
  * List of plan
188
195
  */
189
- plans: Plan[] | (() => Promise<Plan[]>);
196
+ plans: StripePlan[] | (() => Promise<StripePlan[]>);
190
197
  /**
191
198
  * Require email verification before a user is allowed to upgrade
192
199
  * their subscriptions
@@ -204,7 +211,7 @@ interface StripeOptions {
204
211
  event: Stripe.Event;
205
212
  stripeSubscription: Stripe.Subscription;
206
213
  subscription: Subscription;
207
- plan: Plan;
214
+ plan: StripePlan;
208
215
  }, request?: Request) => Promise<void>;
209
216
  /**
210
217
  * A callback to run after a user is about to cancel their subscription
@@ -256,7 +263,7 @@ interface StripeOptions {
256
263
  getCheckoutSessionParams?: (data: {
257
264
  user: User & Record<string, any>;
258
265
  session: Session & Record<string, any>;
259
- plan: Plan;
266
+ plan: StripePlan;
260
267
  subscription: Subscription;
261
268
  }, request?: Request) => Promise<{
262
269
  params?: Stripe.Checkout.SessionCreateParams;
@@ -330,8 +337,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
330
337
  metadata?: Record<string, any> | undefined;
331
338
  annual?: boolean | undefined;
332
339
  referenceId?: string | undefined;
340
+ subscriptionId?: string | undefined;
333
341
  seats?: number | undefined;
334
- uiMode?: "embedded" | "hosted" | undefined;
335
342
  successUrl?: string | undefined;
336
343
  cancelUrl?: string | undefined;
337
344
  returnUrl?: string | undefined;
@@ -503,25 +510,60 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
503
510
  options: {
504
511
  method: "POST";
505
512
  body: z.ZodObject<{
513
+ /**
514
+ * The name of the plan to subscribe
515
+ */
506
516
  plan: z.ZodString;
517
+ /**
518
+ * If annual plan should be applied.
519
+ */
507
520
  annual: z.ZodOptional<z.ZodBoolean>;
521
+ /**
522
+ * Reference id of the subscription to upgrade
523
+ * This is used to identify the subscription to upgrade
524
+ * If not provided, the user's id will be used
525
+ */
508
526
  referenceId: z.ZodOptional<z.ZodString>;
527
+ /**
528
+ * This is to allow a specific subscription to be upgrade.
529
+ * If subscription id is provided, and subscription isn't found,
530
+ * it'll throw an error.
531
+ */
532
+ subscriptionId: z.ZodOptional<z.ZodString>;
533
+ /**
534
+ * Any additional data you want to store in your database
535
+ * subscriptions
536
+ */
509
537
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
538
+ /**
539
+ * If a subscription
540
+ */
510
541
  seats: z.ZodOptional<z.ZodNumber>;
511
- uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
542
+ /**
543
+ * Success url to redirect back after successful subscription
544
+ */
512
545
  successUrl: z.ZodDefault<z.ZodString>;
546
+ /**
547
+ * Cancel URL
548
+ */
513
549
  cancelUrl: z.ZodDefault<z.ZodString>;
550
+ /**
551
+ * Return URL
552
+ */
514
553
  returnUrl: z.ZodOptional<z.ZodString>;
554
+ /**
555
+ * Disable Redirect
556
+ */
515
557
  disableRedirect: z.ZodDefault<z.ZodBoolean>;
516
558
  }, "strip", z.ZodTypeAny, {
517
559
  plan: string;
518
- uiMode: "embedded" | "hosted";
519
560
  successUrl: string;
520
561
  cancelUrl: string;
521
562
  disableRedirect: boolean;
522
563
  metadata?: Record<string, any> | undefined;
523
564
  annual?: boolean | undefined;
524
565
  referenceId?: string | undefined;
566
+ subscriptionId?: string | undefined;
525
567
  seats?: number | undefined;
526
568
  returnUrl?: string | undefined;
527
569
  }, {
@@ -529,8 +571,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
529
571
  metadata?: Record<string, any> | undefined;
530
572
  annual?: boolean | undefined;
531
573
  referenceId?: string | undefined;
574
+ subscriptionId?: string | undefined;
532
575
  seats?: number | undefined;
533
- uiMode?: "embedded" | "hosted" | undefined;
534
576
  successUrl?: string | undefined;
535
577
  cancelUrl?: string | undefined;
536
578
  returnUrl?: string | undefined;
@@ -603,6 +645,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
603
645
  options: {
604
646
  method: "GET";
605
647
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
648
+ use: ((inputContext: {
649
+ body?: any;
650
+ query?: Record<string, any> | undefined;
651
+ request?: Request | undefined;
652
+ headers?: Headers | undefined;
653
+ asResponse?: boolean | undefined;
654
+ returnHeaders?: boolean | undefined;
655
+ use?: better_call.Middleware[] | undefined;
656
+ }) => Promise<void>)[];
606
657
  } & {
607
658
  use: any[];
608
659
  };
@@ -613,6 +664,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
613
664
  body: {
614
665
  returnUrl: string;
615
666
  referenceId?: string | undefined;
667
+ subscriptionId?: string | undefined;
616
668
  };
617
669
  method?: "POST" | undefined;
618
670
  query?: Record<string, any> | undefined;
@@ -641,13 +693,16 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
641
693
  method: "POST";
642
694
  body: z.ZodObject<{
643
695
  referenceId: z.ZodOptional<z.ZodString>;
696
+ subscriptionId: z.ZodOptional<z.ZodString>;
644
697
  returnUrl: z.ZodString;
645
698
  }, "strip", z.ZodTypeAny, {
646
699
  returnUrl: string;
647
700
  referenceId?: string | undefined;
701
+ subscriptionId?: string | undefined;
648
702
  }, {
649
703
  returnUrl: string;
650
704
  referenceId?: string | undefined;
705
+ subscriptionId?: string | undefined;
651
706
  }>;
652
707
  use: (((inputContext: {
653
708
  body?: any;
@@ -823,6 +878,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
823
878
  options: {
824
879
  method: "GET";
825
880
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
881
+ use: ((inputContext: {
882
+ body?: any;
883
+ query?: Record<string, any> | undefined;
884
+ request?: Request | undefined;
885
+ headers?: Headers | undefined;
886
+ asResponse?: boolean | undefined;
887
+ returnHeaders?: boolean | undefined;
888
+ use?: better_call.Middleware[] | undefined;
889
+ }) => Promise<void>)[];
826
890
  } & {
827
891
  use: any[];
828
892
  };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import Stripe from 'stripe';
5
5
  import { z } from 'zod';
6
6
  import { APIError } from 'better-auth/api';
7
7
 
8
- type Plan = {
8
+ type StripePlan = {
9
9
  /**
10
10
  * Monthly price id
11
11
  */
@@ -24,6 +24,13 @@ type Plan = {
24
24
  * yearly subscription
25
25
  */
26
26
  annualDiscountPriceId?: string;
27
+ /**
28
+ * To use lookup key instead of price id
29
+ *
30
+ * https://docs.stripe.com/products-prices/
31
+ * manage-prices#lookup-keys
32
+ */
33
+ annualDiscountLookupKey?: string;
27
34
  /**
28
35
  * Plan name
29
36
  */
@@ -186,7 +193,7 @@ interface StripeOptions {
186
193
  /**
187
194
  * List of plan
188
195
  */
189
- plans: Plan[] | (() => Promise<Plan[]>);
196
+ plans: StripePlan[] | (() => Promise<StripePlan[]>);
190
197
  /**
191
198
  * Require email verification before a user is allowed to upgrade
192
199
  * their subscriptions
@@ -204,7 +211,7 @@ interface StripeOptions {
204
211
  event: Stripe.Event;
205
212
  stripeSubscription: Stripe.Subscription;
206
213
  subscription: Subscription;
207
- plan: Plan;
214
+ plan: StripePlan;
208
215
  }, request?: Request) => Promise<void>;
209
216
  /**
210
217
  * A callback to run after a user is about to cancel their subscription
@@ -256,7 +263,7 @@ interface StripeOptions {
256
263
  getCheckoutSessionParams?: (data: {
257
264
  user: User & Record<string, any>;
258
265
  session: Session & Record<string, any>;
259
- plan: Plan;
266
+ plan: StripePlan;
260
267
  subscription: Subscription;
261
268
  }, request?: Request) => Promise<{
262
269
  params?: Stripe.Checkout.SessionCreateParams;
@@ -330,8 +337,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
330
337
  metadata?: Record<string, any> | undefined;
331
338
  annual?: boolean | undefined;
332
339
  referenceId?: string | undefined;
340
+ subscriptionId?: string | undefined;
333
341
  seats?: number | undefined;
334
- uiMode?: "embedded" | "hosted" | undefined;
335
342
  successUrl?: string | undefined;
336
343
  cancelUrl?: string | undefined;
337
344
  returnUrl?: string | undefined;
@@ -503,25 +510,60 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
503
510
  options: {
504
511
  method: "POST";
505
512
  body: z.ZodObject<{
513
+ /**
514
+ * The name of the plan to subscribe
515
+ */
506
516
  plan: z.ZodString;
517
+ /**
518
+ * If annual plan should be applied.
519
+ */
507
520
  annual: z.ZodOptional<z.ZodBoolean>;
521
+ /**
522
+ * Reference id of the subscription to upgrade
523
+ * This is used to identify the subscription to upgrade
524
+ * If not provided, the user's id will be used
525
+ */
508
526
  referenceId: z.ZodOptional<z.ZodString>;
527
+ /**
528
+ * This is to allow a specific subscription to be upgrade.
529
+ * If subscription id is provided, and subscription isn't found,
530
+ * it'll throw an error.
531
+ */
532
+ subscriptionId: z.ZodOptional<z.ZodString>;
533
+ /**
534
+ * Any additional data you want to store in your database
535
+ * subscriptions
536
+ */
509
537
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
538
+ /**
539
+ * If a subscription
540
+ */
510
541
  seats: z.ZodOptional<z.ZodNumber>;
511
- uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
542
+ /**
543
+ * Success url to redirect back after successful subscription
544
+ */
512
545
  successUrl: z.ZodDefault<z.ZodString>;
546
+ /**
547
+ * Cancel URL
548
+ */
513
549
  cancelUrl: z.ZodDefault<z.ZodString>;
550
+ /**
551
+ * Return URL
552
+ */
514
553
  returnUrl: z.ZodOptional<z.ZodString>;
554
+ /**
555
+ * Disable Redirect
556
+ */
515
557
  disableRedirect: z.ZodDefault<z.ZodBoolean>;
516
558
  }, "strip", z.ZodTypeAny, {
517
559
  plan: string;
518
- uiMode: "embedded" | "hosted";
519
560
  successUrl: string;
520
561
  cancelUrl: string;
521
562
  disableRedirect: boolean;
522
563
  metadata?: Record<string, any> | undefined;
523
564
  annual?: boolean | undefined;
524
565
  referenceId?: string | undefined;
566
+ subscriptionId?: string | undefined;
525
567
  seats?: number | undefined;
526
568
  returnUrl?: string | undefined;
527
569
  }, {
@@ -529,8 +571,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
529
571
  metadata?: Record<string, any> | undefined;
530
572
  annual?: boolean | undefined;
531
573
  referenceId?: string | undefined;
574
+ subscriptionId?: string | undefined;
532
575
  seats?: number | undefined;
533
- uiMode?: "embedded" | "hosted" | undefined;
534
576
  successUrl?: string | undefined;
535
577
  cancelUrl?: string | undefined;
536
578
  returnUrl?: string | undefined;
@@ -603,6 +645,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
603
645
  options: {
604
646
  method: "GET";
605
647
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
648
+ use: ((inputContext: {
649
+ body?: any;
650
+ query?: Record<string, any> | undefined;
651
+ request?: Request | undefined;
652
+ headers?: Headers | undefined;
653
+ asResponse?: boolean | undefined;
654
+ returnHeaders?: boolean | undefined;
655
+ use?: better_call.Middleware[] | undefined;
656
+ }) => Promise<void>)[];
606
657
  } & {
607
658
  use: any[];
608
659
  };
@@ -613,6 +664,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
613
664
  body: {
614
665
  returnUrl: string;
615
666
  referenceId?: string | undefined;
667
+ subscriptionId?: string | undefined;
616
668
  };
617
669
  method?: "POST" | undefined;
618
670
  query?: Record<string, any> | undefined;
@@ -641,13 +693,16 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
641
693
  method: "POST";
642
694
  body: z.ZodObject<{
643
695
  referenceId: z.ZodOptional<z.ZodString>;
696
+ subscriptionId: z.ZodOptional<z.ZodString>;
644
697
  returnUrl: z.ZodString;
645
698
  }, "strip", z.ZodTypeAny, {
646
699
  returnUrl: string;
647
700
  referenceId?: string | undefined;
701
+ subscriptionId?: string | undefined;
648
702
  }, {
649
703
  returnUrl: string;
650
704
  referenceId?: string | undefined;
705
+ subscriptionId?: string | undefined;
651
706
  }>;
652
707
  use: (((inputContext: {
653
708
  body?: any;
@@ -823,6 +878,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
823
878
  options: {
824
879
  method: "GET";
825
880
  query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
881
+ use: ((inputContext: {
882
+ body?: any;
883
+ query?: Record<string, any> | undefined;
884
+ request?: Request | undefined;
885
+ headers?: Headers | undefined;
886
+ asResponse?: boolean | undefined;
887
+ returnHeaders?: boolean | undefined;
888
+ use?: better_call.Middleware[] | undefined;
889
+ }) => Promise<void>)[];
826
890
  } & {
827
891
  use: any[];
828
892
  };