@better-auth/stripe 1.4.10-beta.1 → 1.4.11-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/.turbo/turbo-build.log +8 -9
- package/dist/client.d.mts +3 -72
- package/dist/client.mjs +5 -5
- package/dist/{index-DpiQGYLJ.d.mts → index-CkO4CTbB.d.mts} +276 -187
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +652 -230
- package/package.json +5 -5
- package/src/client.ts +1 -3
- package/src/error-codes.ts +16 -0
- package/src/hooks.ts +229 -53
- package/src/index.ts +141 -46
- package/src/middleware.ts +89 -41
- package/src/routes.ts +638 -337
- package/src/schema.ts +30 -0
- package/src/types.ts +105 -20
- package/src/utils.ts +36 -1
- package/test/stripe-organization.test.ts +1993 -0
- package/{src → test}/stripe.test.ts +3350 -1404
- package/dist/error-codes-qqooUh6R.mjs +0 -16
|
@@ -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
|
-
*
|
|
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:
|
|
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,7 +440,7 @@ 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
|
|
@@ -386,6 +470,10 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
386
470
|
annual: zod0.ZodOptional<zod0.ZodBoolean>;
|
|
387
471
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
388
472
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
473
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
474
|
+
user: "user";
|
|
475
|
+
organization: "organization";
|
|
476
|
+
}>>;
|
|
389
477
|
metadata: zod0.ZodOptional<zod0.ZodRecord<zod0.ZodString, zod0.ZodAny>>;
|
|
390
478
|
seats: zod0.ZodOptional<zod0.ZodNumber>;
|
|
391
479
|
successUrl: zod0.ZodDefault<zod0.ZodString>;
|
|
@@ -398,29 +486,33 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
398
486
|
operationId: string;
|
|
399
487
|
};
|
|
400
488
|
};
|
|
401
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
402
|
-
|
|
403
|
-
session:
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
489
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
490
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
491
|
+
session: {
|
|
492
|
+
session: Record<string, any> & {
|
|
493
|
+
id: string;
|
|
494
|
+
createdAt: Date;
|
|
495
|
+
updatedAt: Date;
|
|
496
|
+
userId: string;
|
|
497
|
+
expiresAt: Date;
|
|
498
|
+
token: string;
|
|
499
|
+
ipAddress?: string | null | undefined;
|
|
500
|
+
userAgent?: string | null | undefined;
|
|
501
|
+
};
|
|
502
|
+
user: Record<string, any> & {
|
|
503
|
+
id: string;
|
|
504
|
+
createdAt: Date;
|
|
505
|
+
updatedAt: Date;
|
|
506
|
+
email: string;
|
|
507
|
+
emailVerified: boolean;
|
|
508
|
+
name: string;
|
|
509
|
+
image?: string | null | undefined;
|
|
510
|
+
};
|
|
421
511
|
};
|
|
422
|
-
};
|
|
423
|
-
}>)
|
|
512
|
+
}>)[];
|
|
513
|
+
}>) => Promise<{
|
|
514
|
+
session: StripeCtxSession;
|
|
515
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
424
516
|
}, {
|
|
425
517
|
url: string;
|
|
426
518
|
redirect: boolean;
|
|
@@ -517,36 +609,45 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
517
609
|
body: zod0.ZodObject<{
|
|
518
610
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
519
611
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
612
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
613
|
+
user: "user";
|
|
614
|
+
organization: "organization";
|
|
615
|
+
}>>;
|
|
520
616
|
returnUrl: zod0.ZodString;
|
|
617
|
+
disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
|
|
521
618
|
}, better_auth0.$strip>;
|
|
522
619
|
metadata: {
|
|
523
620
|
openapi: {
|
|
524
621
|
operationId: string;
|
|
525
622
|
};
|
|
526
623
|
};
|
|
527
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
528
|
-
|
|
529
|
-
session:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
624
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
625
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
626
|
+
session: {
|
|
627
|
+
session: Record<string, any> & {
|
|
628
|
+
id: string;
|
|
629
|
+
createdAt: Date;
|
|
630
|
+
updatedAt: Date;
|
|
631
|
+
userId: string;
|
|
632
|
+
expiresAt: Date;
|
|
633
|
+
token: string;
|
|
634
|
+
ipAddress?: string | null | undefined;
|
|
635
|
+
userAgent?: string | null | undefined;
|
|
636
|
+
};
|
|
637
|
+
user: Record<string, any> & {
|
|
638
|
+
id: string;
|
|
639
|
+
createdAt: Date;
|
|
640
|
+
updatedAt: Date;
|
|
641
|
+
email: string;
|
|
642
|
+
emailVerified: boolean;
|
|
643
|
+
name: string;
|
|
644
|
+
image?: string | null | undefined;
|
|
645
|
+
};
|
|
547
646
|
};
|
|
548
|
-
};
|
|
549
|
-
}>)
|
|
647
|
+
}>)[];
|
|
648
|
+
}>) => Promise<{
|
|
649
|
+
session: StripeCtxSession;
|
|
650
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
550
651
|
}, {
|
|
551
652
|
url: string;
|
|
552
653
|
redirect: boolean;
|
|
@@ -556,69 +657,85 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
556
657
|
body: zod0.ZodObject<{
|
|
557
658
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
558
659
|
subscriptionId: zod0.ZodOptional<zod0.ZodString>;
|
|
660
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
661
|
+
user: "user";
|
|
662
|
+
organization: "organization";
|
|
663
|
+
}>>;
|
|
559
664
|
}, better_auth0.$strip>;
|
|
560
665
|
metadata: {
|
|
561
666
|
openapi: {
|
|
562
667
|
operationId: string;
|
|
563
668
|
};
|
|
564
669
|
};
|
|
565
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
566
|
-
|
|
567
|
-
session:
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
670
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
671
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
672
|
+
session: {
|
|
673
|
+
session: Record<string, any> & {
|
|
674
|
+
id: string;
|
|
675
|
+
createdAt: Date;
|
|
676
|
+
updatedAt: Date;
|
|
677
|
+
userId: string;
|
|
678
|
+
expiresAt: Date;
|
|
679
|
+
token: string;
|
|
680
|
+
ipAddress?: string | null | undefined;
|
|
681
|
+
userAgent?: string | null | undefined;
|
|
682
|
+
};
|
|
683
|
+
user: Record<string, any> & {
|
|
684
|
+
id: string;
|
|
685
|
+
createdAt: Date;
|
|
686
|
+
updatedAt: Date;
|
|
687
|
+
email: string;
|
|
688
|
+
emailVerified: boolean;
|
|
689
|
+
name: string;
|
|
690
|
+
image?: string | null | undefined;
|
|
691
|
+
};
|
|
585
692
|
};
|
|
586
|
-
};
|
|
587
|
-
}>)
|
|
693
|
+
}>)[];
|
|
694
|
+
}>) => Promise<{
|
|
695
|
+
session: StripeCtxSession;
|
|
696
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
588
697
|
}, Stripe.Response<Stripe.Subscription>>;
|
|
589
698
|
listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
|
|
590
699
|
method: "GET";
|
|
591
700
|
query: zod0.ZodOptional<zod0.ZodObject<{
|
|
592
701
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
702
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
703
|
+
user: "user";
|
|
704
|
+
organization: "organization";
|
|
705
|
+
}>>;
|
|
593
706
|
}, better_auth0.$strip>>;
|
|
594
707
|
metadata: {
|
|
595
708
|
openapi: {
|
|
596
709
|
operationId: string;
|
|
597
710
|
};
|
|
598
711
|
};
|
|
599
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
600
|
-
|
|
601
|
-
session:
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
712
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
713
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
714
|
+
session: {
|
|
715
|
+
session: Record<string, any> & {
|
|
716
|
+
id: string;
|
|
717
|
+
createdAt: Date;
|
|
718
|
+
updatedAt: Date;
|
|
719
|
+
userId: string;
|
|
720
|
+
expiresAt: Date;
|
|
721
|
+
token: string;
|
|
722
|
+
ipAddress?: string | null | undefined;
|
|
723
|
+
userAgent?: string | null | undefined;
|
|
724
|
+
};
|
|
725
|
+
user: Record<string, any> & {
|
|
726
|
+
id: string;
|
|
727
|
+
createdAt: Date;
|
|
728
|
+
updatedAt: Date;
|
|
729
|
+
email: string;
|
|
730
|
+
emailVerified: boolean;
|
|
731
|
+
name: string;
|
|
732
|
+
image?: string | null | undefined;
|
|
733
|
+
};
|
|
619
734
|
};
|
|
620
|
-
};
|
|
621
|
-
}>)
|
|
735
|
+
}>)[];
|
|
736
|
+
}>) => Promise<{
|
|
737
|
+
session: StripeCtxSession;
|
|
738
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
622
739
|
}, {
|
|
623
740
|
limits: Record<string, unknown> | undefined;
|
|
624
741
|
priceId: string | undefined;
|
|
@@ -633,6 +750,9 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
633
750
|
periodStart?: Date | undefined;
|
|
634
751
|
periodEnd?: Date | undefined;
|
|
635
752
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
753
|
+
cancelAt?: Date | undefined;
|
|
754
|
+
canceledAt?: Date | undefined;
|
|
755
|
+
endedAt?: Date | undefined;
|
|
636
756
|
groupId?: string | undefined;
|
|
637
757
|
seats?: number | undefined;
|
|
638
758
|
}[]>;
|
|
@@ -645,55 +765,51 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
645
765
|
};
|
|
646
766
|
};
|
|
647
767
|
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
|
-
}>;
|
|
768
|
+
}, never>;
|
|
662
769
|
createBillingPortal: better_call0.StrictEndpoint<"/subscription/billing-portal", {
|
|
663
770
|
method: "POST";
|
|
664
771
|
body: zod0.ZodObject<{
|
|
665
772
|
locale: zod0.ZodOptional<zod0.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
|
|
666
773
|
referenceId: zod0.ZodOptional<zod0.ZodString>;
|
|
774
|
+
customerType: zod0.ZodOptional<zod0.ZodEnum<{
|
|
775
|
+
user: "user";
|
|
776
|
+
organization: "organization";
|
|
777
|
+
}>>;
|
|
667
778
|
returnUrl: zod0.ZodDefault<zod0.ZodString>;
|
|
779
|
+
disableRedirect: zod0.ZodDefault<zod0.ZodBoolean>;
|
|
668
780
|
}, better_auth0.$strip>;
|
|
669
781
|
metadata: {
|
|
670
782
|
openapi: {
|
|
671
783
|
operationId: string;
|
|
672
784
|
};
|
|
673
785
|
};
|
|
674
|
-
use: (((inputContext: better_call0.MiddlewareInputContext<
|
|
675
|
-
|
|
676
|
-
session:
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
786
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<{
|
|
787
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
788
|
+
session: {
|
|
789
|
+
session: Record<string, any> & {
|
|
790
|
+
id: string;
|
|
791
|
+
createdAt: Date;
|
|
792
|
+
updatedAt: Date;
|
|
793
|
+
userId: string;
|
|
794
|
+
expiresAt: Date;
|
|
795
|
+
token: string;
|
|
796
|
+
ipAddress?: string | null | undefined;
|
|
797
|
+
userAgent?: string | null | undefined;
|
|
798
|
+
};
|
|
799
|
+
user: Record<string, any> & {
|
|
800
|
+
id: string;
|
|
801
|
+
createdAt: Date;
|
|
802
|
+
updatedAt: Date;
|
|
803
|
+
email: string;
|
|
804
|
+
emailVerified: boolean;
|
|
805
|
+
name: string;
|
|
806
|
+
image?: string | null | undefined;
|
|
807
|
+
};
|
|
694
808
|
};
|
|
695
|
-
};
|
|
696
|
-
}>)
|
|
809
|
+
}>)[];
|
|
810
|
+
}>) => Promise<{
|
|
811
|
+
session: StripeCtxSession;
|
|
812
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
697
813
|
}, {
|
|
698
814
|
url: string;
|
|
699
815
|
redirect: boolean;
|
|
@@ -704,66 +820,39 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
704
820
|
databaseHooks: {
|
|
705
821
|
user: {
|
|
706
822
|
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>;
|
|
823
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
716
824
|
};
|
|
717
825
|
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>;
|
|
826
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
|
|
727
827
|
};
|
|
728
828
|
};
|
|
729
829
|
};
|
|
730
830
|
};
|
|
731
|
-
};
|
|
831
|
+
} | undefined;
|
|
732
832
|
schema: {};
|
|
733
833
|
options: NoInfer<O>;
|
|
734
834
|
$ERROR_CODES: {
|
|
735
|
-
readonly
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
readonly
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
readonly
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
readonly
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
readonly
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
readonly
|
|
756
|
-
code: "EMAIL_VERIFICATION_REQUIRED";
|
|
757
|
-
message: "Email verification is required before you can subscribe to a plan";
|
|
758
|
-
};
|
|
759
|
-
readonly SUBSCRIPTION_NOT_ACTIVE: {
|
|
760
|
-
code: "SUBSCRIPTION_NOT_ACTIVE";
|
|
761
|
-
message: "Subscription is not active";
|
|
762
|
-
};
|
|
763
|
-
readonly SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: {
|
|
764
|
-
code: "SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION";
|
|
765
|
-
message: "Subscription is not scheduled for cancellation";
|
|
766
|
-
};
|
|
835
|
+
readonly UNAUTHORIZED: "Unauthorized access";
|
|
836
|
+
readonly INVALID_REQUEST_BODY: "Invalid request body";
|
|
837
|
+
readonly SUBSCRIPTION_NOT_FOUND: "Subscription not found";
|
|
838
|
+
readonly SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found";
|
|
839
|
+
readonly ALREADY_SUBSCRIBED_PLAN: "You're already subscribed to this plan";
|
|
840
|
+
readonly REFERENCE_ID_NOT_ALLOWED: "Reference id is not allowed";
|
|
841
|
+
readonly CUSTOMER_NOT_FOUND: "Stripe customer not found for this user";
|
|
842
|
+
readonly UNABLE_TO_CREATE_CUSTOMER: "Unable to create customer";
|
|
843
|
+
readonly UNABLE_TO_CREATE_BILLING_PORTAL: "Unable to create billing portal session";
|
|
844
|
+
readonly STRIPE_SIGNATURE_NOT_FOUND: "Stripe signature not found";
|
|
845
|
+
readonly STRIPE_WEBHOOK_SECRET_NOT_FOUND: "Stripe webhook secret not found";
|
|
846
|
+
readonly STRIPE_WEBHOOK_ERROR: "Stripe webhook error";
|
|
847
|
+
readonly FAILED_TO_CONSTRUCT_STRIPE_EVENT: "Failed to construct Stripe event";
|
|
848
|
+
readonly FAILED_TO_FETCH_PLANS: "Failed to fetch plans";
|
|
849
|
+
readonly EMAIL_VERIFICATION_REQUIRED: "Email verification is required before you can subscribe to a plan";
|
|
850
|
+
readonly SUBSCRIPTION_NOT_ACTIVE: "Subscription is not active";
|
|
851
|
+
readonly SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: "Subscription is not scheduled for cancellation";
|
|
852
|
+
readonly ORGANIZATION_NOT_FOUND: "Organization not found";
|
|
853
|
+
readonly ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: "Organization subscription is not enabled";
|
|
854
|
+
readonly ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: "Cannot delete organization with active subscription";
|
|
855
|
+
readonly ORGANIZATION_REFERENCE_ID_REQUIRED: "Reference ID is required. Provide referenceId or set activeOrganizationId in session";
|
|
767
856
|
};
|
|
768
857
|
};
|
|
769
858
|
type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-
|
|
1
|
+
import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-CkO4CTbB.mjs";
|
|
2
2
|
export { StripePlan, StripePlugin, Subscription, SubscriptionOptions, stripe };
|