@better-auth/stripe 1.2.0-beta.18

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,884 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { User, Session, GenericEndpointContext } from 'better-auth';
3
+ import * as better_call from 'better-call';
4
+ import Stripe from 'stripe';
5
+ import { z } from 'zod';
6
+ import { APIError } from 'better-auth/api';
7
+
8
+ type Plan = {
9
+ /**
10
+ * Monthly price id
11
+ */
12
+ priceId?: string;
13
+ /**
14
+ * To use lookup key instead of price id
15
+ *
16
+ * https://docs.stripe.com/products-prices/
17
+ * manage-prices#lookup-keys
18
+ */
19
+ lookupKey?: string;
20
+ /**
21
+ * A yearly discount price id
22
+ *
23
+ * useful when you want to offer a discount for
24
+ * yearly subscription
25
+ */
26
+ annualDiscountPriceId?: string;
27
+ /**
28
+ * Plan name
29
+ */
30
+ name: string;
31
+ /**
32
+ * Limits for the plan
33
+ */
34
+ limits?: Record<string, number>;
35
+ /**
36
+ * Plan group name
37
+ *
38
+ * useful when you want to group plans or
39
+ * when a user can subscribe to multiple plans.
40
+ */
41
+ group?: string;
42
+ /**
43
+ * Free trial days
44
+ */
45
+ freeTrial?: {
46
+ /**
47
+ * Number of days
48
+ */
49
+ days: number;
50
+ /**
51
+ * Only available for new users or users without existing subscription
52
+ *
53
+ * @default true
54
+ */
55
+ forNewUsersOnly?: boolean;
56
+ /**
57
+ * A function that will be called when the trial
58
+ * starts.
59
+ *
60
+ * @param subscription
61
+ * @returns
62
+ */
63
+ onTrialStart?: (subscription: Subscription) => Promise<void>;
64
+ /**
65
+ * A function that will be called when the trial
66
+ * ends
67
+ *
68
+ * @param subscription - Subscription
69
+ * @returns
70
+ */
71
+ onTrialEnd?: (data: {
72
+ subscription: Subscription;
73
+ user: User & Record<string, any>;
74
+ }, request?: Request) => Promise<void>;
75
+ /**
76
+ * A function that will be called when the trial
77
+ * expired.
78
+ * @param subscription - Subscription
79
+ * @returns
80
+ */
81
+ onTrialExpired?: (subscription: Subscription) => Promise<void>;
82
+ };
83
+ };
84
+ interface Subscription {
85
+ /**
86
+ * Database identifier
87
+ */
88
+ id: string;
89
+ /**
90
+ * The plan name
91
+ */
92
+ plan: string;
93
+ /**
94
+ * Stripe customer id
95
+ */
96
+ stripeCustomerId?: string;
97
+ /**
98
+ * Stripe subscription id
99
+ */
100
+ stripeSubscriptionId?: string;
101
+ /**
102
+ * Trial start date
103
+ */
104
+ trialStart?: Date;
105
+ /**
106
+ * Trial end date
107
+ */
108
+ trialEnd?: Date;
109
+ /**
110
+ * Price Id for the subscription
111
+ */
112
+ priceId?: string;
113
+ /**
114
+ * To what reference id the subscription belongs to
115
+ * @example
116
+ * - userId for a user
117
+ * - workspace id for a saas platform
118
+ * - website id for a hosting platform
119
+ *
120
+ * @default - userId
121
+ */
122
+ referenceId: string;
123
+ /**
124
+ * Subscription status
125
+ */
126
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
127
+ /**
128
+ * The billing cycle start date
129
+ */
130
+ periodStart?: Date;
131
+ /**
132
+ * The billing cycle end date
133
+ */
134
+ periodEnd?: Date;
135
+ /**
136
+ * Cancel at period end
137
+ */
138
+ cancelAtPeriodEnd?: boolean;
139
+ /**
140
+ * A field to group subscriptions so you can have multiple subscriptions
141
+ * for one reference id
142
+ */
143
+ groupId?: string;
144
+ /**
145
+ * Number of seats for the subscription (useful for team plans)
146
+ */
147
+ seats?: number;
148
+ }
149
+ interface StripeOptions {
150
+ /**
151
+ * Stripe Client
152
+ */
153
+ stripeClient: Stripe;
154
+ /**
155
+ * Stripe Webhook Secret
156
+ *
157
+ * @description Stripe webhook secret key
158
+ */
159
+ stripeWebhookSecret: string;
160
+ /**
161
+ * Enable customer creation when a user signs up
162
+ */
163
+ createCustomerOnSignUp?: boolean;
164
+ /**
165
+ * A callback to run after a customer has been created
166
+ * @param customer - Customer Data
167
+ * @param stripeCustomer - Stripe Customer Data
168
+ * @returns
169
+ */
170
+ onCustomerCreate?: (data: {
171
+ customer: Customer;
172
+ stripeCustomer: Stripe.Customer;
173
+ user: User;
174
+ }, request?: Request) => Promise<void>;
175
+ /**
176
+ * A custom function to get the customer create
177
+ * params
178
+ * @param data - data containing user and session
179
+ * @returns
180
+ */
181
+ getCustomerCreateParams?: (data: {
182
+ user: User;
183
+ session: Session;
184
+ }, request?: Request) => Promise<{}>;
185
+ /**
186
+ * Subscriptions
187
+ */
188
+ subscription?: {
189
+ enabled: boolean;
190
+ /**
191
+ * Subscription Configuration
192
+ */
193
+ /**
194
+ * List of plan
195
+ */
196
+ plans: Plan[] | (() => Promise<Plan[]>);
197
+ /**
198
+ * Require email verification before a user is allowed to upgrade
199
+ * their subscriptions
200
+ *
201
+ * @default false
202
+ */
203
+ requireEmailVerification?: boolean;
204
+ /**
205
+ * A callback to run after a user has subscribed to a package
206
+ * @param event - Stripe Event
207
+ * @param subscription - Subscription Data
208
+ * @returns
209
+ */
210
+ onSubscriptionComplete?: (data: {
211
+ event: Stripe.Event;
212
+ stripeSubscription: Stripe.Subscription;
213
+ subscription: Subscription;
214
+ plan: Plan;
215
+ }, request?: Request) => Promise<void>;
216
+ /**
217
+ * A callback to run after a user is about to cancel their subscription
218
+ * @returns
219
+ */
220
+ onSubscriptionUpdate?: (data: {
221
+ event: Stripe.Event;
222
+ subscription: Subscription;
223
+ }) => Promise<void>;
224
+ /**
225
+ * A callback to run after a user is about to cancel their subscription
226
+ * @returns
227
+ */
228
+ onSubscriptionCancel?: (data: {
229
+ event: Stripe.Event;
230
+ subscription: Subscription;
231
+ stripeSubscription: Stripe.Subscription;
232
+ cancellationDetails?: Stripe.Subscription.CancellationDetails;
233
+ }) => Promise<void>;
234
+ /**
235
+ * A function to check if the reference id is valid
236
+ * and belongs to the user
237
+ *
238
+ * @param data - data containing user, session and referenceId
239
+ * @param request - Request Object
240
+ * @returns
241
+ */
242
+ authorizeReference?: (data: {
243
+ user: User & Record<string, any>;
244
+ session: Session & Record<string, any>;
245
+ referenceId: string;
246
+ action: "upgrade-subscription" | "list-subscription" | "cancel-subscription";
247
+ }, request?: Request) => Promise<boolean>;
248
+ /**
249
+ * A callback to run after a user has deleted their subscription
250
+ * @returns
251
+ */
252
+ onSubscriptionDeleted?: (data: {
253
+ event: Stripe.Event;
254
+ stripeSubscription: Stripe.Subscription;
255
+ subscription: Subscription;
256
+ }) => Promise<void>;
257
+ /**
258
+ * parameters for session create params
259
+ *
260
+ * @param data - data containing user, session and plan
261
+ * @param request - Request Object
262
+ */
263
+ getCheckoutSessionParams?: (data: {
264
+ user: User & Record<string, any>;
265
+ session: Session & Record<string, any>;
266
+ plan: Plan;
267
+ subscription: Subscription;
268
+ }, request?: Request) => Promise<{
269
+ params?: Stripe.Checkout.SessionCreateParams;
270
+ options?: Stripe.RequestOptions;
271
+ }> | {
272
+ params?: Stripe.Checkout.SessionCreateParams;
273
+ options?: Stripe.RequestOptions;
274
+ };
275
+ /**
276
+ * Enable organization subscription
277
+ */
278
+ organization?: {
279
+ enabled: boolean;
280
+ };
281
+ };
282
+ onEvent?: (event: Stripe.Event) => Promise<void>;
283
+ }
284
+ interface Customer {
285
+ id: string;
286
+ stripeCustomerId?: string;
287
+ userId: string;
288
+ createdAt: Date;
289
+ updatedAt: Date;
290
+ }
291
+
292
+ declare const stripe: <O extends StripeOptions>(options: O) => {
293
+ id: "stripe";
294
+ endpoints: {
295
+ stripeWebhook: {
296
+ <C extends [({
297
+ body?: undefined;
298
+ method?: "POST" | undefined;
299
+ query?: Record<string, any> | undefined;
300
+ params?: Record<string, any> | undefined;
301
+ request?: Request | undefined;
302
+ headers?: HeadersInit | undefined;
303
+ asResponse?: boolean | undefined;
304
+ returnHeaders?: boolean | undefined;
305
+ use?: better_call.Middleware[] | undefined;
306
+ path?: string | undefined;
307
+ } | undefined)?]>(...inputCtx: C): Promise<C extends [{
308
+ asResponse: true;
309
+ }] ? Response : C extends [{
310
+ returnHeaders: true;
311
+ }] ? {
312
+ headers: Headers;
313
+ response: {
314
+ success: boolean;
315
+ };
316
+ } : {
317
+ success: boolean;
318
+ }>;
319
+ options: {
320
+ method: "POST";
321
+ metadata: {
322
+ isAction: boolean;
323
+ };
324
+ cloneRequest: true;
325
+ } & {
326
+ use: any[];
327
+ };
328
+ path: "/stripe/webhook";
329
+ };
330
+ } & (O["subscription"] extends {
331
+ enabled: boolean;
332
+ } ? {
333
+ readonly upgradeSubscription: {
334
+ <C extends [{
335
+ body: {
336
+ plan: string;
337
+ metadata?: Record<string, any> | undefined;
338
+ referenceId?: string | undefined;
339
+ seats?: number | undefined;
340
+ uiMode?: "embedded" | "hosted" | undefined;
341
+ successUrl?: string | undefined;
342
+ cancelUrl?: string | undefined;
343
+ returnUrl?: string | undefined;
344
+ withoutTrial?: boolean | undefined;
345
+ disableRedirect?: boolean | undefined;
346
+ };
347
+ method?: "POST" | undefined;
348
+ query?: Record<string, any> | undefined;
349
+ params?: Record<string, any> | undefined;
350
+ request?: Request | undefined;
351
+ headers?: HeadersInit | undefined;
352
+ asResponse?: boolean | undefined;
353
+ returnHeaders?: boolean | undefined;
354
+ use?: better_call.Middleware[] | undefined;
355
+ path?: string | undefined;
356
+ }]>(...inputCtx: C): Promise<C extends [{
357
+ asResponse: true;
358
+ }] ? Response : C extends [{
359
+ returnHeaders: true;
360
+ }] ? {
361
+ headers: Headers;
362
+ response: {
363
+ url: string;
364
+ redirect: boolean;
365
+ } | {
366
+ redirect: boolean;
367
+ id: string;
368
+ object: "checkout.session";
369
+ adaptive_pricing: Stripe.Checkout.Session.AdaptivePricing | null;
370
+ after_expiration: Stripe.Checkout.Session.AfterExpiration | null;
371
+ allow_promotion_codes: boolean | null;
372
+ amount_subtotal: number | null;
373
+ amount_total: number | null;
374
+ automatic_tax: Stripe.Checkout.Session.AutomaticTax;
375
+ billing_address_collection: Stripe.Checkout.Session.BillingAddressCollection | null;
376
+ cancel_url: string | null;
377
+ client_reference_id: string | null;
378
+ client_secret: string | null;
379
+ collected_information?: Stripe.Checkout.Session.CollectedInformation | null;
380
+ consent: Stripe.Checkout.Session.Consent | null;
381
+ consent_collection: Stripe.Checkout.Session.ConsentCollection | null;
382
+ created: number;
383
+ currency: string | null;
384
+ currency_conversion: Stripe.Checkout.Session.CurrencyConversion | null;
385
+ custom_fields: Array<Stripe.Checkout.Session.CustomField>;
386
+ custom_text: Stripe.Checkout.Session.CustomText;
387
+ customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
388
+ customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
389
+ customer_details: Stripe.Checkout.Session.CustomerDetails | null;
390
+ customer_email: string | null;
391
+ discounts: Array<Stripe.Checkout.Session.Discount> | null;
392
+ expires_at: number;
393
+ invoice: string | Stripe.Invoice | null;
394
+ invoice_creation: Stripe.Checkout.Session.InvoiceCreation | null;
395
+ line_items?: Stripe.ApiList<Stripe.LineItem>;
396
+ livemode: boolean;
397
+ locale: Stripe.Checkout.Session.Locale | null;
398
+ metadata: Stripe.Metadata | null;
399
+ mode: Stripe.Checkout.Session.Mode;
400
+ payment_intent: string | Stripe.PaymentIntent | null;
401
+ payment_link: string | Stripe.PaymentLink | null;
402
+ payment_method_collection: Stripe.Checkout.Session.PaymentMethodCollection | null;
403
+ payment_method_configuration_details: Stripe.Checkout.Session.PaymentMethodConfigurationDetails | null;
404
+ payment_method_options: Stripe.Checkout.Session.PaymentMethodOptions | null;
405
+ payment_method_types: Array<string>;
406
+ payment_status: Stripe.Checkout.Session.PaymentStatus;
407
+ phone_number_collection?: Stripe.Checkout.Session.PhoneNumberCollection;
408
+ recovered_from: string | null;
409
+ redirect_on_completion?: Stripe.Checkout.Session.RedirectOnCompletion;
410
+ return_url?: string;
411
+ saved_payment_method_options: Stripe.Checkout.Session.SavedPaymentMethodOptions | null;
412
+ setup_intent: string | Stripe.SetupIntent | null;
413
+ shipping_address_collection: Stripe.Checkout.Session.ShippingAddressCollection | null;
414
+ shipping_cost: Stripe.Checkout.Session.ShippingCost | null;
415
+ shipping_details: Stripe.Checkout.Session.ShippingDetails | null;
416
+ shipping_options: Array<Stripe.Checkout.Session.ShippingOption>;
417
+ status: Stripe.Checkout.Session.Status | null;
418
+ submit_type: Stripe.Checkout.Session.SubmitType | null;
419
+ subscription: string | Stripe.Subscription | null;
420
+ success_url: string | null;
421
+ tax_id_collection?: Stripe.Checkout.Session.TaxIdCollection;
422
+ total_details: Stripe.Checkout.Session.TotalDetails | null;
423
+ ui_mode: Stripe.Checkout.Session.UiMode | null;
424
+ url: string | null;
425
+ lastResponse: {
426
+ headers: {
427
+ [key: string]: string;
428
+ };
429
+ requestId: string;
430
+ statusCode: number;
431
+ apiVersion?: string;
432
+ idempotencyKey?: string;
433
+ stripeAccount?: string;
434
+ };
435
+ };
436
+ } : {
437
+ url: string;
438
+ redirect: boolean;
439
+ } | {
440
+ redirect: boolean;
441
+ id: string;
442
+ object: "checkout.session";
443
+ adaptive_pricing: Stripe.Checkout.Session.AdaptivePricing | null;
444
+ after_expiration: Stripe.Checkout.Session.AfterExpiration | null;
445
+ allow_promotion_codes: boolean | null;
446
+ amount_subtotal: number | null;
447
+ amount_total: number | null;
448
+ automatic_tax: Stripe.Checkout.Session.AutomaticTax;
449
+ billing_address_collection: Stripe.Checkout.Session.BillingAddressCollection | null;
450
+ cancel_url: string | null;
451
+ client_reference_id: string | null;
452
+ client_secret: string | null;
453
+ collected_information?: Stripe.Checkout.Session.CollectedInformation | null;
454
+ consent: Stripe.Checkout.Session.Consent | null;
455
+ consent_collection: Stripe.Checkout.Session.ConsentCollection | null;
456
+ created: number;
457
+ currency: string | null;
458
+ currency_conversion: Stripe.Checkout.Session.CurrencyConversion | null;
459
+ custom_fields: Array<Stripe.Checkout.Session.CustomField>;
460
+ custom_text: Stripe.Checkout.Session.CustomText;
461
+ customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
462
+ customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
463
+ customer_details: Stripe.Checkout.Session.CustomerDetails | null;
464
+ customer_email: string | null;
465
+ discounts: Array<Stripe.Checkout.Session.Discount> | null;
466
+ expires_at: number;
467
+ invoice: string | Stripe.Invoice | null;
468
+ invoice_creation: Stripe.Checkout.Session.InvoiceCreation | null;
469
+ line_items?: Stripe.ApiList<Stripe.LineItem>;
470
+ livemode: boolean;
471
+ locale: Stripe.Checkout.Session.Locale | null;
472
+ metadata: Stripe.Metadata | null;
473
+ mode: Stripe.Checkout.Session.Mode;
474
+ payment_intent: string | Stripe.PaymentIntent | null;
475
+ payment_link: string | Stripe.PaymentLink | null;
476
+ payment_method_collection: Stripe.Checkout.Session.PaymentMethodCollection | null;
477
+ payment_method_configuration_details: Stripe.Checkout.Session.PaymentMethodConfigurationDetails | null;
478
+ payment_method_options: Stripe.Checkout.Session.PaymentMethodOptions | null;
479
+ payment_method_types: Array<string>;
480
+ payment_status: Stripe.Checkout.Session.PaymentStatus;
481
+ phone_number_collection?: Stripe.Checkout.Session.PhoneNumberCollection;
482
+ recovered_from: string | null;
483
+ redirect_on_completion?: Stripe.Checkout.Session.RedirectOnCompletion;
484
+ return_url?: string;
485
+ saved_payment_method_options: Stripe.Checkout.Session.SavedPaymentMethodOptions | null;
486
+ setup_intent: string | Stripe.SetupIntent | null;
487
+ shipping_address_collection: Stripe.Checkout.Session.ShippingAddressCollection | null;
488
+ shipping_cost: Stripe.Checkout.Session.ShippingCost | null;
489
+ shipping_details: Stripe.Checkout.Session.ShippingDetails | null;
490
+ shipping_options: Array<Stripe.Checkout.Session.ShippingOption>;
491
+ status: Stripe.Checkout.Session.Status | null;
492
+ submit_type: Stripe.Checkout.Session.SubmitType | null;
493
+ subscription: string | Stripe.Subscription | null;
494
+ success_url: string | null;
495
+ tax_id_collection?: Stripe.Checkout.Session.TaxIdCollection;
496
+ total_details: Stripe.Checkout.Session.TotalDetails | null;
497
+ ui_mode: Stripe.Checkout.Session.UiMode | null;
498
+ url: string | null;
499
+ lastResponse: {
500
+ headers: {
501
+ [key: string]: string;
502
+ };
503
+ requestId: string;
504
+ statusCode: number;
505
+ apiVersion?: string;
506
+ idempotencyKey?: string;
507
+ stripeAccount?: string;
508
+ };
509
+ }>;
510
+ options: {
511
+ method: "POST";
512
+ body: z.ZodObject<{
513
+ plan: z.ZodString;
514
+ referenceId: z.ZodOptional<z.ZodString>;
515
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
516
+ seats: z.ZodOptional<z.ZodNumber>;
517
+ uiMode: z.ZodDefault<z.ZodEnum<["embedded", "hosted"]>>;
518
+ successUrl: z.ZodDefault<z.ZodString>;
519
+ cancelUrl: z.ZodDefault<z.ZodString>;
520
+ returnUrl: z.ZodOptional<z.ZodString>;
521
+ withoutTrial: z.ZodOptional<z.ZodBoolean>;
522
+ disableRedirect: z.ZodDefault<z.ZodBoolean>;
523
+ }, "strip", z.ZodTypeAny, {
524
+ plan: string;
525
+ uiMode: "embedded" | "hosted";
526
+ successUrl: string;
527
+ cancelUrl: string;
528
+ disableRedirect: boolean;
529
+ metadata?: Record<string, any> | undefined;
530
+ referenceId?: string | undefined;
531
+ seats?: number | undefined;
532
+ returnUrl?: string | undefined;
533
+ withoutTrial?: boolean | undefined;
534
+ }, {
535
+ plan: string;
536
+ metadata?: Record<string, any> | undefined;
537
+ referenceId?: string | undefined;
538
+ seats?: number | undefined;
539
+ uiMode?: "embedded" | "hosted" | undefined;
540
+ successUrl?: string | undefined;
541
+ cancelUrl?: string | undefined;
542
+ returnUrl?: string | undefined;
543
+ withoutTrial?: boolean | undefined;
544
+ disableRedirect?: boolean | undefined;
545
+ }>;
546
+ use: (((inputContext: {
547
+ body?: any;
548
+ query?: Record<string, any> | undefined;
549
+ request?: Request | undefined;
550
+ headers?: Headers | undefined;
551
+ asResponse?: boolean | undefined;
552
+ returnHeaders?: boolean | undefined;
553
+ use?: better_call.Middleware[] | undefined;
554
+ }) => Promise<{
555
+ session: {
556
+ session: Record<string, any> & {
557
+ id: string;
558
+ createdAt: Date;
559
+ updatedAt: Date;
560
+ userId: string;
561
+ expiresAt: Date;
562
+ token: string;
563
+ ipAddress?: string | null | undefined;
564
+ userAgent?: string | null | undefined;
565
+ };
566
+ user: Record<string, any> & {
567
+ id: string;
568
+ name: string;
569
+ email: string;
570
+ emailVerified: boolean;
571
+ createdAt: Date;
572
+ updatedAt: Date;
573
+ image?: string | null | undefined;
574
+ };
575
+ };
576
+ }>) | ((inputContext: {
577
+ body?: any;
578
+ query?: Record<string, any> | undefined;
579
+ request?: Request | undefined;
580
+ headers?: Headers | undefined;
581
+ asResponse?: boolean | undefined;
582
+ returnHeaders?: boolean | undefined;
583
+ use?: better_call.Middleware[] | undefined;
584
+ }) => Promise<void>))[];
585
+ } & {
586
+ use: any[];
587
+ };
588
+ path: "/subscription/upgrade";
589
+ };
590
+ readonly cancelSubscription: {
591
+ <C extends [{
592
+ body: {
593
+ returnUrl: string;
594
+ referenceId?: string | undefined;
595
+ };
596
+ method?: "POST" | undefined;
597
+ query?: Record<string, any> | undefined;
598
+ params?: Record<string, any> | undefined;
599
+ request?: Request | undefined;
600
+ headers?: HeadersInit | undefined;
601
+ asResponse?: boolean | undefined;
602
+ returnHeaders?: boolean | undefined;
603
+ use?: better_call.Middleware[] | undefined;
604
+ path?: string | undefined;
605
+ }]>(...inputCtx: C): Promise<C extends [{
606
+ asResponse: true;
607
+ }] ? Response : C extends [{
608
+ returnHeaders: true;
609
+ }] ? {
610
+ headers: Headers;
611
+ response: {
612
+ url: string;
613
+ redirect: boolean;
614
+ };
615
+ } : {
616
+ url: string;
617
+ redirect: boolean;
618
+ }>;
619
+ options: {
620
+ method: "POST";
621
+ body: z.ZodObject<{
622
+ referenceId: z.ZodOptional<z.ZodString>;
623
+ returnUrl: z.ZodString;
624
+ }, "strip", z.ZodTypeAny, {
625
+ returnUrl: string;
626
+ referenceId?: string | undefined;
627
+ }, {
628
+ returnUrl: string;
629
+ referenceId?: string | undefined;
630
+ }>;
631
+ use: (((inputContext: {
632
+ body?: any;
633
+ query?: Record<string, any> | undefined;
634
+ request?: Request | undefined;
635
+ headers?: Headers | undefined;
636
+ asResponse?: boolean | undefined;
637
+ returnHeaders?: boolean | undefined;
638
+ use?: better_call.Middleware[] | undefined;
639
+ }) => Promise<{
640
+ session: {
641
+ session: Record<string, any> & {
642
+ id: string;
643
+ createdAt: Date;
644
+ updatedAt: Date;
645
+ userId: string;
646
+ expiresAt: Date;
647
+ token: string;
648
+ ipAddress?: string | null | undefined;
649
+ userAgent?: string | null | undefined;
650
+ };
651
+ user: Record<string, any> & {
652
+ id: string;
653
+ name: string;
654
+ email: string;
655
+ emailVerified: boolean;
656
+ createdAt: Date;
657
+ updatedAt: Date;
658
+ image?: string | null | undefined;
659
+ };
660
+ };
661
+ }>) | ((inputContext: {
662
+ body?: any;
663
+ query?: Record<string, any> | undefined;
664
+ request?: Request | undefined;
665
+ headers?: Headers | undefined;
666
+ asResponse?: boolean | undefined;
667
+ returnHeaders?: boolean | undefined;
668
+ use?: better_call.Middleware[] | undefined;
669
+ }) => Promise<void>))[];
670
+ } & {
671
+ use: any[];
672
+ };
673
+ path: "/subscription/cancel";
674
+ };
675
+ readonly listActiveSubscriptions: {
676
+ <C extends [({
677
+ body?: undefined;
678
+ method?: "GET" | undefined;
679
+ query?: {
680
+ referenceId?: string | undefined;
681
+ } | undefined;
682
+ params?: Record<string, any> | undefined;
683
+ request?: Request | undefined;
684
+ headers?: HeadersInit | undefined;
685
+ asResponse?: boolean | undefined;
686
+ returnHeaders?: boolean | undefined;
687
+ use?: better_call.Middleware[] | undefined;
688
+ path?: string | undefined;
689
+ } | undefined)?]>(...inputCtx: C): Promise<C extends [{
690
+ asResponse: true;
691
+ }] ? Response : C extends [{
692
+ returnHeaders: true;
693
+ }] ? {
694
+ headers: Headers;
695
+ response: {
696
+ limits: Record<string, number> | undefined;
697
+ id: string;
698
+ plan: string;
699
+ stripeCustomerId?: string;
700
+ stripeSubscriptionId?: string;
701
+ trialStart?: Date;
702
+ trialEnd?: Date;
703
+ priceId?: string;
704
+ referenceId: string;
705
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
706
+ periodStart?: Date;
707
+ periodEnd?: Date;
708
+ cancelAtPeriodEnd?: boolean;
709
+ groupId?: string;
710
+ seats?: number;
711
+ }[];
712
+ } : {
713
+ limits: Record<string, number> | undefined;
714
+ id: string;
715
+ plan: string;
716
+ stripeCustomerId?: string;
717
+ stripeSubscriptionId?: string;
718
+ trialStart?: Date;
719
+ trialEnd?: Date;
720
+ priceId?: string;
721
+ referenceId: string;
722
+ status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
723
+ periodStart?: Date;
724
+ periodEnd?: Date;
725
+ cancelAtPeriodEnd?: boolean;
726
+ groupId?: string;
727
+ seats?: number;
728
+ }[]>;
729
+ options: {
730
+ method: "GET";
731
+ query: z.ZodOptional<z.ZodObject<{
732
+ referenceId: z.ZodOptional<z.ZodString>;
733
+ }, "strip", z.ZodTypeAny, {
734
+ referenceId?: string | undefined;
735
+ }, {
736
+ referenceId?: string | undefined;
737
+ }>>;
738
+ use: (((inputContext: {
739
+ body?: any;
740
+ query?: Record<string, any> | undefined;
741
+ request?: Request | undefined;
742
+ headers?: Headers | undefined;
743
+ asResponse?: boolean | undefined;
744
+ returnHeaders?: boolean | undefined;
745
+ use?: better_call.Middleware[] | undefined;
746
+ }) => Promise<{
747
+ session: {
748
+ session: Record<string, any> & {
749
+ id: string;
750
+ createdAt: Date;
751
+ updatedAt: Date;
752
+ userId: string;
753
+ expiresAt: Date;
754
+ token: string;
755
+ ipAddress?: string | null | undefined;
756
+ userAgent?: string | null | undefined;
757
+ };
758
+ user: Record<string, any> & {
759
+ id: string;
760
+ name: string;
761
+ email: string;
762
+ emailVerified: boolean;
763
+ createdAt: Date;
764
+ updatedAt: Date;
765
+ image?: string | null | undefined;
766
+ };
767
+ };
768
+ }>) | ((inputContext: {
769
+ body?: any;
770
+ query?: Record<string, any> | undefined;
771
+ request?: Request | undefined;
772
+ headers?: Headers | undefined;
773
+ asResponse?: boolean | undefined;
774
+ returnHeaders?: boolean | undefined;
775
+ use?: better_call.Middleware[] | undefined;
776
+ }) => Promise<void>))[];
777
+ } & {
778
+ use: any[];
779
+ };
780
+ path: "/subscription/list";
781
+ };
782
+ readonly subscriptionSuccess: {
783
+ <C extends [({
784
+ body?: undefined;
785
+ method?: "GET" | undefined;
786
+ query?: Record<string, any> | undefined;
787
+ params?: Record<string, any> | undefined;
788
+ request?: Request | undefined;
789
+ headers?: HeadersInit | undefined;
790
+ asResponse?: boolean | undefined;
791
+ returnHeaders?: boolean | undefined;
792
+ use?: better_call.Middleware[] | undefined;
793
+ path?: string | undefined;
794
+ } | undefined)?]>(...inputCtx: C): Promise<C extends [{
795
+ asResponse: true;
796
+ }] ? Response : C extends [{
797
+ returnHeaders: true;
798
+ }] ? {
799
+ headers: Headers;
800
+ response: APIError;
801
+ } : APIError>;
802
+ options: {
803
+ method: "GET";
804
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
805
+ } & {
806
+ use: any[];
807
+ };
808
+ path: "/subscription/success";
809
+ };
810
+ } : {});
811
+ init(ctx: better_auth.AuthContext): {
812
+ options: {
813
+ databaseHooks: {
814
+ user: {
815
+ create: {
816
+ after(user: {
817
+ id: string;
818
+ name: string;
819
+ email: string;
820
+ emailVerified: boolean;
821
+ createdAt: Date;
822
+ updatedAt: Date;
823
+ image?: string | null | undefined;
824
+ }, ctx: GenericEndpointContext | undefined): Promise<void>;
825
+ };
826
+ };
827
+ };
828
+ };
829
+ };
830
+ schema: {
831
+ user: {
832
+ fields: {
833
+ stripeCustomerId: {
834
+ type: "string";
835
+ required: false;
836
+ };
837
+ };
838
+ };
839
+ } & {
840
+ subscription: {
841
+ fields: {
842
+ plan: {
843
+ type: "string";
844
+ required: true;
845
+ };
846
+ referenceId: {
847
+ type: "string";
848
+ required: true;
849
+ };
850
+ stripeCustomerId: {
851
+ type: "string";
852
+ required: false;
853
+ };
854
+ stripeSubscriptionId: {
855
+ type: "string";
856
+ required: false;
857
+ };
858
+ status: {
859
+ type: "string";
860
+ defaultValue: string;
861
+ };
862
+ periodStart: {
863
+ type: "date";
864
+ required: false;
865
+ };
866
+ periodEnd: {
867
+ type: "date";
868
+ required: false;
869
+ };
870
+ cancelAtPeriodEnd: {
871
+ type: "boolean";
872
+ required: false;
873
+ defaultValue: false;
874
+ };
875
+ seats: {
876
+ type: "number";
877
+ required: false;
878
+ };
879
+ };
880
+ };
881
+ };
882
+ };
883
+
884
+ export { type Subscription, stripe };