@better-auth/stripe 1.5.0-beta.1 → 1.5.0-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.
@@ -2,6 +2,7 @@ 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
4
  import * as zod0 from "zod";
5
+ import { Organization } from "better-auth/plugins/organization";
5
6
  import Stripe from "stripe";
6
7
 
7
8
  //#region src/schema.d.ts
@@ -49,6 +50,18 @@ declare const subscriptions: {
49
50
  required: false;
50
51
  defaultValue: false;
51
52
  };
53
+ cancelAt: {
54
+ type: "date";
55
+ required: false;
56
+ };
57
+ canceledAt: {
58
+ type: "date";
59
+ required: false;
60
+ };
61
+ endedAt: {
62
+ type: "date";
63
+ required: false;
64
+ };
52
65
  seats: {
53
66
  type: "number";
54
67
  required: false;
@@ -66,8 +79,29 @@ declare const user: {
66
79
  };
67
80
  };
68
81
  };
82
+ declare const organization: {
83
+ organization: {
84
+ fields: {
85
+ stripeCustomerId: {
86
+ type: "string";
87
+ required: false;
88
+ };
89
+ };
90
+ };
91
+ };
69
92
  //#endregion
70
93
  //#region src/types.d.ts
94
+ type AuthorizeReferenceAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
95
+ type WithStripeCustomerId = {
96
+ stripeCustomerId?: string;
97
+ };
98
+ type WithActiveOrganizationId = {
99
+ activeOrganizationId?: string;
100
+ };
101
+ type StripeCtxSession = {
102
+ session: Session & WithActiveOrganizationId;
103
+ user: User & WithStripeCustomerId;
104
+ };
71
105
  type StripePlan = {
72
106
  /**
73
107
  * Monthly price id
@@ -198,9 +232,26 @@ interface Subscription {
198
232
  */
199
233
  periodEnd?: Date | undefined;
200
234
  /**
201
- * Cancel at period end
235
+ * Whether this subscription will (if status=active)
236
+ * or did (if status=canceled) cancel at the end of the current billing period.
202
237
  */
203
238
  cancelAtPeriodEnd?: boolean | undefined;
239
+ /**
240
+ * If the subscription is scheduled to be canceled,
241
+ * this is the time at which the cancellation will take effect.
242
+ */
243
+ cancelAt?: Date | undefined;
244
+ /**
245
+ * If the subscription has been canceled, this is the time when it was canceled.
246
+ *
247
+ * Note: If the subscription was canceled with `cancel_at_period_end`,
248
+ * this reflects the cancellation request time, not when the subscription actually ends.
249
+ */
250
+ canceledAt?: Date | undefined;
251
+ /**
252
+ * If the subscription has ended, the date the subscription ended.
253
+ */
254
+ endedAt?: Date | undefined;
204
255
  /**
205
256
  * A field to group subscriptions so you can have multiple subscriptions
206
257
  * for one reference id
@@ -268,7 +319,7 @@ type SubscriptionOptions = {
268
319
  user: User & Record<string, any>;
269
320
  session: Session & Record<string, any>;
270
321
  referenceId: string;
271
- action: "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
322
+ action: AuthorizeReferenceAction;
272
323
  }, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
273
324
  /**
274
325
  * A callback to run after a user has deleted their subscription
@@ -279,6 +330,16 @@ type SubscriptionOptions = {
279
330
  stripeSubscription: Stripe.Subscription;
280
331
  subscription: Subscription;
281
332
  }) => Promise<void>) | undefined;
333
+ /**
334
+ * A callback to run when a subscription is created
335
+ * @returns
336
+ */
337
+ onSubscriptionCreated?: ((data: {
338
+ event: Stripe.Event;
339
+ stripeSubscription: Stripe.Subscription;
340
+ subscription: Subscription;
341
+ plan: StripePlan;
342
+ }) => Promise<void>) | undefined;
282
343
  /**
283
344
  * parameters for session create params
284
345
  *
@@ -298,12 +359,6 @@ type SubscriptionOptions = {
298
359
  params?: Stripe.Checkout.SessionCreateParams;
299
360
  options?: Stripe.RequestOptions;
300
361
  }) | undefined;
301
- /**
302
- * Enable organization subscription
303
- */
304
- organization?: {
305
- enabled: boolean;
306
- } | undefined;
307
362
  };
308
363
  interface StripeOptions {
309
364
  /**
@@ -328,9 +383,7 @@ interface StripeOptions {
328
383
  */
329
384
  onCustomerCreate?: ((data: {
330
385
  stripeCustomer: Stripe.Customer;
331
- user: User & {
332
- stripeCustomerId: string;
333
- };
386
+ user: User & WithStripeCustomerId;
334
387
  }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
335
388
  /**
336
389
  * A custom function to get the customer create
@@ -347,6 +400,37 @@ interface StripeOptions {
347
400
  } | ({
348
401
  enabled: true;
349
402
  } & SubscriptionOptions)) | undefined;
403
+ /**
404
+ * Organization Stripe integration
405
+ *
406
+ * Enable organizations to have their own Stripe customer ID
407
+ */
408
+ organization?: {
409
+ /**
410
+ * Enable organization Stripe customer
411
+ */
412
+ enabled: true;
413
+ /**
414
+ * A custom function to get the customer create params
415
+ * for organization customers.
416
+ *
417
+ * @param organization - the organization
418
+ * @param ctx - the context object
419
+ * @returns
420
+ */
421
+ getCustomerCreateParams?: ((organization: Organization, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
422
+ /**
423
+ * A callback to run after an organization customer has been created
424
+ *
425
+ * @param data - data containing stripeCustomer and organization
426
+ * @param ctx - the context object
427
+ * @returns
428
+ */
429
+ onCustomerCreate?: ((data: {
430
+ stripeCustomer: Stripe.Customer;
431
+ organization: Organization & WithStripeCustomerId;
432
+ }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
433
+ } | undefined;
350
434
  /**
351
435
  * A callback to run after a stripe event is received
352
436
  * @param event - Stripe Event
@@ -356,10 +440,17 @@ interface StripeOptions {
356
440
  /**
357
441
  * Schema for the stripe plugin
358
442
  */
359
- schema?: InferOptionSchema<typeof subscriptions & typeof user> | undefined;
443
+ schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization> | undefined;
360
444
  }
361
445
  //#endregion
362
446
  //#region src/index.d.ts
447
+ declare module "@better-auth/core" {
448
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
449
+ stripe: {
450
+ creator: typeof stripe;
451
+ };
452
+ }
453
+ }
363
454
  declare const stripe: <O extends StripeOptions>(options: O) => {
364
455
  id: "stripe";
365
456
  endpoints: {
@@ -386,8 +477,13 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
386
477
  annual: zod0.ZodOptional<zod0.ZodBoolean>;
387
478
  referenceId: zod0.ZodOptional<zod0.ZodString>;
388
479
  subscriptionId: zod0.ZodOptional<zod0.ZodString>;
480
+ customerType: zod0.ZodOptional<zod0.ZodEnum<{
481
+ user: "user";
482
+ organization: "organization";
483
+ }>>;
389
484
  metadata: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodAny>>;
390
485
  seats: zod0.ZodOptional<zod0.ZodNumber>;
486
+ locale: zod0.ZodOptional<zod0.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
391
487
  successUrl: zod0.ZodDefault<zod0.ZodString>;
392
488
  cancelUrl: zod0.ZodDefault<zod0.ZodString>;
393
489
  returnUrl: zod0.ZodOptional<zod0.ZodString>;
@@ -398,29 +494,33 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
398
494
  operationId: string;
399
495
  };
400
496
  };
401
- use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
402
- session: {
403
- session: Record<string, any> & {
404
- id: string;
405
- createdAt: Date;
406
- updatedAt: Date;
407
- userId: string;
408
- expiresAt: Date;
409
- token: string;
410
- ipAddress?: string | null | undefined;
411
- userAgent?: string | null | undefined;
412
- };
413
- user: Record<string, any> & {
414
- id: string;
415
- createdAt: Date;
416
- updatedAt: Date;
417
- email: string;
418
- emailVerified: boolean;
419
- name: string;
420
- image?: string | null | undefined;
497
+ use: (((inputContext: better_call0.MiddlewareInputContext<{
498
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
499
+ session: {
500
+ session: Record<string, any> & {
501
+ id: string;
502
+ createdAt: Date;
503
+ updatedAt: Date;
504
+ userId: string;
505
+ expiresAt: Date;
506
+ token: string;
507
+ ipAddress?: string | null | undefined;
508
+ userAgent?: string | null | undefined;
509
+ };
510
+ user: Record<string, any> & {
511
+ id: string;
512
+ createdAt: Date;
513
+ updatedAt: Date;
514
+ email: string;
515
+ emailVerified: boolean;
516
+ name: string;
517
+ image?: string | null | undefined;
518
+ };
421
519
  };
422
- };
423
- }>))[];
520
+ }>)[];
521
+ }>) => Promise<{
522
+ session: StripeCtxSession;
523
+ }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
424
524
  }, {
425
525
  url: string;
426
526
  redirect: boolean;
@@ -448,6 +548,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
448
548
  custom_fields: Array<Stripe.Checkout.Session.CustomField>;
449
549
  custom_text: Stripe.Checkout.Session.CustomText;
450
550
  customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
551
+ customer_account: string | null;
451
552
  customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
452
553
  customer_details: Stripe.Checkout.Session.CustomerDetails | null;
453
554
  customer_email: string | null;
@@ -517,36 +618,45 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
517
618
  body: zod0.ZodObject<{
518
619
  referenceId: zod0.ZodOptional<zod0.ZodString>;
519
620
  subscriptionId: zod0.ZodOptional<zod0.ZodString>;
621
+ customerType: zod0.ZodOptional<zod0.ZodEnum<{
622
+ user: "user";
623
+ organization: "organization";
624
+ }>>;
520
625
  returnUrl: zod0.ZodString;
626
+ disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
521
627
  }, better_auth0.$strip>;
522
628
  metadata: {
523
629
  openapi: {
524
630
  operationId: string;
525
631
  };
526
632
  };
527
- use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
528
- session: {
529
- session: Record<string, any> & {
530
- id: string;
531
- createdAt: Date;
532
- updatedAt: Date;
533
- userId: string;
534
- expiresAt: Date;
535
- token: string;
536
- ipAddress?: string | null | undefined;
537
- userAgent?: string | null | undefined;
538
- };
539
- user: Record<string, any> & {
540
- id: string;
541
- createdAt: Date;
542
- updatedAt: Date;
543
- email: string;
544
- emailVerified: boolean;
545
- name: string;
546
- image?: string | null | undefined;
633
+ use: (((inputContext: better_call0.MiddlewareInputContext<{
634
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
635
+ session: {
636
+ session: Record<string, any> & {
637
+ id: string;
638
+ createdAt: Date;
639
+ updatedAt: Date;
640
+ userId: string;
641
+ expiresAt: Date;
642
+ token: string;
643
+ ipAddress?: string | null | undefined;
644
+ userAgent?: string | null | undefined;
645
+ };
646
+ user: Record<string, any> & {
647
+ id: string;
648
+ createdAt: Date;
649
+ updatedAt: Date;
650
+ email: string;
651
+ emailVerified: boolean;
652
+ name: string;
653
+ image?: string | null | undefined;
654
+ };
547
655
  };
548
- };
549
- }>))[];
656
+ }>)[];
657
+ }>) => Promise<{
658
+ session: StripeCtxSession;
659
+ }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
550
660
  }, {
551
661
  url: string;
552
662
  redirect: boolean;
@@ -556,69 +666,85 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
556
666
  body: zod0.ZodObject<{
557
667
  referenceId: zod0.ZodOptional<zod0.ZodString>;
558
668
  subscriptionId: zod0.ZodOptional<zod0.ZodString>;
669
+ customerType: zod0.ZodOptional<zod0.ZodEnum<{
670
+ user: "user";
671
+ organization: "organization";
672
+ }>>;
559
673
  }, better_auth0.$strip>;
560
674
  metadata: {
561
675
  openapi: {
562
676
  operationId: string;
563
677
  };
564
678
  };
565
- use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
566
- session: {
567
- session: Record<string, any> & {
568
- id: string;
569
- createdAt: Date;
570
- updatedAt: Date;
571
- userId: string;
572
- expiresAt: Date;
573
- token: string;
574
- ipAddress?: string | null | undefined;
575
- userAgent?: string | null | undefined;
576
- };
577
- user: Record<string, any> & {
578
- id: string;
579
- createdAt: Date;
580
- updatedAt: Date;
581
- email: string;
582
- emailVerified: boolean;
583
- name: string;
584
- image?: string | null | undefined;
679
+ use: (((inputContext: better_call0.MiddlewareInputContext<{
680
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
681
+ session: {
682
+ session: Record<string, any> & {
683
+ id: string;
684
+ createdAt: Date;
685
+ updatedAt: Date;
686
+ userId: string;
687
+ expiresAt: Date;
688
+ token: string;
689
+ ipAddress?: string | null | undefined;
690
+ userAgent?: string | null | undefined;
691
+ };
692
+ user: Record<string, any> & {
693
+ id: string;
694
+ createdAt: Date;
695
+ updatedAt: Date;
696
+ email: string;
697
+ emailVerified: boolean;
698
+ name: string;
699
+ image?: string | null | undefined;
700
+ };
585
701
  };
586
- };
587
- }>))[];
702
+ }>)[];
703
+ }>) => Promise<{
704
+ session: StripeCtxSession;
705
+ }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
588
706
  }, Stripe.Response<Stripe.Subscription>>;
589
707
  listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
590
708
  method: "GET";
591
709
  query: zod0.ZodOptional<zod0.ZodObject<{
592
710
  referenceId: zod0.ZodOptional<zod0.ZodString>;
711
+ customerType: zod0.ZodOptional<zod0.ZodEnum<{
712
+ user: "user";
713
+ organization: "organization";
714
+ }>>;
593
715
  }, better_auth0.$strip>>;
594
716
  metadata: {
595
717
  openapi: {
596
718
  operationId: string;
597
719
  };
598
720
  };
599
- use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
600
- session: {
601
- session: Record<string, any> & {
602
- id: string;
603
- createdAt: Date;
604
- updatedAt: Date;
605
- userId: string;
606
- expiresAt: Date;
607
- token: string;
608
- ipAddress?: string | null | undefined;
609
- userAgent?: string | null | undefined;
610
- };
611
- user: Record<string, any> & {
612
- id: string;
613
- createdAt: Date;
614
- updatedAt: Date;
615
- email: string;
616
- emailVerified: boolean;
617
- name: string;
618
- image?: string | null | undefined;
721
+ use: (((inputContext: better_call0.MiddlewareInputContext<{
722
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
723
+ session: {
724
+ session: Record<string, any> & {
725
+ id: string;
726
+ createdAt: Date;
727
+ updatedAt: Date;
728
+ userId: string;
729
+ expiresAt: Date;
730
+ token: string;
731
+ ipAddress?: string | null | undefined;
732
+ userAgent?: string | null | undefined;
733
+ };
734
+ user: Record<string, any> & {
735
+ id: string;
736
+ createdAt: Date;
737
+ updatedAt: Date;
738
+ email: string;
739
+ emailVerified: boolean;
740
+ name: string;
741
+ image?: string | null | undefined;
742
+ };
619
743
  };
620
- };
621
- }>))[];
744
+ }>)[];
745
+ }>) => Promise<{
746
+ session: StripeCtxSession;
747
+ }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
622
748
  }, {
623
749
  limits: Record<string, unknown> | undefined;
624
750
  priceId: string | undefined;
@@ -633,6 +759,9 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
633
759
  periodStart?: Date | undefined;
634
760
  periodEnd?: Date | undefined;
635
761
  cancelAtPeriodEnd?: boolean | undefined;
762
+ cancelAt?: Date | undefined;
763
+ canceledAt?: Date | undefined;
764
+ endedAt?: Date | undefined;
636
765
  groupId?: string | undefined;
637
766
  seats?: number | undefined;
638
767
  }[]>;
@@ -645,55 +774,51 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
645
774
  };
646
775
  };
647
776
  use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
648
- }, {
649
- status: ("NOT_FOUND" | "FOUND" | "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call0.Status;
650
- body: ({
651
- message?: string;
652
- code?: string;
653
- cause?: unknown;
654
- } & Record<string, any>) | undefined;
655
- headers: HeadersInit;
656
- statusCode: number;
657
- name: string;
658
- message: string;
659
- stack?: string;
660
- cause?: unknown;
661
- }>;
777
+ }, never>;
662
778
  createBillingPortal: better_call0.StrictEndpoint<"/subscription/billing-portal", {
663
779
  method: "POST";
664
780
  body: zod0.ZodObject<{
665
781
  locale: zod0.ZodOptional<zod0.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
666
782
  referenceId: zod0.ZodOptional<zod0.ZodString>;
783
+ customerType: zod0.ZodOptional<zod0.ZodEnum<{
784
+ user: "user";
785
+ organization: "organization";
786
+ }>>;
667
787
  returnUrl: zod0.ZodDefault<zod0.ZodString>;
788
+ disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
668
789
  }, better_auth0.$strip>;
669
790
  metadata: {
670
791
  openapi: {
671
792
  operationId: string;
672
793
  };
673
794
  };
674
- use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
675
- session: {
676
- session: Record<string, any> & {
677
- id: string;
678
- createdAt: Date;
679
- updatedAt: Date;
680
- userId: string;
681
- expiresAt: Date;
682
- token: string;
683
- ipAddress?: string | null | undefined;
684
- userAgent?: string | null | undefined;
685
- };
686
- user: Record<string, any> & {
687
- id: string;
688
- createdAt: Date;
689
- updatedAt: Date;
690
- email: string;
691
- emailVerified: boolean;
692
- name: string;
693
- image?: string | null | undefined;
795
+ use: (((inputContext: better_call0.MiddlewareInputContext<{
796
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
797
+ session: {
798
+ session: Record<string, any> & {
799
+ id: string;
800
+ createdAt: Date;
801
+ updatedAt: Date;
802
+ userId: string;
803
+ expiresAt: Date;
804
+ token: string;
805
+ ipAddress?: string | null | undefined;
806
+ userAgent?: string | null | undefined;
807
+ };
808
+ user: Record<string, any> & {
809
+ id: string;
810
+ createdAt: Date;
811
+ updatedAt: Date;
812
+ email: string;
813
+ emailVerified: boolean;
814
+ name: string;
815
+ image?: string | null | undefined;
816
+ };
694
817
  };
695
- };
696
- }>))[];
818
+ }>)[];
819
+ }>) => Promise<{
820
+ session: StripeCtxSession;
821
+ }>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
697
822
  }, {
698
823
  url: string;
699
824
  redirect: boolean;
@@ -704,68 +829,126 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
704
829
  databaseHooks: {
705
830
  user: {
706
831
  create: {
707
- after(user: {
708
- id: string;
709
- createdAt: Date;
710
- updatedAt: Date;
711
- email: string;
712
- emailVerified: boolean;
713
- name: string;
714
- image?: string | null | undefined;
715
- } & Record<string, unknown>, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
832
+ after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
716
833
  };
717
834
  update: {
718
- after(user: {
719
- id: string;
720
- createdAt: Date;
721
- updatedAt: Date;
722
- email: string;
723
- emailVerified: boolean;
724
- name: string;
725
- image?: string | null | undefined;
726
- } & Record<string, unknown>, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
835
+ after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
727
836
  };
728
837
  };
729
838
  };
730
839
  };
731
- };
732
- schema: {};
733
- options: NoInfer<O>;
734
- $ERROR_CODES: {
735
- readonly SUBSCRIPTION_NOT_FOUND: {
736
- code: "SUBSCRIPTION_NOT_FOUND";
737
- message: "Subscription not found";
738
- };
739
- readonly SUBSCRIPTION_PLAN_NOT_FOUND: {
740
- code: "SUBSCRIPTION_PLAN_NOT_FOUND";
741
- message: "Subscription plan not found";
742
- };
743
- readonly ALREADY_SUBSCRIBED_PLAN: {
744
- code: "ALREADY_SUBSCRIBED_PLAN";
745
- message: "You're already subscribed to this plan";
746
- };
747
- readonly UNABLE_TO_CREATE_CUSTOMER: {
748
- code: "UNABLE_TO_CREATE_CUSTOMER";
749
- message: "Unable to create customer";
750
- };
751
- readonly FAILED_TO_FETCH_PLANS: {
752
- code: "FAILED_TO_FETCH_PLANS";
753
- message: "Failed to fetch plans";
754
- };
755
- readonly EMAIL_VERIFICATION_REQUIRED: {
756
- code: "EMAIL_VERIFICATION_REQUIRED";
757
- message: "Email verification is required before you can subscribe to a plan";
840
+ } | undefined;
841
+ schema: {
842
+ user: {
843
+ fields: {
844
+ stripeCustomerId: {
845
+ type: "string";
846
+ required: false;
847
+ };
848
+ };
758
849
  };
759
- readonly SUBSCRIPTION_NOT_ACTIVE: {
760
- code: "SUBSCRIPTION_NOT_ACTIVE";
761
- message: "Subscription is not active";
850
+ } & (O["subscription"] extends {
851
+ enabled: true;
852
+ } ? {
853
+ subscription: {
854
+ fields: {
855
+ plan: {
856
+ type: "string";
857
+ required: true;
858
+ };
859
+ referenceId: {
860
+ type: "string";
861
+ required: true;
862
+ };
863
+ stripeCustomerId: {
864
+ type: "string";
865
+ required: false;
866
+ };
867
+ stripeSubscriptionId: {
868
+ type: "string";
869
+ required: false;
870
+ };
871
+ status: {
872
+ type: "string";
873
+ defaultValue: string;
874
+ };
875
+ periodStart: {
876
+ type: "date";
877
+ required: false;
878
+ };
879
+ periodEnd: {
880
+ type: "date";
881
+ required: false;
882
+ };
883
+ trialStart: {
884
+ type: "date";
885
+ required: false;
886
+ };
887
+ trialEnd: {
888
+ type: "date";
889
+ required: false;
890
+ };
891
+ cancelAtPeriodEnd: {
892
+ type: "boolean";
893
+ required: false;
894
+ defaultValue: false;
895
+ };
896
+ cancelAt: {
897
+ type: "date";
898
+ required: false;
899
+ };
900
+ canceledAt: {
901
+ type: "date";
902
+ required: false;
903
+ };
904
+ endedAt: {
905
+ type: "date";
906
+ required: false;
907
+ };
908
+ seats: {
909
+ type: "number";
910
+ required: false;
911
+ };
912
+ };
762
913
  };
763
- readonly SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: {
764
- code: "SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION";
765
- message: "Subscription is not scheduled for cancellation";
914
+ } : {}) & (O["organization"] extends {
915
+ enabled: true;
916
+ } ? {
917
+ organization: {
918
+ fields: {
919
+ stripeCustomerId: {
920
+ type: "string";
921
+ required: false;
922
+ };
923
+ };
766
924
  };
925
+ } : {});
926
+ options: NoInfer<O>;
927
+ $ERROR_CODES: {
928
+ UNAUTHORIZED: better_auth0.RawError<"UNAUTHORIZED">;
929
+ INVALID_REQUEST_BODY: better_auth0.RawError<"INVALID_REQUEST_BODY">;
930
+ SUBSCRIPTION_NOT_FOUND: better_auth0.RawError<"SUBSCRIPTION_NOT_FOUND">;
931
+ SUBSCRIPTION_PLAN_NOT_FOUND: better_auth0.RawError<"SUBSCRIPTION_PLAN_NOT_FOUND">;
932
+ ALREADY_SUBSCRIBED_PLAN: better_auth0.RawError<"ALREADY_SUBSCRIBED_PLAN">;
933
+ REFERENCE_ID_NOT_ALLOWED: better_auth0.RawError<"REFERENCE_ID_NOT_ALLOWED">;
934
+ CUSTOMER_NOT_FOUND: better_auth0.RawError<"CUSTOMER_NOT_FOUND">;
935
+ UNABLE_TO_CREATE_CUSTOMER: better_auth0.RawError<"UNABLE_TO_CREATE_CUSTOMER">;
936
+ UNABLE_TO_CREATE_BILLING_PORTAL: better_auth0.RawError<"UNABLE_TO_CREATE_BILLING_PORTAL">;
937
+ STRIPE_SIGNATURE_NOT_FOUND: better_auth0.RawError<"STRIPE_SIGNATURE_NOT_FOUND">;
938
+ STRIPE_WEBHOOK_SECRET_NOT_FOUND: better_auth0.RawError<"STRIPE_WEBHOOK_SECRET_NOT_FOUND">;
939
+ STRIPE_WEBHOOK_ERROR: better_auth0.RawError<"STRIPE_WEBHOOK_ERROR">;
940
+ FAILED_TO_CONSTRUCT_STRIPE_EVENT: better_auth0.RawError<"FAILED_TO_CONSTRUCT_STRIPE_EVENT">;
941
+ FAILED_TO_FETCH_PLANS: better_auth0.RawError<"FAILED_TO_FETCH_PLANS">;
942
+ EMAIL_VERIFICATION_REQUIRED: better_auth0.RawError<"EMAIL_VERIFICATION_REQUIRED">;
943
+ SUBSCRIPTION_NOT_ACTIVE: better_auth0.RawError<"SUBSCRIPTION_NOT_ACTIVE">;
944
+ SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: better_auth0.RawError<"SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION">;
945
+ ORGANIZATION_NOT_FOUND: better_auth0.RawError<"ORGANIZATION_NOT_FOUND">;
946
+ ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: better_auth0.RawError<"ORGANIZATION_SUBSCRIPTION_NOT_ENABLED">;
947
+ ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: better_auth0.RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
948
+ ORGANIZATION_REFERENCE_ID_REQUIRED: better_auth0.RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
767
949
  };
768
950
  };
769
951
  type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
770
952
  //#endregion
771
- export { SubscriptionOptions as a, Subscription as i, stripe as n, StripePlan as r, StripePlugin as t };
953
+ export { SubscriptionOptions as a, Subscription as i, stripe as n, StripePlan as r, StripePlugin as t };
954
+ //# sourceMappingURL=index-D9Pr9jIc.d.mts.map