@better-auth/stripe 1.5.0 → 1.5.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.
@@ -0,0 +1,993 @@
1
+ import * as better_auth0 from "better-auth";
2
+ import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
3
+ import * as better_call0 from "better-call";
4
+ import * as zod from "zod";
5
+ import { Organization } from "better-auth/plugins/organization";
6
+ import Stripe from "stripe";
7
+
8
+ //#region src/schema.d.ts
9
+ declare const subscriptions: {
10
+ subscription: {
11
+ fields: {
12
+ plan: {
13
+ type: "string";
14
+ required: true;
15
+ };
16
+ referenceId: {
17
+ type: "string";
18
+ required: true;
19
+ };
20
+ stripeCustomerId: {
21
+ type: "string";
22
+ required: false;
23
+ };
24
+ stripeSubscriptionId: {
25
+ type: "string";
26
+ required: false;
27
+ };
28
+ status: {
29
+ type: "string";
30
+ defaultValue: string;
31
+ };
32
+ periodStart: {
33
+ type: "date";
34
+ required: false;
35
+ };
36
+ periodEnd: {
37
+ type: "date";
38
+ required: false;
39
+ };
40
+ trialStart: {
41
+ type: "date";
42
+ required: false;
43
+ };
44
+ trialEnd: {
45
+ type: "date";
46
+ required: false;
47
+ };
48
+ cancelAtPeriodEnd: {
49
+ type: "boolean";
50
+ required: false;
51
+ defaultValue: false;
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
+ };
65
+ seats: {
66
+ type: "number";
67
+ required: false;
68
+ };
69
+ billingInterval: {
70
+ type: "string";
71
+ required: false;
72
+ };
73
+ stripeScheduleId: {
74
+ type: "string";
75
+ required: false;
76
+ };
77
+ };
78
+ };
79
+ };
80
+ declare const user: {
81
+ user: {
82
+ fields: {
83
+ stripeCustomerId: {
84
+ type: "string";
85
+ required: false;
86
+ };
87
+ };
88
+ };
89
+ };
90
+ declare const organization: {
91
+ organization: {
92
+ fields: {
93
+ stripeCustomerId: {
94
+ type: "string";
95
+ required: false;
96
+ };
97
+ };
98
+ };
99
+ };
100
+ //#endregion
101
+ //#region src/types.d.ts
102
+ type AuthorizeReferenceAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
103
+ type CustomerType = "user" | "organization";
104
+ type WithStripeCustomerId = {
105
+ stripeCustomerId?: string;
106
+ };
107
+ type WithActiveOrganizationId = {
108
+ activeOrganizationId?: string;
109
+ };
110
+ type StripeCtxSession = {
111
+ session: Session & WithActiveOrganizationId;
112
+ user: User & WithStripeCustomerId;
113
+ };
114
+ type StripePlan = {
115
+ /**
116
+ * Monthly price id
117
+ */
118
+ priceId?: string | undefined;
119
+ /**
120
+ * To use lookup key instead of price id
121
+ *
122
+ * https://docs.stripe.com/products-prices/
123
+ * manage-prices#lookup-keys
124
+ */
125
+ lookupKey?: string | undefined;
126
+ /**
127
+ * A yearly discount price id
128
+ *
129
+ * useful when you want to offer a discount for
130
+ * yearly subscription
131
+ */
132
+ annualDiscountPriceId?: string | undefined;
133
+ /**
134
+ * To use lookup key instead of price id
135
+ *
136
+ * https://docs.stripe.com/products-prices/
137
+ * manage-prices#lookup-keys
138
+ */
139
+ annualDiscountLookupKey?: string | undefined;
140
+ /**
141
+ * Plan name
142
+ */
143
+ name: string;
144
+ /**
145
+ * Limits for the plan
146
+ *
147
+ * useful when you want to define plan-specific metadata.
148
+ */
149
+ limits?: Record<string, unknown> | undefined;
150
+ /**
151
+ * Plan group name
152
+ *
153
+ * useful when you want to group plans or
154
+ * when a user can subscribe to multiple plans.
155
+ */
156
+ group?: string | undefined;
157
+ /**
158
+ * Per-seat billing price ID
159
+ *
160
+ * Requires the `organization` plugin. Member changes
161
+ * automatically sync the seat quantity in Stripe.
162
+ */
163
+ seatPriceId?: string | undefined;
164
+ /**
165
+ * Additional line items to include in the checkout session.
166
+ *
167
+ * All line items must use the same billing interval as the base price (e.g. all monthly or all yearly).
168
+ * Stripe does not support mixed-interval subscriptions via Checkout Sessions.
169
+ *
170
+ * @see https://docs.stripe.com/billing/subscriptions/mixed-interval#limitations
171
+ */
172
+ lineItems?: Stripe.Checkout.SessionCreateParams.LineItem[] | undefined;
173
+ /**
174
+ * Free trial days
175
+ */
176
+ freeTrial?: {
177
+ /**
178
+ * Number of days
179
+ */
180
+ days: number;
181
+ /**
182
+ * A function that will be called when the trial
183
+ * starts.
184
+ *
185
+ * @param subscription
186
+ * @returns
187
+ */
188
+ onTrialStart?: (subscription: Subscription) => Promise<void>;
189
+ /**
190
+ * A function that will be called when the trial
191
+ * ends
192
+ *
193
+ * @param subscription - Subscription
194
+ * @returns
195
+ */
196
+ onTrialEnd?: (data: {
197
+ subscription: Subscription;
198
+ }, ctx: GenericEndpointContext) => Promise<void>;
199
+ /**
200
+ * A function that will be called when the trial
201
+ * expired.
202
+ * @param subscription - Subscription
203
+ * @returns
204
+ */
205
+ onTrialExpired?: (subscription: Subscription, ctx: GenericEndpointContext) => Promise<void>;
206
+ } | undefined;
207
+ };
208
+ interface Subscription {
209
+ /**
210
+ * Database identifier
211
+ */
212
+ id: string;
213
+ /**
214
+ * The plan name
215
+ */
216
+ plan: string;
217
+ /**
218
+ * Stripe customer id
219
+ */
220
+ stripeCustomerId?: string | undefined;
221
+ /**
222
+ * Stripe subscription id
223
+ */
224
+ stripeSubscriptionId?: string | undefined;
225
+ /**
226
+ * Trial start date
227
+ */
228
+ trialStart?: Date | undefined;
229
+ /**
230
+ * Trial end date
231
+ */
232
+ trialEnd?: Date | undefined;
233
+ /**
234
+ * Price Id for the subscription
235
+ */
236
+ priceId?: string | undefined;
237
+ /**
238
+ * To what reference id the subscription belongs to
239
+ * @example
240
+ * - userId for a user
241
+ * - workspace id for a saas platform
242
+ * - website id for a hosting platform
243
+ *
244
+ * @default - userId
245
+ */
246
+ referenceId: string;
247
+ /**
248
+ * Subscription status
249
+ */
250
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
251
+ /**
252
+ * The billing cycle start date
253
+ */
254
+ periodStart?: Date | undefined;
255
+ /**
256
+ * The billing cycle end date
257
+ */
258
+ periodEnd?: Date | undefined;
259
+ /**
260
+ * Whether this subscription will (if status=active)
261
+ * or did (if status=canceled) cancel at the end of the current billing period.
262
+ */
263
+ cancelAtPeriodEnd?: boolean | undefined;
264
+ /**
265
+ * If the subscription is scheduled to be canceled,
266
+ * this is the time at which the cancellation will take effect.
267
+ */
268
+ cancelAt?: Date | undefined;
269
+ /**
270
+ * If the subscription has been canceled, this is the time when it was canceled.
271
+ *
272
+ * Note: If the subscription was canceled with `cancel_at_period_end`,
273
+ * this reflects the cancellation request time, not when the subscription actually ends.
274
+ */
275
+ canceledAt?: Date | undefined;
276
+ /**
277
+ * If the subscription has ended, the date the subscription ended.
278
+ */
279
+ endedAt?: Date | undefined;
280
+ /**
281
+ * A field to group subscriptions so you can have multiple subscriptions
282
+ * for one reference id
283
+ */
284
+ groupId?: string | undefined;
285
+ /**
286
+ * Number of seats for the subscription (useful for team plans)
287
+ */
288
+ seats?: number | undefined;
289
+ /**
290
+ * The billing interval for this subscription.
291
+ * Indicates how often the subscription is billed.
292
+ * @see https://docs.stripe.com/api/plans/object#plan_object-interval
293
+ */
294
+ billingInterval?: "day" | "week" | "month" | "year" | undefined;
295
+ /**
296
+ * Stripe Subscription Schedule ID, present when a scheduled
297
+ * plan change is pending for this subscription.
298
+ */
299
+ stripeScheduleId?: string | undefined;
300
+ }
301
+ type SubscriptionOptions = {
302
+ /**
303
+ * Subscription Configuration
304
+ */
305
+ /**
306
+ * List of plan
307
+ */
308
+ plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
309
+ /**
310
+ * Require email verification before a user is allowed to upgrade
311
+ * their subscriptions
312
+ *
313
+ * @default false
314
+ */
315
+ requireEmailVerification?: boolean | undefined;
316
+ /**
317
+ * A callback to run after a user has subscribed to a package
318
+ * @param event - Stripe Event
319
+ * @param subscription - Subscription Data
320
+ * @returns
321
+ */
322
+ onSubscriptionComplete?: ((data: {
323
+ event: Stripe.Event;
324
+ stripeSubscription: Stripe.Subscription;
325
+ subscription: Subscription;
326
+ plan: StripePlan;
327
+ }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
328
+ /**
329
+ * A callback to run after a user is about to cancel their subscription
330
+ * @returns
331
+ */
332
+ onSubscriptionUpdate?: ((data: {
333
+ event: Stripe.Event;
334
+ subscription: Subscription;
335
+ }) => Promise<void>) | undefined;
336
+ /**
337
+ * A callback to run after a user is about to cancel their subscription
338
+ * @returns
339
+ */
340
+ onSubscriptionCancel?: ((data: {
341
+ event?: Stripe.Event;
342
+ subscription: Subscription;
343
+ stripeSubscription: Stripe.Subscription;
344
+ cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
345
+ }) => Promise<void>) | undefined;
346
+ /**
347
+ * A function to check if the reference id is valid
348
+ * and belongs to the user
349
+ *
350
+ * @param data - data containing user, session and referenceId
351
+ * @param ctx - the context object
352
+ * @returns
353
+ */
354
+ authorizeReference?: ((data: {
355
+ user: User & Record<string, any>;
356
+ session: Session & Record<string, any>;
357
+ referenceId: string;
358
+ action: AuthorizeReferenceAction;
359
+ }, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
360
+ /**
361
+ * A callback to run after a user has deleted their subscription
362
+ * @returns
363
+ */
364
+ onSubscriptionDeleted?: ((data: {
365
+ event: Stripe.Event;
366
+ stripeSubscription: Stripe.Subscription;
367
+ subscription: Subscription;
368
+ }) => Promise<void>) | undefined;
369
+ /**
370
+ * A callback to run when a subscription is created
371
+ * @returns
372
+ */
373
+ onSubscriptionCreated?: ((data: {
374
+ event: Stripe.Event;
375
+ stripeSubscription: Stripe.Subscription;
376
+ subscription: Subscription;
377
+ plan: StripePlan;
378
+ }) => Promise<void>) | undefined;
379
+ /**
380
+ * parameters for session create params
381
+ *
382
+ * @param data - data containing user, session and plan
383
+ * @param req - the request object
384
+ * @param ctx - the context object
385
+ */
386
+ getCheckoutSessionParams?: ((data: {
387
+ user: User & Record<string, any>;
388
+ session: Session & Record<string, any>;
389
+ plan: StripePlan;
390
+ subscription: Subscription;
391
+ }, req: GenericEndpointContext["request"], ctx: GenericEndpointContext) => Promise<{
392
+ params?: Stripe.Checkout.SessionCreateParams;
393
+ options?: Stripe.RequestOptions;
394
+ }> | {
395
+ params?: Stripe.Checkout.SessionCreateParams;
396
+ options?: Stripe.RequestOptions;
397
+ }) | undefined;
398
+ };
399
+ interface StripeOptions {
400
+ /**
401
+ * Stripe Client
402
+ */
403
+ stripeClient: Stripe;
404
+ /**
405
+ * Stripe Webhook Secret
406
+ *
407
+ * @description Stripe webhook secret key
408
+ */
409
+ stripeWebhookSecret: string;
410
+ /**
411
+ * Enable customer creation when a user signs up
412
+ */
413
+ createCustomerOnSignUp?: boolean | undefined;
414
+ /**
415
+ * A callback to run after a customer has been created
416
+ * @param customer - Customer Data
417
+ * @param stripeCustomer - Stripe Customer Data
418
+ * @returns
419
+ */
420
+ onCustomerCreate?: ((data: {
421
+ stripeCustomer: Stripe.Customer;
422
+ user: User & WithStripeCustomerId;
423
+ }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
424
+ /**
425
+ * A custom function to get the customer create
426
+ * params
427
+ * @param data - data containing user and session
428
+ * @returns
429
+ */
430
+ getCustomerCreateParams?: ((user: User, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
431
+ /**
432
+ * Subscriptions
433
+ */
434
+ subscription?: ({
435
+ enabled: false;
436
+ } | ({
437
+ enabled: true;
438
+ } & SubscriptionOptions)) | undefined;
439
+ /**
440
+ * Organization Stripe integration
441
+ *
442
+ * Enable organizations to have their own Stripe customer ID
443
+ */
444
+ organization?: {
445
+ /**
446
+ * Enable organization Stripe customer
447
+ */
448
+ enabled: true;
449
+ /**
450
+ * A custom function to get the customer create params
451
+ * for organization customers.
452
+ *
453
+ * @param organization - the organization
454
+ * @param ctx - the context object
455
+ * @returns
456
+ */
457
+ getCustomerCreateParams?: ((organization: Organization, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
458
+ /**
459
+ * A callback to run after an organization customer has been created
460
+ *
461
+ * @param data - data containing stripeCustomer and organization
462
+ * @param ctx - the context object
463
+ * @returns
464
+ */
465
+ onCustomerCreate?: ((data: {
466
+ stripeCustomer: Stripe.Customer;
467
+ organization: Organization & WithStripeCustomerId;
468
+ }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
469
+ } | undefined;
470
+ /**
471
+ * A callback to run after a stripe event is received
472
+ * @param event - Stripe Event
473
+ * @returns
474
+ */
475
+ onEvent?: ((event: Stripe.Event) => Promise<void>) | undefined;
476
+ /**
477
+ * Schema for the stripe plugin
478
+ */
479
+ schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization> | undefined;
480
+ }
481
+ //#endregion
482
+ //#region src/index.d.ts
483
+ declare module "@better-auth/core" {
484
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
485
+ stripe: {
486
+ creator: typeof stripe;
487
+ };
488
+ }
489
+ }
490
+ declare const stripe: <O extends StripeOptions>(options: O) => {
491
+ id: "stripe";
492
+ 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
+ success: boolean;
505
+ }>;
506
+ } & (O["subscription"] extends {
507
+ enabled: true;
508
+ } ? {
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
+ }, {
562
+ url: string;
563
+ redirect: boolean;
564
+ } | {
565
+ redirect: boolean;
566
+ id: string;
567
+ object: "checkout.session";
568
+ adaptive_pricing: Stripe.Checkout.Session.AdaptivePricing | null;
569
+ after_expiration: Stripe.Checkout.Session.AfterExpiration | null;
570
+ allow_promotion_codes: boolean | null;
571
+ amount_subtotal: number | null;
572
+ amount_total: number | null;
573
+ automatic_tax: Stripe.Checkout.Session.AutomaticTax;
574
+ billing_address_collection: Stripe.Checkout.Session.BillingAddressCollection | null;
575
+ branding_settings?: Stripe.Checkout.Session.BrandingSettings;
576
+ cancel_url: string | null;
577
+ client_reference_id: string | null;
578
+ client_secret: string | null;
579
+ collected_information: Stripe.Checkout.Session.CollectedInformation | null;
580
+ consent: Stripe.Checkout.Session.Consent | null;
581
+ consent_collection: Stripe.Checkout.Session.ConsentCollection | null;
582
+ created: number;
583
+ currency: string | null;
584
+ currency_conversion: Stripe.Checkout.Session.CurrencyConversion | null;
585
+ custom_fields: Array<Stripe.Checkout.Session.CustomField>;
586
+ custom_text: Stripe.Checkout.Session.CustomText;
587
+ customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
588
+ customer_account: string | null;
589
+ customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
590
+ customer_details: Stripe.Checkout.Session.CustomerDetails | null;
591
+ customer_email: string | null;
592
+ discounts: Array<Stripe.Checkout.Session.Discount> | null;
593
+ excluded_payment_method_types?: Array<string>;
594
+ expires_at: number;
595
+ invoice: string | Stripe.Invoice | null;
596
+ invoice_creation: Stripe.Checkout.Session.InvoiceCreation | null;
597
+ line_items?: Stripe.ApiList<Stripe.LineItem>;
598
+ livemode: boolean;
599
+ locale: Stripe.Checkout.Session.Locale | null;
600
+ metadata: Stripe.Metadata | null;
601
+ mode: Stripe.Checkout.Session.Mode;
602
+ name_collection?: Stripe.Checkout.Session.NameCollection;
603
+ optional_items?: Array<Stripe.Checkout.Session.OptionalItem> | null;
604
+ origin_context: Stripe.Checkout.Session.OriginContext | null;
605
+ payment_intent: string | Stripe.PaymentIntent | null;
606
+ payment_link: string | Stripe.PaymentLink | null;
607
+ payment_method_collection: Stripe.Checkout.Session.PaymentMethodCollection | null;
608
+ payment_method_configuration_details: Stripe.Checkout.Session.PaymentMethodConfigurationDetails | null;
609
+ payment_method_options: Stripe.Checkout.Session.PaymentMethodOptions | null;
610
+ payment_method_types: Array<string>;
611
+ payment_status: Stripe.Checkout.Session.PaymentStatus;
612
+ permissions: Stripe.Checkout.Session.Permissions | null;
613
+ phone_number_collection?: Stripe.Checkout.Session.PhoneNumberCollection;
614
+ presentment_details?: Stripe.Checkout.Session.PresentmentDetails;
615
+ recovered_from: string | null;
616
+ redirect_on_completion?: Stripe.Checkout.Session.RedirectOnCompletion;
617
+ return_url?: string;
618
+ saved_payment_method_options: Stripe.Checkout.Session.SavedPaymentMethodOptions | null;
619
+ setup_intent: string | Stripe.SetupIntent | null;
620
+ shipping_address_collection: Stripe.Checkout.Session.ShippingAddressCollection | null;
621
+ shipping_cost: Stripe.Checkout.Session.ShippingCost | null;
622
+ shipping_options: Array<Stripe.Checkout.Session.ShippingOption>;
623
+ status: Stripe.Checkout.Session.Status | null;
624
+ submit_type: Stripe.Checkout.Session.SubmitType | null;
625
+ subscription: string | Stripe.Subscription | null;
626
+ success_url: string | null;
627
+ tax_id_collection?: Stripe.Checkout.Session.TaxIdCollection;
628
+ total_details: Stripe.Checkout.Session.TotalDetails | null;
629
+ ui_mode: Stripe.Checkout.Session.UiMode | null;
630
+ url: string | null;
631
+ wallet_options: Stripe.Checkout.Session.WalletOptions | null;
632
+ lastResponse: {
633
+ headers: {
634
+ [key: string]: string;
635
+ };
636
+ requestId: string;
637
+ statusCode: number;
638
+ apiVersion?: string;
639
+ idempotencyKey?: string;
640
+ stripeAccount?: string;
641
+ };
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
+ }, {
688
+ url: string;
689
+ 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
+ };
705
+ };
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
+ };
747
+ };
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
+ }, {
776
+ limits: Record<string, unknown> | undefined;
777
+ priceId: string | undefined;
778
+ id: string;
779
+ plan: string;
780
+ stripeCustomerId?: string | undefined;
781
+ stripeSubscriptionId?: string | undefined;
782
+ trialStart?: Date | undefined;
783
+ trialEnd?: Date | undefined;
784
+ referenceId: string;
785
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
786
+ periodStart?: Date | undefined;
787
+ periodEnd?: Date | undefined;
788
+ cancelAtPeriodEnd?: boolean | undefined;
789
+ cancelAt?: Date | undefined;
790
+ canceledAt?: Date | undefined;
791
+ endedAt?: Date | undefined;
792
+ groupId?: string | undefined;
793
+ seats?: number | undefined;
794
+ billingInterval?: "day" | "week" | "month" | "year" | undefined;
795
+ 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
+ };
804
+ };
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
+ };
823
+ };
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
+ }, {
852
+ url: string;
853
+ redirect: boolean;
854
+ }>;
855
+ } : {});
856
+ init(ctx: better_auth0.AuthContext): {
857
+ options: {
858
+ databaseHooks: {
859
+ user: {
860
+ create: {
861
+ after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
862
+ };
863
+ update: {
864
+ after(user: User & WithStripeCustomerId, ctx: better_auth0.GenericEndpointContext | null): Promise<void>;
865
+ };
866
+ };
867
+ };
868
+ };
869
+ } | undefined;
870
+ schema: {
871
+ user: {
872
+ fields: {
873
+ stripeCustomerId: {
874
+ type: "string";
875
+ required: false;
876
+ };
877
+ };
878
+ };
879
+ } & (O["subscription"] extends {
880
+ enabled: true;
881
+ } ? {
882
+ subscription: {
883
+ fields: {
884
+ plan: {
885
+ type: "string";
886
+ required: true;
887
+ };
888
+ referenceId: {
889
+ type: "string";
890
+ required: true;
891
+ };
892
+ stripeCustomerId: {
893
+ type: "string";
894
+ required: false;
895
+ };
896
+ stripeSubscriptionId: {
897
+ type: "string";
898
+ required: false;
899
+ };
900
+ status: {
901
+ type: "string";
902
+ defaultValue: string;
903
+ };
904
+ periodStart: {
905
+ type: "date";
906
+ required: false;
907
+ };
908
+ periodEnd: {
909
+ type: "date";
910
+ required: false;
911
+ };
912
+ trialStart: {
913
+ type: "date";
914
+ required: false;
915
+ };
916
+ trialEnd: {
917
+ type: "date";
918
+ required: false;
919
+ };
920
+ cancelAtPeriodEnd: {
921
+ type: "boolean";
922
+ required: false;
923
+ defaultValue: false;
924
+ };
925
+ cancelAt: {
926
+ type: "date";
927
+ required: false;
928
+ };
929
+ canceledAt: {
930
+ type: "date";
931
+ required: false;
932
+ };
933
+ endedAt: {
934
+ type: "date";
935
+ required: false;
936
+ };
937
+ seats: {
938
+ type: "number";
939
+ required: false;
940
+ };
941
+ billingInterval: {
942
+ type: "string";
943
+ required: false;
944
+ };
945
+ stripeScheduleId: {
946
+ type: "string";
947
+ required: false;
948
+ };
949
+ };
950
+ };
951
+ } : {}) & (O["organization"] extends {
952
+ enabled: true;
953
+ } ? {
954
+ organization: {
955
+ fields: {
956
+ stripeCustomerId: {
957
+ type: "string";
958
+ required: false;
959
+ };
960
+ };
961
+ };
962
+ } : {});
963
+ options: NoInfer<O>;
964
+ $ERROR_CODES: {
965
+ UNAUTHORIZED: better_auth0.RawError<"UNAUTHORIZED">;
966
+ INVALID_REQUEST_BODY: better_auth0.RawError<"INVALID_REQUEST_BODY">;
967
+ SUBSCRIPTION_NOT_FOUND: better_auth0.RawError<"SUBSCRIPTION_NOT_FOUND">;
968
+ SUBSCRIPTION_PLAN_NOT_FOUND: better_auth0.RawError<"SUBSCRIPTION_PLAN_NOT_FOUND">;
969
+ ALREADY_SUBSCRIBED_PLAN: better_auth0.RawError<"ALREADY_SUBSCRIBED_PLAN">;
970
+ REFERENCE_ID_NOT_ALLOWED: better_auth0.RawError<"REFERENCE_ID_NOT_ALLOWED">;
971
+ CUSTOMER_NOT_FOUND: better_auth0.RawError<"CUSTOMER_NOT_FOUND">;
972
+ UNABLE_TO_CREATE_CUSTOMER: better_auth0.RawError<"UNABLE_TO_CREATE_CUSTOMER">;
973
+ UNABLE_TO_CREATE_BILLING_PORTAL: better_auth0.RawError<"UNABLE_TO_CREATE_BILLING_PORTAL">;
974
+ STRIPE_SIGNATURE_NOT_FOUND: better_auth0.RawError<"STRIPE_SIGNATURE_NOT_FOUND">;
975
+ STRIPE_WEBHOOK_SECRET_NOT_FOUND: better_auth0.RawError<"STRIPE_WEBHOOK_SECRET_NOT_FOUND">;
976
+ STRIPE_WEBHOOK_ERROR: better_auth0.RawError<"STRIPE_WEBHOOK_ERROR">;
977
+ FAILED_TO_CONSTRUCT_STRIPE_EVENT: better_auth0.RawError<"FAILED_TO_CONSTRUCT_STRIPE_EVENT">;
978
+ FAILED_TO_FETCH_PLANS: better_auth0.RawError<"FAILED_TO_FETCH_PLANS">;
979
+ EMAIL_VERIFICATION_REQUIRED: better_auth0.RawError<"EMAIL_VERIFICATION_REQUIRED">;
980
+ SUBSCRIPTION_NOT_ACTIVE: better_auth0.RawError<"SUBSCRIPTION_NOT_ACTIVE">;
981
+ SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: better_auth0.RawError<"SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION">;
982
+ SUBSCRIPTION_NOT_PENDING_CHANGE: better_auth0.RawError<"SUBSCRIPTION_NOT_PENDING_CHANGE">;
983
+ ORGANIZATION_NOT_FOUND: better_auth0.RawError<"ORGANIZATION_NOT_FOUND">;
984
+ ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: better_auth0.RawError<"ORGANIZATION_SUBSCRIPTION_NOT_ENABLED">;
985
+ AUTHORIZE_REFERENCE_REQUIRED: better_auth0.RawError<"AUTHORIZE_REFERENCE_REQUIRED">;
986
+ ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: better_auth0.RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
987
+ ORGANIZATION_REFERENCE_ID_REQUIRED: better_auth0.RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
988
+ };
989
+ };
990
+ type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
991
+ //#endregion
992
+ 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