@vynxc/better-stripe 0.1.0
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/README.md +321 -0
- package/dist/chunk-4KHAYSFO.js +44 -0
- package/dist/chunk-4KHAYSFO.js.map +1 -0
- package/dist/client.d.ts +88 -0
- package/dist/client.js +21 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +1388 -0
- package/dist/index.js +7511 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1388 @@
|
|
|
1
|
+
import * as better_auth from 'better-auth';
|
|
2
|
+
import { User, GenericEndpointContext, Session, InferOptionSchema } from 'better-auth';
|
|
3
|
+
import { Organization } from 'better-auth/plugins/organization';
|
|
4
|
+
import Stripe from 'stripe';
|
|
5
|
+
import * as zod from 'zod';
|
|
6
|
+
import * as better_call from 'better-call';
|
|
7
|
+
|
|
8
|
+
declare const subscriptions: {
|
|
9
|
+
subscription: {
|
|
10
|
+
fields: {
|
|
11
|
+
plan: {
|
|
12
|
+
type: "string";
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
referenceId: {
|
|
16
|
+
type: "string";
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
stripeCustomerId: {
|
|
20
|
+
type: "string";
|
|
21
|
+
required: false;
|
|
22
|
+
};
|
|
23
|
+
stripeSubscriptionId: {
|
|
24
|
+
type: "string";
|
|
25
|
+
required: false;
|
|
26
|
+
};
|
|
27
|
+
status: {
|
|
28
|
+
type: "string";
|
|
29
|
+
defaultValue: string;
|
|
30
|
+
};
|
|
31
|
+
periodStart: {
|
|
32
|
+
type: "date";
|
|
33
|
+
required: false;
|
|
34
|
+
};
|
|
35
|
+
periodEnd: {
|
|
36
|
+
type: "date";
|
|
37
|
+
required: false;
|
|
38
|
+
};
|
|
39
|
+
trialStart: {
|
|
40
|
+
type: "date";
|
|
41
|
+
required: false;
|
|
42
|
+
};
|
|
43
|
+
trialEnd: {
|
|
44
|
+
type: "date";
|
|
45
|
+
required: false;
|
|
46
|
+
};
|
|
47
|
+
cancelAtPeriodEnd: {
|
|
48
|
+
type: "boolean";
|
|
49
|
+
required: false;
|
|
50
|
+
defaultValue: false;
|
|
51
|
+
};
|
|
52
|
+
cancelAt: {
|
|
53
|
+
type: "date";
|
|
54
|
+
required: false;
|
|
55
|
+
};
|
|
56
|
+
canceledAt: {
|
|
57
|
+
type: "date";
|
|
58
|
+
required: false;
|
|
59
|
+
};
|
|
60
|
+
endedAt: {
|
|
61
|
+
type: "date";
|
|
62
|
+
required: false;
|
|
63
|
+
};
|
|
64
|
+
seats: {
|
|
65
|
+
type: "number";
|
|
66
|
+
required: false;
|
|
67
|
+
};
|
|
68
|
+
billingInterval: {
|
|
69
|
+
type: "string";
|
|
70
|
+
required: false;
|
|
71
|
+
};
|
|
72
|
+
stripeScheduleId: {
|
|
73
|
+
type: "string";
|
|
74
|
+
required: false;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
declare const payments: {
|
|
80
|
+
payment: {
|
|
81
|
+
fields: {
|
|
82
|
+
product: {
|
|
83
|
+
type: "string";
|
|
84
|
+
required: true;
|
|
85
|
+
};
|
|
86
|
+
referenceId: {
|
|
87
|
+
type: "string";
|
|
88
|
+
required: true;
|
|
89
|
+
};
|
|
90
|
+
stripeCustomerId: {
|
|
91
|
+
type: "string";
|
|
92
|
+
required: false;
|
|
93
|
+
};
|
|
94
|
+
stripeSessionId: {
|
|
95
|
+
type: "string";
|
|
96
|
+
required: false;
|
|
97
|
+
};
|
|
98
|
+
stripePaymentIntentId: {
|
|
99
|
+
type: "string";
|
|
100
|
+
required: false;
|
|
101
|
+
};
|
|
102
|
+
priceId: {
|
|
103
|
+
type: "string";
|
|
104
|
+
required: false;
|
|
105
|
+
};
|
|
106
|
+
status: {
|
|
107
|
+
type: "string";
|
|
108
|
+
defaultValue: string;
|
|
109
|
+
};
|
|
110
|
+
amount: {
|
|
111
|
+
type: "number";
|
|
112
|
+
required: false;
|
|
113
|
+
};
|
|
114
|
+
currency: {
|
|
115
|
+
type: "string";
|
|
116
|
+
required: false;
|
|
117
|
+
defaultValue: string;
|
|
118
|
+
};
|
|
119
|
+
metadata: {
|
|
120
|
+
type: "string";
|
|
121
|
+
required: false;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
declare const user: {
|
|
127
|
+
user: {
|
|
128
|
+
fields: {
|
|
129
|
+
stripeCustomerId: {
|
|
130
|
+
type: "string";
|
|
131
|
+
required: false;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
declare const organization: {
|
|
137
|
+
organization: {
|
|
138
|
+
fields: {
|
|
139
|
+
stripeCustomerId: {
|
|
140
|
+
type: "string";
|
|
141
|
+
required: false;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type AuthorizeReferenceAction = SubscriptionAction | PaymentAction;
|
|
148
|
+
type SubscriptionAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
|
|
149
|
+
type PaymentAction = "create-payment" | "view-payment" | "list-payments";
|
|
150
|
+
type CustomerType = "user" | "organization";
|
|
151
|
+
type WithStripeCustomerId = {
|
|
152
|
+
stripeCustomerId?: string;
|
|
153
|
+
};
|
|
154
|
+
type WithActiveOrganizationId = {
|
|
155
|
+
activeOrganizationId?: string;
|
|
156
|
+
};
|
|
157
|
+
type StripeCtxSession = {
|
|
158
|
+
session: Session & WithActiveOrganizationId;
|
|
159
|
+
user: User & WithStripeCustomerId;
|
|
160
|
+
};
|
|
161
|
+
type StripePlan = {
|
|
162
|
+
/**
|
|
163
|
+
* Monthly price id
|
|
164
|
+
*/
|
|
165
|
+
priceId?: string | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* To use lookup key instead of price id
|
|
168
|
+
*
|
|
169
|
+
* https://docs.stripe.com/products-prices/
|
|
170
|
+
* manage-prices#lookup-keys
|
|
171
|
+
*/
|
|
172
|
+
lookupKey?: string | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* A yearly discount price id
|
|
175
|
+
*
|
|
176
|
+
* useful when you want to offer a discount for
|
|
177
|
+
* yearly subscription
|
|
178
|
+
*/
|
|
179
|
+
annualDiscountPriceId?: string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* To use lookup key instead of price id
|
|
182
|
+
*
|
|
183
|
+
* https://docs.stripe.com/products-prices/
|
|
184
|
+
* manage-prices#lookup-keys
|
|
185
|
+
*/
|
|
186
|
+
annualDiscountLookupKey?: string | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Plan name
|
|
189
|
+
*/
|
|
190
|
+
name: string;
|
|
191
|
+
/**
|
|
192
|
+
* Limits for the plan
|
|
193
|
+
*
|
|
194
|
+
* useful when you want to define plan-specific metadata.
|
|
195
|
+
*/
|
|
196
|
+
limits?: Record<string, unknown> | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Plan group name
|
|
199
|
+
*
|
|
200
|
+
* useful when you want to group plans or
|
|
201
|
+
* when a user can subscribe to multiple plans.
|
|
202
|
+
*/
|
|
203
|
+
group?: string | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Per-seat billing price ID
|
|
206
|
+
*
|
|
207
|
+
* Requires the `organization` plugin. Member changes
|
|
208
|
+
* automatically sync the seat quantity in Stripe.
|
|
209
|
+
*/
|
|
210
|
+
seatPriceId?: string | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Proration behavior when updating this plan's subscription.
|
|
213
|
+
*
|
|
214
|
+
* Controls how Stripe handles mid-cycle price changes.
|
|
215
|
+
* - `create_prorations`: Add proration line items to the next invoice (default)
|
|
216
|
+
* - `always_invoice`: Create prorations and immediately invoice
|
|
217
|
+
* - `none`: No proration; new price applies at next billing cycle
|
|
218
|
+
*
|
|
219
|
+
* @default "create_prorations"
|
|
220
|
+
* @see https://docs.stripe.com/billing/subscriptions/prorations
|
|
221
|
+
*/
|
|
222
|
+
prorationBehavior?: Stripe.SubscriptionUpdateParams.ProrationBehavior | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Additional line items to include in the checkout session.
|
|
225
|
+
*
|
|
226
|
+
* All line items must use the same billing interval as the base price (e.g. all monthly or all yearly).
|
|
227
|
+
* Stripe does not support mixed-interval subscriptions via Checkout Sessions.
|
|
228
|
+
*
|
|
229
|
+
* @see https://docs.stripe.com/billing/subscriptions/mixed-interval#limitations
|
|
230
|
+
*/
|
|
231
|
+
lineItems?: Stripe.Checkout.SessionCreateParams.LineItem[] | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Free trial days
|
|
234
|
+
*/
|
|
235
|
+
freeTrial?: {
|
|
236
|
+
/**
|
|
237
|
+
* Number of days
|
|
238
|
+
*/
|
|
239
|
+
days: number;
|
|
240
|
+
/**
|
|
241
|
+
* A function that will be called when the trial
|
|
242
|
+
* starts.
|
|
243
|
+
*
|
|
244
|
+
* @param subscription
|
|
245
|
+
* @returns
|
|
246
|
+
*/
|
|
247
|
+
onTrialStart?: (subscription: Subscription) => Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* A function that will be called when the trial
|
|
250
|
+
* ends
|
|
251
|
+
*
|
|
252
|
+
* @param subscription - Subscription
|
|
253
|
+
* @returns
|
|
254
|
+
*/
|
|
255
|
+
onTrialEnd?: (data: {
|
|
256
|
+
subscription: Subscription;
|
|
257
|
+
}, ctx: GenericEndpointContext) => Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* A function that will be called when the trial
|
|
260
|
+
* expired.
|
|
261
|
+
* @param subscription - Subscription
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
264
|
+
onTrialExpired?: (subscription: Subscription, ctx: GenericEndpointContext) => Promise<void>;
|
|
265
|
+
} | undefined;
|
|
266
|
+
};
|
|
267
|
+
interface Subscription {
|
|
268
|
+
/**
|
|
269
|
+
* Database identifier
|
|
270
|
+
*/
|
|
271
|
+
id: string;
|
|
272
|
+
/**
|
|
273
|
+
* The plan name
|
|
274
|
+
*/
|
|
275
|
+
plan: string;
|
|
276
|
+
/**
|
|
277
|
+
* Stripe customer id
|
|
278
|
+
*/
|
|
279
|
+
stripeCustomerId?: string | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Stripe subscription id
|
|
282
|
+
*/
|
|
283
|
+
stripeSubscriptionId?: string | undefined;
|
|
284
|
+
/**
|
|
285
|
+
* Trial start date
|
|
286
|
+
*/
|
|
287
|
+
trialStart?: Date | undefined;
|
|
288
|
+
/**
|
|
289
|
+
* Trial end date
|
|
290
|
+
*/
|
|
291
|
+
trialEnd?: Date | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Price Id for the subscription
|
|
294
|
+
*/
|
|
295
|
+
priceId?: string | undefined;
|
|
296
|
+
/**
|
|
297
|
+
* To what reference id the subscription belongs to
|
|
298
|
+
* @example
|
|
299
|
+
* - userId for a user
|
|
300
|
+
* - workspace id for a saas platform
|
|
301
|
+
* - website id for a hosting platform
|
|
302
|
+
*
|
|
303
|
+
* @default - userId
|
|
304
|
+
*/
|
|
305
|
+
referenceId: string;
|
|
306
|
+
/**
|
|
307
|
+
* Subscription status
|
|
308
|
+
*/
|
|
309
|
+
status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
|
|
310
|
+
/**
|
|
311
|
+
* The billing cycle start date
|
|
312
|
+
*/
|
|
313
|
+
periodStart?: Date | undefined;
|
|
314
|
+
/**
|
|
315
|
+
* The billing cycle end date
|
|
316
|
+
*/
|
|
317
|
+
periodEnd?: Date | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* Whether this subscription will (if status=active)
|
|
320
|
+
* or did (if status=canceled) cancel at the end of the current billing period.
|
|
321
|
+
*/
|
|
322
|
+
cancelAtPeriodEnd?: boolean | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* If the subscription is scheduled to be canceled,
|
|
325
|
+
* this is the time at which the cancellation will take effect.
|
|
326
|
+
*/
|
|
327
|
+
cancelAt?: Date | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* If the subscription has been canceled, this is the time when it was canceled.
|
|
330
|
+
*
|
|
331
|
+
* Note: If the subscription was canceled with `cancel_at_period_end`,
|
|
332
|
+
* this reflects the cancellation request time, not when the subscription actually ends.
|
|
333
|
+
*/
|
|
334
|
+
canceledAt?: Date | undefined;
|
|
335
|
+
/**
|
|
336
|
+
* If the subscription has ended, the date the subscription ended.
|
|
337
|
+
*/
|
|
338
|
+
endedAt?: Date | undefined;
|
|
339
|
+
/**
|
|
340
|
+
* A field to group subscriptions so you can have multiple subscriptions
|
|
341
|
+
* for one reference id
|
|
342
|
+
*/
|
|
343
|
+
groupId?: string | undefined;
|
|
344
|
+
/**
|
|
345
|
+
* Number of seats for the subscription (useful for team plans)
|
|
346
|
+
*/
|
|
347
|
+
seats?: number | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* The billing interval for this subscription.
|
|
350
|
+
* Indicates how often the subscription is billed.
|
|
351
|
+
* @see https://docs.stripe.com/api/plans/object#plan_object-interval
|
|
352
|
+
*/
|
|
353
|
+
billingInterval?: "day" | "week" | "month" | "year" | undefined;
|
|
354
|
+
/**
|
|
355
|
+
* Stripe Subscription Schedule ID, present when a scheduled
|
|
356
|
+
* plan change is pending for this subscription.
|
|
357
|
+
*/
|
|
358
|
+
stripeScheduleId?: string | undefined;
|
|
359
|
+
}
|
|
360
|
+
type StripeProduct = {
|
|
361
|
+
/**
|
|
362
|
+
* Product price id
|
|
363
|
+
*/
|
|
364
|
+
priceId?: string;
|
|
365
|
+
/**
|
|
366
|
+
* To use lookup key instead of price id
|
|
367
|
+
*
|
|
368
|
+
* https://docs.stripe.com/products-prices/manage-prices#lookup-keys
|
|
369
|
+
*/
|
|
370
|
+
lookupKey?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Product name
|
|
373
|
+
*/
|
|
374
|
+
name: string;
|
|
375
|
+
/**
|
|
376
|
+
* Product description
|
|
377
|
+
*/
|
|
378
|
+
description?: string;
|
|
379
|
+
/**
|
|
380
|
+
* Product group name
|
|
381
|
+
*
|
|
382
|
+
* useful when you want to group products or
|
|
383
|
+
* categorize different types of payments
|
|
384
|
+
*/
|
|
385
|
+
group?: string;
|
|
386
|
+
/**
|
|
387
|
+
* Product metadata
|
|
388
|
+
*/
|
|
389
|
+
metadata?: Record<string, any>;
|
|
390
|
+
/**
|
|
391
|
+
* A callback to run after a payment is completed
|
|
392
|
+
*/
|
|
393
|
+
onPaymentComplete?: (data: {
|
|
394
|
+
event: Stripe.Event;
|
|
395
|
+
stripeSession: Stripe.Checkout.Session;
|
|
396
|
+
payment: Payment;
|
|
397
|
+
product: StripeProduct;
|
|
398
|
+
}, ctx: GenericEndpointContext) => Promise<void>;
|
|
399
|
+
};
|
|
400
|
+
interface Payment {
|
|
401
|
+
/**
|
|
402
|
+
* Database identifier
|
|
403
|
+
*/
|
|
404
|
+
id: string;
|
|
405
|
+
/**
|
|
406
|
+
* The product name
|
|
407
|
+
*/
|
|
408
|
+
product: string;
|
|
409
|
+
/**
|
|
410
|
+
* Stripe customer id
|
|
411
|
+
*/
|
|
412
|
+
stripeCustomerId?: string;
|
|
413
|
+
/**
|
|
414
|
+
* Stripe checkout session id
|
|
415
|
+
*/
|
|
416
|
+
stripeSessionId?: string;
|
|
417
|
+
/**
|
|
418
|
+
* Stripe payment intent id
|
|
419
|
+
*/
|
|
420
|
+
stripePaymentIntentId?: string;
|
|
421
|
+
/**
|
|
422
|
+
* Price Id for the payment
|
|
423
|
+
*/
|
|
424
|
+
priceId?: string;
|
|
425
|
+
/**
|
|
426
|
+
* To what reference id the payment belongs to
|
|
427
|
+
* @example
|
|
428
|
+
* - userId for a user
|
|
429
|
+
* - workspace id for a saas platform
|
|
430
|
+
* - website id for a hosting platform
|
|
431
|
+
*
|
|
432
|
+
* @default - userId
|
|
433
|
+
*/
|
|
434
|
+
referenceId: string;
|
|
435
|
+
/**
|
|
436
|
+
* Payment status
|
|
437
|
+
*/
|
|
438
|
+
status: "requires_payment_method" | "requires_confirmation" | "requires_action" | "processing" | "requires_capture" | "canceled" | "succeeded";
|
|
439
|
+
/**
|
|
440
|
+
* Amount paid (in cents)
|
|
441
|
+
*/
|
|
442
|
+
amount?: number;
|
|
443
|
+
/**
|
|
444
|
+
* Currency code
|
|
445
|
+
*/
|
|
446
|
+
currency?: string;
|
|
447
|
+
/**
|
|
448
|
+
* Additional metadata
|
|
449
|
+
*/
|
|
450
|
+
metadata?: string;
|
|
451
|
+
}
|
|
452
|
+
interface InputPayment extends Omit<Payment, "id"> {
|
|
453
|
+
}
|
|
454
|
+
type SubscriptionOptions = {
|
|
455
|
+
/**
|
|
456
|
+
* Subscription Configuration
|
|
457
|
+
*/
|
|
458
|
+
/**
|
|
459
|
+
* List of plan
|
|
460
|
+
*/
|
|
461
|
+
plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
|
|
462
|
+
/**
|
|
463
|
+
* Require email verification before a user is allowed to upgrade
|
|
464
|
+
* their subscriptions
|
|
465
|
+
*
|
|
466
|
+
* @default false
|
|
467
|
+
*/
|
|
468
|
+
requireEmailVerification?: boolean | undefined;
|
|
469
|
+
/**
|
|
470
|
+
* A callback to run after a user has subscribed to a package
|
|
471
|
+
* @param event - Stripe Event
|
|
472
|
+
* @param subscription - Subscription Data
|
|
473
|
+
* @returns
|
|
474
|
+
*/
|
|
475
|
+
onSubscriptionComplete?: ((data: {
|
|
476
|
+
event: Stripe.Event;
|
|
477
|
+
stripeSubscription: Stripe.Subscription;
|
|
478
|
+
subscription: Subscription;
|
|
479
|
+
plan: StripePlan;
|
|
480
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
481
|
+
/**
|
|
482
|
+
* A callback to run after a user is about to cancel their subscription
|
|
483
|
+
* @returns
|
|
484
|
+
*/
|
|
485
|
+
onSubscriptionUpdate?: ((data: {
|
|
486
|
+
event: Stripe.Event;
|
|
487
|
+
subscription: Subscription;
|
|
488
|
+
}) => Promise<void>) | undefined;
|
|
489
|
+
/**
|
|
490
|
+
* A callback to run after a user is about to cancel their subscription
|
|
491
|
+
* @returns
|
|
492
|
+
*/
|
|
493
|
+
onSubscriptionCancel?: ((data: {
|
|
494
|
+
event?: Stripe.Event;
|
|
495
|
+
subscription: Subscription;
|
|
496
|
+
stripeSubscription: Stripe.Subscription;
|
|
497
|
+
cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
|
|
498
|
+
}) => Promise<void>) | undefined;
|
|
499
|
+
/**
|
|
500
|
+
* A function to check if the reference id is valid
|
|
501
|
+
* and belongs to the user
|
|
502
|
+
*
|
|
503
|
+
* @param data - data containing user, session and referenceId
|
|
504
|
+
* @param ctx - the context object
|
|
505
|
+
* @returns
|
|
506
|
+
*/
|
|
507
|
+
authorizeReference?: ((data: {
|
|
508
|
+
user: User & Record<string, any>;
|
|
509
|
+
session: Session & Record<string, any>;
|
|
510
|
+
referenceId: string;
|
|
511
|
+
action: AuthorizeReferenceAction;
|
|
512
|
+
}, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
|
|
513
|
+
/**
|
|
514
|
+
* A callback to run after a user has deleted their subscription
|
|
515
|
+
* @returns
|
|
516
|
+
*/
|
|
517
|
+
onSubscriptionDeleted?: ((data: {
|
|
518
|
+
event: Stripe.Event;
|
|
519
|
+
stripeSubscription: Stripe.Subscription;
|
|
520
|
+
subscription: Subscription;
|
|
521
|
+
}) => Promise<void>) | undefined;
|
|
522
|
+
/**
|
|
523
|
+
* A callback to run when a subscription is created
|
|
524
|
+
* @returns
|
|
525
|
+
*/
|
|
526
|
+
onSubscriptionCreated?: ((data: {
|
|
527
|
+
event: Stripe.Event;
|
|
528
|
+
stripeSubscription: Stripe.Subscription;
|
|
529
|
+
subscription: Subscription;
|
|
530
|
+
plan: StripePlan;
|
|
531
|
+
}) => Promise<void>) | undefined;
|
|
532
|
+
/**
|
|
533
|
+
* parameters for session create params
|
|
534
|
+
*
|
|
535
|
+
* @param data - data containing user, session and plan
|
|
536
|
+
* @param req - the request object
|
|
537
|
+
* @param ctx - the context object
|
|
538
|
+
*/
|
|
539
|
+
getCheckoutSessionParams?: ((data: {
|
|
540
|
+
user: User & Record<string, any>;
|
|
541
|
+
session: Session & Record<string, any>;
|
|
542
|
+
plan: StripePlan;
|
|
543
|
+
subscription: Subscription;
|
|
544
|
+
}, req: GenericEndpointContext["request"], ctx: GenericEndpointContext) => Promise<{
|
|
545
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
546
|
+
options?: Stripe.RequestOptions;
|
|
547
|
+
}> | {
|
|
548
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
549
|
+
options?: Stripe.RequestOptions;
|
|
550
|
+
}) | undefined;
|
|
551
|
+
};
|
|
552
|
+
interface StripeOptions {
|
|
553
|
+
/**
|
|
554
|
+
* Stripe Client
|
|
555
|
+
*/
|
|
556
|
+
stripeClient: Stripe;
|
|
557
|
+
/**
|
|
558
|
+
* Stripe Webhook Secret
|
|
559
|
+
*
|
|
560
|
+
* @description Stripe webhook secret key
|
|
561
|
+
*/
|
|
562
|
+
stripeWebhookSecret: string;
|
|
563
|
+
/**
|
|
564
|
+
* Enable customer creation when a user signs up
|
|
565
|
+
*/
|
|
566
|
+
createCustomerOnSignUp?: boolean | undefined;
|
|
567
|
+
/**
|
|
568
|
+
* A callback to run after a customer has been created
|
|
569
|
+
* @param customer - Customer Data
|
|
570
|
+
* @param stripeCustomer - Stripe Customer Data
|
|
571
|
+
* @returns
|
|
572
|
+
*/
|
|
573
|
+
onCustomerCreate?: ((data: {
|
|
574
|
+
stripeCustomer: Stripe.Customer;
|
|
575
|
+
user: User & WithStripeCustomerId;
|
|
576
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
577
|
+
/**
|
|
578
|
+
* A custom function to get the customer create
|
|
579
|
+
* params
|
|
580
|
+
* @param data - data containing user and session
|
|
581
|
+
* @returns
|
|
582
|
+
*/
|
|
583
|
+
getCustomerCreateParams?: ((user: User, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
|
|
584
|
+
/**
|
|
585
|
+
* Subscriptions
|
|
586
|
+
*/
|
|
587
|
+
subscription?: ({
|
|
588
|
+
enabled: false;
|
|
589
|
+
} | ({
|
|
590
|
+
enabled: true;
|
|
591
|
+
} & SubscriptionOptions)) | undefined;
|
|
592
|
+
/**
|
|
593
|
+
* One-time payments
|
|
594
|
+
*/
|
|
595
|
+
payments?: {
|
|
596
|
+
enabled: boolean;
|
|
597
|
+
/**
|
|
598
|
+
* List of products available for one-time purchase
|
|
599
|
+
*/
|
|
600
|
+
products: StripeProduct[] | (() => StripeProduct[] | Promise<StripeProduct[]>);
|
|
601
|
+
/**
|
|
602
|
+
* Require email verification before a user is allowed to make payments
|
|
603
|
+
*
|
|
604
|
+
* @default false
|
|
605
|
+
*/
|
|
606
|
+
requireEmailVerification?: boolean;
|
|
607
|
+
/**
|
|
608
|
+
* Default success URL for checkout sessions
|
|
609
|
+
*/
|
|
610
|
+
successUrl?: string;
|
|
611
|
+
/**
|
|
612
|
+
* Default cancel URL for checkout sessions
|
|
613
|
+
*/
|
|
614
|
+
cancelUrl?: string;
|
|
615
|
+
/**
|
|
616
|
+
* Allow promotion codes in checkout
|
|
617
|
+
*
|
|
618
|
+
* @default false
|
|
619
|
+
*/
|
|
620
|
+
allowPromotionCodes?: boolean;
|
|
621
|
+
/**
|
|
622
|
+
* Enable automatic tax calculation
|
|
623
|
+
*
|
|
624
|
+
* @default false
|
|
625
|
+
*/
|
|
626
|
+
automaticTax?: boolean;
|
|
627
|
+
/**
|
|
628
|
+
* A function to check if the reference id is valid
|
|
629
|
+
* and belongs to the user
|
|
630
|
+
*/
|
|
631
|
+
authorizeReference?: (data: {
|
|
632
|
+
user: User & Record<string, any>;
|
|
633
|
+
session: Session & Record<string, any>;
|
|
634
|
+
referenceId: string;
|
|
635
|
+
action: PaymentAction;
|
|
636
|
+
}, ctx: GenericEndpointContext) => Promise<boolean>;
|
|
637
|
+
/**
|
|
638
|
+
* Custom parameters for checkout session creation
|
|
639
|
+
*/
|
|
640
|
+
getCheckoutSessionParams?: (data: {
|
|
641
|
+
user: User & Record<string, any>;
|
|
642
|
+
session: Session & Record<string, any>;
|
|
643
|
+
product: StripeProduct;
|
|
644
|
+
payment: Payment;
|
|
645
|
+
}, ctx: GenericEndpointContext) => Promise<{
|
|
646
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
647
|
+
options?: Stripe.RequestOptions;
|
|
648
|
+
}> | {
|
|
649
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
650
|
+
options?: Stripe.RequestOptions;
|
|
651
|
+
};
|
|
652
|
+
} | undefined;
|
|
653
|
+
/**
|
|
654
|
+
* Organization Stripe integration
|
|
655
|
+
*
|
|
656
|
+
* Enable organizations to have their own Stripe customer ID
|
|
657
|
+
*/
|
|
658
|
+
organization?: {
|
|
659
|
+
/**
|
|
660
|
+
* Enable organization Stripe customer
|
|
661
|
+
*/
|
|
662
|
+
enabled: true;
|
|
663
|
+
/**
|
|
664
|
+
* A custom function to get the customer create params
|
|
665
|
+
* for organization customers.
|
|
666
|
+
*
|
|
667
|
+
* @param organization - the organization
|
|
668
|
+
* @param ctx - the context object
|
|
669
|
+
* @returns
|
|
670
|
+
*/
|
|
671
|
+
getCustomerCreateParams?: ((organization: Organization, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
|
|
672
|
+
/**
|
|
673
|
+
* A callback to run after an organization customer has been created
|
|
674
|
+
*
|
|
675
|
+
* @param data - data containing stripeCustomer and organization
|
|
676
|
+
* @param ctx - the context object
|
|
677
|
+
* @returns
|
|
678
|
+
*/
|
|
679
|
+
onCustomerCreate?: ((data: {
|
|
680
|
+
stripeCustomer: Stripe.Customer;
|
|
681
|
+
organization: Organization & WithStripeCustomerId;
|
|
682
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
683
|
+
} | undefined;
|
|
684
|
+
/**
|
|
685
|
+
* A callback to run after a stripe event is received
|
|
686
|
+
* @param event - Stripe Event
|
|
687
|
+
* @returns
|
|
688
|
+
*/
|
|
689
|
+
onEvent?: ((event: Stripe.Event) => Promise<void>) | undefined;
|
|
690
|
+
/**
|
|
691
|
+
* Schema for the stripe plugin
|
|
692
|
+
*/
|
|
693
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization & typeof payments> | undefined;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
declare module "@better-auth/core" {
|
|
697
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
698
|
+
stripe: {
|
|
699
|
+
creator: typeof stripe;
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
704
|
+
id: "stripe";
|
|
705
|
+
endpoints: {
|
|
706
|
+
stripeWebhook: better_call.StrictEndpoint<"/stripe/webhook", {
|
|
707
|
+
method: "POST";
|
|
708
|
+
metadata: {
|
|
709
|
+
openapi: {
|
|
710
|
+
operationId: string;
|
|
711
|
+
};
|
|
712
|
+
scope: "server";
|
|
713
|
+
};
|
|
714
|
+
cloneRequest: true;
|
|
715
|
+
disableBody: true;
|
|
716
|
+
}, {
|
|
717
|
+
success: boolean;
|
|
718
|
+
}>;
|
|
719
|
+
} & (O["subscription"] extends {
|
|
720
|
+
enabled: true;
|
|
721
|
+
} ? {
|
|
722
|
+
upgradeSubscription: better_call.StrictEndpoint<"/subscription/upgrade", {
|
|
723
|
+
method: "POST";
|
|
724
|
+
body: zod.ZodObject<{
|
|
725
|
+
plan: zod.ZodString;
|
|
726
|
+
annual: zod.ZodOptional<zod.ZodBoolean>;
|
|
727
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
728
|
+
subscriptionId: zod.ZodOptional<zod.ZodString>;
|
|
729
|
+
customerType: zod.ZodOptional<zod.ZodEnum<{
|
|
730
|
+
organization: "organization";
|
|
731
|
+
user: "user";
|
|
732
|
+
}>>;
|
|
733
|
+
metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
734
|
+
seats: zod.ZodOptional<zod.ZodNumber>;
|
|
735
|
+
locale: zod.ZodOptional<zod.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
|
|
736
|
+
successUrl: zod.ZodDefault<zod.ZodString>;
|
|
737
|
+
cancelUrl: zod.ZodDefault<zod.ZodString>;
|
|
738
|
+
returnUrl: zod.ZodOptional<zod.ZodString>;
|
|
739
|
+
scheduleAtPeriodEnd: zod.ZodDefault<zod.ZodBoolean>;
|
|
740
|
+
disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
|
|
741
|
+
}, better_auth.$strip>;
|
|
742
|
+
metadata: {
|
|
743
|
+
openapi: {
|
|
744
|
+
operationId: string;
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
748
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
749
|
+
session: {
|
|
750
|
+
session: Record<string, any> & {
|
|
751
|
+
id: string;
|
|
752
|
+
createdAt: Date;
|
|
753
|
+
updatedAt: Date;
|
|
754
|
+
userId: string;
|
|
755
|
+
expiresAt: Date;
|
|
756
|
+
token: string;
|
|
757
|
+
ipAddress?: string | null | undefined;
|
|
758
|
+
userAgent?: string | null | undefined;
|
|
759
|
+
};
|
|
760
|
+
user: Record<string, any> & {
|
|
761
|
+
id: string;
|
|
762
|
+
createdAt: Date;
|
|
763
|
+
updatedAt: Date;
|
|
764
|
+
email: string;
|
|
765
|
+
emailVerified: boolean;
|
|
766
|
+
name: string;
|
|
767
|
+
image?: string | null | undefined;
|
|
768
|
+
};
|
|
769
|
+
};
|
|
770
|
+
}>)[];
|
|
771
|
+
}>) => Promise<{
|
|
772
|
+
session: StripeCtxSession;
|
|
773
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
774
|
+
}, {
|
|
775
|
+
url: string;
|
|
776
|
+
redirect: boolean;
|
|
777
|
+
} | {
|
|
778
|
+
redirect: boolean;
|
|
779
|
+
id: string;
|
|
780
|
+
object: "checkout.session";
|
|
781
|
+
adaptive_pricing: Stripe.Checkout.Session.AdaptivePricing | null;
|
|
782
|
+
after_expiration: Stripe.Checkout.Session.AfterExpiration | null;
|
|
783
|
+
allow_promotion_codes: boolean | null;
|
|
784
|
+
amount_subtotal: number | null;
|
|
785
|
+
amount_total: number | null;
|
|
786
|
+
automatic_tax: Stripe.Checkout.Session.AutomaticTax;
|
|
787
|
+
billing_address_collection: Stripe.Checkout.Session.BillingAddressCollection | null;
|
|
788
|
+
branding_settings?: Stripe.Checkout.Session.BrandingSettings;
|
|
789
|
+
cancel_url: string | null;
|
|
790
|
+
client_reference_id: string | null;
|
|
791
|
+
client_secret: string | null;
|
|
792
|
+
collected_information: Stripe.Checkout.Session.CollectedInformation | null;
|
|
793
|
+
consent: Stripe.Checkout.Session.Consent | null;
|
|
794
|
+
consent_collection: Stripe.Checkout.Session.ConsentCollection | null;
|
|
795
|
+
created: number;
|
|
796
|
+
currency: string | null;
|
|
797
|
+
currency_conversion: Stripe.Checkout.Session.CurrencyConversion | null;
|
|
798
|
+
custom_fields: Array<Stripe.Checkout.Session.CustomField>;
|
|
799
|
+
custom_text: Stripe.Checkout.Session.CustomText;
|
|
800
|
+
customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
|
|
801
|
+
customer_account: string | null;
|
|
802
|
+
customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
|
|
803
|
+
customer_details: Stripe.Checkout.Session.CustomerDetails | null;
|
|
804
|
+
customer_email: string | null;
|
|
805
|
+
discounts: Array<Stripe.Checkout.Session.Discount> | null;
|
|
806
|
+
excluded_payment_method_types?: Array<string>;
|
|
807
|
+
expires_at: number;
|
|
808
|
+
invoice: string | Stripe.Invoice | null;
|
|
809
|
+
invoice_creation: Stripe.Checkout.Session.InvoiceCreation | null;
|
|
810
|
+
line_items?: Stripe.ApiList<Stripe.LineItem>;
|
|
811
|
+
livemode: boolean;
|
|
812
|
+
locale: Stripe.Checkout.Session.Locale | null;
|
|
813
|
+
metadata: Stripe.Metadata | null;
|
|
814
|
+
mode: Stripe.Checkout.Session.Mode;
|
|
815
|
+
name_collection?: Stripe.Checkout.Session.NameCollection;
|
|
816
|
+
optional_items?: Array<Stripe.Checkout.Session.OptionalItem> | null;
|
|
817
|
+
origin_context: Stripe.Checkout.Session.OriginContext | null;
|
|
818
|
+
payment_intent: string | Stripe.PaymentIntent | null;
|
|
819
|
+
payment_link: string | Stripe.PaymentLink | null;
|
|
820
|
+
payment_method_collection: Stripe.Checkout.Session.PaymentMethodCollection | null;
|
|
821
|
+
payment_method_configuration_details: Stripe.Checkout.Session.PaymentMethodConfigurationDetails | null;
|
|
822
|
+
payment_method_options: Stripe.Checkout.Session.PaymentMethodOptions | null;
|
|
823
|
+
payment_method_types: Array<string>;
|
|
824
|
+
payment_status: Stripe.Checkout.Session.PaymentStatus;
|
|
825
|
+
permissions: Stripe.Checkout.Session.Permissions | null;
|
|
826
|
+
phone_number_collection?: Stripe.Checkout.Session.PhoneNumberCollection;
|
|
827
|
+
presentment_details?: Stripe.Checkout.Session.PresentmentDetails;
|
|
828
|
+
recovered_from: string | null;
|
|
829
|
+
redirect_on_completion?: Stripe.Checkout.Session.RedirectOnCompletion;
|
|
830
|
+
return_url?: string;
|
|
831
|
+
saved_payment_method_options: Stripe.Checkout.Session.SavedPaymentMethodOptions | null;
|
|
832
|
+
setup_intent: string | Stripe.SetupIntent | null;
|
|
833
|
+
shipping_address_collection: Stripe.Checkout.Session.ShippingAddressCollection | null;
|
|
834
|
+
shipping_cost: Stripe.Checkout.Session.ShippingCost | null;
|
|
835
|
+
shipping_options: Array<Stripe.Checkout.Session.ShippingOption>;
|
|
836
|
+
status: Stripe.Checkout.Session.Status | null;
|
|
837
|
+
submit_type: Stripe.Checkout.Session.SubmitType | null;
|
|
838
|
+
subscription: string | Stripe.Subscription | null;
|
|
839
|
+
success_url: string | null;
|
|
840
|
+
tax_id_collection?: Stripe.Checkout.Session.TaxIdCollection;
|
|
841
|
+
total_details: Stripe.Checkout.Session.TotalDetails | null;
|
|
842
|
+
ui_mode: Stripe.Checkout.Session.UiMode | null;
|
|
843
|
+
url: string | null;
|
|
844
|
+
wallet_options: Stripe.Checkout.Session.WalletOptions | null;
|
|
845
|
+
lastResponse: {
|
|
846
|
+
headers: {
|
|
847
|
+
[key: string]: string;
|
|
848
|
+
};
|
|
849
|
+
requestId: string;
|
|
850
|
+
statusCode: number;
|
|
851
|
+
apiVersion?: string;
|
|
852
|
+
idempotencyKey?: string;
|
|
853
|
+
stripeAccount?: string;
|
|
854
|
+
};
|
|
855
|
+
}>;
|
|
856
|
+
cancelSubscription: better_call.StrictEndpoint<"/subscription/cancel", {
|
|
857
|
+
method: "POST";
|
|
858
|
+
body: zod.ZodObject<{
|
|
859
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
860
|
+
subscriptionId: zod.ZodOptional<zod.ZodString>;
|
|
861
|
+
customerType: zod.ZodOptional<zod.ZodEnum<{
|
|
862
|
+
organization: "organization";
|
|
863
|
+
user: "user";
|
|
864
|
+
}>>;
|
|
865
|
+
returnUrl: zod.ZodString;
|
|
866
|
+
disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
|
|
867
|
+
}, better_auth.$strip>;
|
|
868
|
+
metadata: {
|
|
869
|
+
openapi: {
|
|
870
|
+
operationId: string;
|
|
871
|
+
};
|
|
872
|
+
};
|
|
873
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
874
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
875
|
+
session: {
|
|
876
|
+
session: Record<string, any> & {
|
|
877
|
+
id: string;
|
|
878
|
+
createdAt: Date;
|
|
879
|
+
updatedAt: Date;
|
|
880
|
+
userId: string;
|
|
881
|
+
expiresAt: Date;
|
|
882
|
+
token: string;
|
|
883
|
+
ipAddress?: string | null | undefined;
|
|
884
|
+
userAgent?: string | null | undefined;
|
|
885
|
+
};
|
|
886
|
+
user: Record<string, any> & {
|
|
887
|
+
id: string;
|
|
888
|
+
createdAt: Date;
|
|
889
|
+
updatedAt: Date;
|
|
890
|
+
email: string;
|
|
891
|
+
emailVerified: boolean;
|
|
892
|
+
name: string;
|
|
893
|
+
image?: string | null | undefined;
|
|
894
|
+
};
|
|
895
|
+
};
|
|
896
|
+
}>)[];
|
|
897
|
+
}>) => Promise<{
|
|
898
|
+
session: StripeCtxSession;
|
|
899
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
900
|
+
}, {
|
|
901
|
+
url: string;
|
|
902
|
+
redirect: boolean;
|
|
903
|
+
}>;
|
|
904
|
+
restoreSubscription: better_call.StrictEndpoint<"/subscription/restore", {
|
|
905
|
+
method: "POST";
|
|
906
|
+
body: zod.ZodObject<{
|
|
907
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
908
|
+
subscriptionId: zod.ZodOptional<zod.ZodString>;
|
|
909
|
+
customerType: zod.ZodOptional<zod.ZodEnum<{
|
|
910
|
+
organization: "organization";
|
|
911
|
+
user: "user";
|
|
912
|
+
}>>;
|
|
913
|
+
}, better_auth.$strip>;
|
|
914
|
+
metadata: {
|
|
915
|
+
openapi: {
|
|
916
|
+
operationId: string;
|
|
917
|
+
};
|
|
918
|
+
};
|
|
919
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
920
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
921
|
+
session: {
|
|
922
|
+
session: Record<string, any> & {
|
|
923
|
+
id: string;
|
|
924
|
+
createdAt: Date;
|
|
925
|
+
updatedAt: Date;
|
|
926
|
+
userId: string;
|
|
927
|
+
expiresAt: Date;
|
|
928
|
+
token: string;
|
|
929
|
+
ipAddress?: string | null | undefined;
|
|
930
|
+
userAgent?: string | null | undefined;
|
|
931
|
+
};
|
|
932
|
+
user: Record<string, any> & {
|
|
933
|
+
id: string;
|
|
934
|
+
createdAt: Date;
|
|
935
|
+
updatedAt: Date;
|
|
936
|
+
email: string;
|
|
937
|
+
emailVerified: boolean;
|
|
938
|
+
name: string;
|
|
939
|
+
image?: string | null | undefined;
|
|
940
|
+
};
|
|
941
|
+
};
|
|
942
|
+
}>)[];
|
|
943
|
+
}>) => Promise<{
|
|
944
|
+
session: StripeCtxSession;
|
|
945
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
946
|
+
}, Stripe.Response<Stripe.Subscription>>;
|
|
947
|
+
listActiveSubscriptions: better_call.StrictEndpoint<"/subscription/list", {
|
|
948
|
+
method: "GET";
|
|
949
|
+
query: zod.ZodOptional<zod.ZodObject<{
|
|
950
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
951
|
+
customerType: zod.ZodOptional<zod.ZodEnum<{
|
|
952
|
+
organization: "organization";
|
|
953
|
+
user: "user";
|
|
954
|
+
}>>;
|
|
955
|
+
}, better_auth.$strip>>;
|
|
956
|
+
metadata: {
|
|
957
|
+
openapi: {
|
|
958
|
+
operationId: string;
|
|
959
|
+
};
|
|
960
|
+
};
|
|
961
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
962
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
963
|
+
session: {
|
|
964
|
+
session: Record<string, any> & {
|
|
965
|
+
id: string;
|
|
966
|
+
createdAt: Date;
|
|
967
|
+
updatedAt: Date;
|
|
968
|
+
userId: string;
|
|
969
|
+
expiresAt: Date;
|
|
970
|
+
token: string;
|
|
971
|
+
ipAddress?: string | null | undefined;
|
|
972
|
+
userAgent?: string | null | undefined;
|
|
973
|
+
};
|
|
974
|
+
user: Record<string, any> & {
|
|
975
|
+
id: string;
|
|
976
|
+
createdAt: Date;
|
|
977
|
+
updatedAt: Date;
|
|
978
|
+
email: string;
|
|
979
|
+
emailVerified: boolean;
|
|
980
|
+
name: string;
|
|
981
|
+
image?: string | null | undefined;
|
|
982
|
+
};
|
|
983
|
+
};
|
|
984
|
+
}>)[];
|
|
985
|
+
}>) => Promise<{
|
|
986
|
+
session: StripeCtxSession;
|
|
987
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
988
|
+
}, {
|
|
989
|
+
limits: Record<string, unknown> | undefined;
|
|
990
|
+
priceId: string | undefined;
|
|
991
|
+
id: string;
|
|
992
|
+
plan: string;
|
|
993
|
+
stripeCustomerId?: string | undefined;
|
|
994
|
+
stripeSubscriptionId?: string | undefined;
|
|
995
|
+
trialStart?: Date | undefined;
|
|
996
|
+
trialEnd?: Date | undefined;
|
|
997
|
+
referenceId: string;
|
|
998
|
+
status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
|
|
999
|
+
periodStart?: Date | undefined;
|
|
1000
|
+
periodEnd?: Date | undefined;
|
|
1001
|
+
cancelAtPeriodEnd?: boolean | undefined;
|
|
1002
|
+
cancelAt?: Date | undefined;
|
|
1003
|
+
canceledAt?: Date | undefined;
|
|
1004
|
+
endedAt?: Date | undefined;
|
|
1005
|
+
groupId?: string | undefined;
|
|
1006
|
+
seats?: number | undefined;
|
|
1007
|
+
billingInterval?: "day" | "week" | "month" | "year" | undefined;
|
|
1008
|
+
stripeScheduleId?: string | undefined;
|
|
1009
|
+
}[]>;
|
|
1010
|
+
subscriptionSuccess: better_call.StrictEndpoint<"/subscription/success", {
|
|
1011
|
+
method: "GET";
|
|
1012
|
+
query: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
1013
|
+
metadata: {
|
|
1014
|
+
openapi: {
|
|
1015
|
+
operationId: string;
|
|
1016
|
+
};
|
|
1017
|
+
};
|
|
1018
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>)[];
|
|
1019
|
+
}, never>;
|
|
1020
|
+
createBillingPortal: better_call.StrictEndpoint<"/subscription/billing-portal", {
|
|
1021
|
+
method: "POST";
|
|
1022
|
+
body: zod.ZodObject<{
|
|
1023
|
+
locale: zod.ZodOptional<zod.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
|
|
1024
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
1025
|
+
customerType: zod.ZodOptional<zod.ZodEnum<{
|
|
1026
|
+
organization: "organization";
|
|
1027
|
+
user: "user";
|
|
1028
|
+
}>>;
|
|
1029
|
+
returnUrl: zod.ZodDefault<zod.ZodString>;
|
|
1030
|
+
disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
|
|
1031
|
+
}, better_auth.$strip>;
|
|
1032
|
+
metadata: {
|
|
1033
|
+
openapi: {
|
|
1034
|
+
operationId: string;
|
|
1035
|
+
};
|
|
1036
|
+
};
|
|
1037
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
1038
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
1039
|
+
session: {
|
|
1040
|
+
session: Record<string, any> & {
|
|
1041
|
+
id: string;
|
|
1042
|
+
createdAt: Date;
|
|
1043
|
+
updatedAt: Date;
|
|
1044
|
+
userId: string;
|
|
1045
|
+
expiresAt: Date;
|
|
1046
|
+
token: string;
|
|
1047
|
+
ipAddress?: string | null | undefined;
|
|
1048
|
+
userAgent?: string | null | undefined;
|
|
1049
|
+
};
|
|
1050
|
+
user: Record<string, any> & {
|
|
1051
|
+
id: string;
|
|
1052
|
+
createdAt: Date;
|
|
1053
|
+
updatedAt: Date;
|
|
1054
|
+
email: string;
|
|
1055
|
+
emailVerified: boolean;
|
|
1056
|
+
name: string;
|
|
1057
|
+
image?: string | null | undefined;
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
}>)[];
|
|
1061
|
+
}>) => Promise<{
|
|
1062
|
+
session: StripeCtxSession;
|
|
1063
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
1064
|
+
}, {
|
|
1065
|
+
url: string;
|
|
1066
|
+
redirect: boolean;
|
|
1067
|
+
}>;
|
|
1068
|
+
} : {}) & (O["payments"] extends {
|
|
1069
|
+
enabled: true;
|
|
1070
|
+
} ? {
|
|
1071
|
+
createPaymentSession: better_call.StrictEndpoint<"/payment/create-session", {
|
|
1072
|
+
method: "POST";
|
|
1073
|
+
body: zod.ZodObject<{
|
|
1074
|
+
productName: zod.ZodString;
|
|
1075
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
1076
|
+
quantity: zod.ZodDefault<zod.ZodNumber>;
|
|
1077
|
+
successUrl: zod.ZodDefault<zod.ZodString>;
|
|
1078
|
+
cancelUrl: zod.ZodDefault<zod.ZodString>;
|
|
1079
|
+
disableRedirect: zod.ZodDefault<zod.ZodBoolean>;
|
|
1080
|
+
metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
1081
|
+
}, better_auth.$strip>;
|
|
1082
|
+
metadata: {
|
|
1083
|
+
openapi: {
|
|
1084
|
+
operationId: string;
|
|
1085
|
+
};
|
|
1086
|
+
};
|
|
1087
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
1088
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
1089
|
+
session: {
|
|
1090
|
+
session: Record<string, any> & {
|
|
1091
|
+
id: string;
|
|
1092
|
+
createdAt: Date;
|
|
1093
|
+
updatedAt: Date;
|
|
1094
|
+
userId: string;
|
|
1095
|
+
expiresAt: Date;
|
|
1096
|
+
token: string;
|
|
1097
|
+
ipAddress?: string | null | undefined;
|
|
1098
|
+
userAgent?: string | null | undefined;
|
|
1099
|
+
};
|
|
1100
|
+
user: Record<string, any> & {
|
|
1101
|
+
id: string;
|
|
1102
|
+
createdAt: Date;
|
|
1103
|
+
updatedAt: Date;
|
|
1104
|
+
email: string;
|
|
1105
|
+
emailVerified: boolean;
|
|
1106
|
+
name: string;
|
|
1107
|
+
image?: string | null | undefined;
|
|
1108
|
+
};
|
|
1109
|
+
};
|
|
1110
|
+
}>)[];
|
|
1111
|
+
}>) => Promise<{
|
|
1112
|
+
session: StripeCtxSession;
|
|
1113
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
1114
|
+
}, {
|
|
1115
|
+
url: string | null;
|
|
1116
|
+
sessionId: string;
|
|
1117
|
+
paymentId: string;
|
|
1118
|
+
redirect: boolean;
|
|
1119
|
+
}>;
|
|
1120
|
+
getPaymentStatus: better_call.StrictEndpoint<"/payment/status", {
|
|
1121
|
+
method: "GET";
|
|
1122
|
+
query: zod.ZodOptional<zod.ZodObject<{
|
|
1123
|
+
paymentId: zod.ZodOptional<zod.ZodString>;
|
|
1124
|
+
sessionId: zod.ZodOptional<zod.ZodString>;
|
|
1125
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
1126
|
+
}, better_auth.$strip>>;
|
|
1127
|
+
metadata: {
|
|
1128
|
+
openapi: {
|
|
1129
|
+
operationId: string;
|
|
1130
|
+
};
|
|
1131
|
+
};
|
|
1132
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
1133
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
1134
|
+
session: {
|
|
1135
|
+
session: Record<string, any> & {
|
|
1136
|
+
id: string;
|
|
1137
|
+
createdAt: Date;
|
|
1138
|
+
updatedAt: Date;
|
|
1139
|
+
userId: string;
|
|
1140
|
+
expiresAt: Date;
|
|
1141
|
+
token: string;
|
|
1142
|
+
ipAddress?: string | null | undefined;
|
|
1143
|
+
userAgent?: string | null | undefined;
|
|
1144
|
+
};
|
|
1145
|
+
user: Record<string, any> & {
|
|
1146
|
+
id: string;
|
|
1147
|
+
createdAt: Date;
|
|
1148
|
+
updatedAt: Date;
|
|
1149
|
+
email: string;
|
|
1150
|
+
emailVerified: boolean;
|
|
1151
|
+
name: string;
|
|
1152
|
+
image?: string | null | undefined;
|
|
1153
|
+
};
|
|
1154
|
+
};
|
|
1155
|
+
}>)[];
|
|
1156
|
+
}>) => Promise<{
|
|
1157
|
+
session: StripeCtxSession;
|
|
1158
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
1159
|
+
}, Payment>;
|
|
1160
|
+
listPayments: better_call.StrictEndpoint<"/payment/list", {
|
|
1161
|
+
method: "GET";
|
|
1162
|
+
query: zod.ZodOptional<zod.ZodObject<{
|
|
1163
|
+
referenceId: zod.ZodOptional<zod.ZodString>;
|
|
1164
|
+
status: zod.ZodOptional<zod.ZodString>;
|
|
1165
|
+
limit: zod.ZodDefault<zod.ZodNumber>;
|
|
1166
|
+
offset: zod.ZodDefault<zod.ZodNumber>;
|
|
1167
|
+
}, better_auth.$strip>>;
|
|
1168
|
+
metadata: {
|
|
1169
|
+
openapi: {
|
|
1170
|
+
operationId: string;
|
|
1171
|
+
};
|
|
1172
|
+
};
|
|
1173
|
+
use: (((inputContext: better_call.MiddlewareInputContext<{
|
|
1174
|
+
use: ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<{
|
|
1175
|
+
session: {
|
|
1176
|
+
session: Record<string, any> & {
|
|
1177
|
+
id: string;
|
|
1178
|
+
createdAt: Date;
|
|
1179
|
+
updatedAt: Date;
|
|
1180
|
+
userId: string;
|
|
1181
|
+
expiresAt: Date;
|
|
1182
|
+
token: string;
|
|
1183
|
+
ipAddress?: string | null | undefined;
|
|
1184
|
+
userAgent?: string | null | undefined;
|
|
1185
|
+
};
|
|
1186
|
+
user: Record<string, any> & {
|
|
1187
|
+
id: string;
|
|
1188
|
+
createdAt: Date;
|
|
1189
|
+
updatedAt: Date;
|
|
1190
|
+
email: string;
|
|
1191
|
+
emailVerified: boolean;
|
|
1192
|
+
name: string;
|
|
1193
|
+
image?: string | null | undefined;
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
}>)[];
|
|
1197
|
+
}>) => Promise<{
|
|
1198
|
+
session: StripeCtxSession;
|
|
1199
|
+
}>) | ((inputContext: better_call.MiddlewareInputContext<better_call.MiddlewareOptions>) => Promise<void>))[];
|
|
1200
|
+
}, Payment[]>;
|
|
1201
|
+
} : {});
|
|
1202
|
+
init(ctx: better_auth.AuthContext): {
|
|
1203
|
+
options: {
|
|
1204
|
+
databaseHooks: {
|
|
1205
|
+
user: {
|
|
1206
|
+
create: {
|
|
1207
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth.GenericEndpointContext | null): Promise<void>;
|
|
1208
|
+
};
|
|
1209
|
+
update: {
|
|
1210
|
+
after(user: User & WithStripeCustomerId, ctx: better_auth.GenericEndpointContext | null): Promise<void>;
|
|
1211
|
+
};
|
|
1212
|
+
};
|
|
1213
|
+
};
|
|
1214
|
+
};
|
|
1215
|
+
} | undefined;
|
|
1216
|
+
schema: {
|
|
1217
|
+
user: {
|
|
1218
|
+
fields: {
|
|
1219
|
+
stripeCustomerId: {
|
|
1220
|
+
type: "string";
|
|
1221
|
+
required: false;
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
};
|
|
1225
|
+
} & (O["subscription"] extends {
|
|
1226
|
+
enabled: true;
|
|
1227
|
+
} ? {
|
|
1228
|
+
subscription: {
|
|
1229
|
+
fields: {
|
|
1230
|
+
plan: {
|
|
1231
|
+
type: "string";
|
|
1232
|
+
required: true;
|
|
1233
|
+
};
|
|
1234
|
+
referenceId: {
|
|
1235
|
+
type: "string";
|
|
1236
|
+
required: true;
|
|
1237
|
+
};
|
|
1238
|
+
stripeCustomerId: {
|
|
1239
|
+
type: "string";
|
|
1240
|
+
required: false;
|
|
1241
|
+
};
|
|
1242
|
+
stripeSubscriptionId: {
|
|
1243
|
+
type: "string";
|
|
1244
|
+
required: false;
|
|
1245
|
+
};
|
|
1246
|
+
status: {
|
|
1247
|
+
type: "string";
|
|
1248
|
+
defaultValue: string;
|
|
1249
|
+
};
|
|
1250
|
+
periodStart: {
|
|
1251
|
+
type: "date";
|
|
1252
|
+
required: false;
|
|
1253
|
+
};
|
|
1254
|
+
periodEnd: {
|
|
1255
|
+
type: "date";
|
|
1256
|
+
required: false;
|
|
1257
|
+
};
|
|
1258
|
+
trialStart: {
|
|
1259
|
+
type: "date";
|
|
1260
|
+
required: false;
|
|
1261
|
+
};
|
|
1262
|
+
trialEnd: {
|
|
1263
|
+
type: "date";
|
|
1264
|
+
required: false;
|
|
1265
|
+
};
|
|
1266
|
+
cancelAtPeriodEnd: {
|
|
1267
|
+
type: "boolean";
|
|
1268
|
+
required: false;
|
|
1269
|
+
defaultValue: false;
|
|
1270
|
+
};
|
|
1271
|
+
cancelAt: {
|
|
1272
|
+
type: "date";
|
|
1273
|
+
required: false;
|
|
1274
|
+
};
|
|
1275
|
+
canceledAt: {
|
|
1276
|
+
type: "date";
|
|
1277
|
+
required: false;
|
|
1278
|
+
};
|
|
1279
|
+
endedAt: {
|
|
1280
|
+
type: "date";
|
|
1281
|
+
required: false;
|
|
1282
|
+
};
|
|
1283
|
+
seats: {
|
|
1284
|
+
type: "number";
|
|
1285
|
+
required: false;
|
|
1286
|
+
};
|
|
1287
|
+
billingInterval: {
|
|
1288
|
+
type: "string";
|
|
1289
|
+
required: false;
|
|
1290
|
+
};
|
|
1291
|
+
stripeScheduleId: {
|
|
1292
|
+
type: "string";
|
|
1293
|
+
required: false;
|
|
1294
|
+
};
|
|
1295
|
+
};
|
|
1296
|
+
};
|
|
1297
|
+
} : {}) & (O["organization"] extends {
|
|
1298
|
+
enabled: true;
|
|
1299
|
+
} ? {
|
|
1300
|
+
organization: {
|
|
1301
|
+
fields: {
|
|
1302
|
+
stripeCustomerId: {
|
|
1303
|
+
type: "string";
|
|
1304
|
+
required: false;
|
|
1305
|
+
};
|
|
1306
|
+
};
|
|
1307
|
+
};
|
|
1308
|
+
} : {}) & (O["payments"] extends {
|
|
1309
|
+
enabled: true;
|
|
1310
|
+
} ? {
|
|
1311
|
+
payment: {
|
|
1312
|
+
fields: {
|
|
1313
|
+
product: {
|
|
1314
|
+
type: "string";
|
|
1315
|
+
required: true;
|
|
1316
|
+
};
|
|
1317
|
+
referenceId: {
|
|
1318
|
+
type: "string";
|
|
1319
|
+
required: true;
|
|
1320
|
+
};
|
|
1321
|
+
stripeCustomerId: {
|
|
1322
|
+
type: "string";
|
|
1323
|
+
required: false;
|
|
1324
|
+
};
|
|
1325
|
+
stripeSessionId: {
|
|
1326
|
+
type: "string";
|
|
1327
|
+
required: false;
|
|
1328
|
+
};
|
|
1329
|
+
stripePaymentIntentId: {
|
|
1330
|
+
type: "string";
|
|
1331
|
+
required: false;
|
|
1332
|
+
};
|
|
1333
|
+
priceId: {
|
|
1334
|
+
type: "string";
|
|
1335
|
+
required: false;
|
|
1336
|
+
};
|
|
1337
|
+
status: {
|
|
1338
|
+
type: "string";
|
|
1339
|
+
defaultValue: string;
|
|
1340
|
+
};
|
|
1341
|
+
amount: {
|
|
1342
|
+
type: "number";
|
|
1343
|
+
required: false;
|
|
1344
|
+
};
|
|
1345
|
+
currency: {
|
|
1346
|
+
type: "string";
|
|
1347
|
+
required: false;
|
|
1348
|
+
defaultValue: string;
|
|
1349
|
+
};
|
|
1350
|
+
metadata: {
|
|
1351
|
+
type: "string";
|
|
1352
|
+
required: false;
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
};
|
|
1356
|
+
} : {});
|
|
1357
|
+
options: NoInfer<O>;
|
|
1358
|
+
$ERROR_CODES: {
|
|
1359
|
+
UNAUTHORIZED: better_auth.RawError<"UNAUTHORIZED">;
|
|
1360
|
+
INVALID_REQUEST_BODY: better_auth.RawError<"INVALID_REQUEST_BODY">;
|
|
1361
|
+
SUBSCRIPTION_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_NOT_FOUND">;
|
|
1362
|
+
SUBSCRIPTION_PLAN_NOT_FOUND: better_auth.RawError<"SUBSCRIPTION_PLAN_NOT_FOUND">;
|
|
1363
|
+
ALREADY_SUBSCRIBED_PLAN: better_auth.RawError<"ALREADY_SUBSCRIBED_PLAN">;
|
|
1364
|
+
REFERENCE_ID_NOT_ALLOWED: better_auth.RawError<"REFERENCE_ID_NOT_ALLOWED">;
|
|
1365
|
+
CUSTOMER_NOT_FOUND: better_auth.RawError<"CUSTOMER_NOT_FOUND">;
|
|
1366
|
+
UNABLE_TO_CREATE_CUSTOMER: better_auth.RawError<"UNABLE_TO_CREATE_CUSTOMER">;
|
|
1367
|
+
UNABLE_TO_CREATE_BILLING_PORTAL: better_auth.RawError<"UNABLE_TO_CREATE_BILLING_PORTAL">;
|
|
1368
|
+
STRIPE_SIGNATURE_NOT_FOUND: better_auth.RawError<"STRIPE_SIGNATURE_NOT_FOUND">;
|
|
1369
|
+
STRIPE_WEBHOOK_SECRET_NOT_FOUND: better_auth.RawError<"STRIPE_WEBHOOK_SECRET_NOT_FOUND">;
|
|
1370
|
+
STRIPE_WEBHOOK_ERROR: better_auth.RawError<"STRIPE_WEBHOOK_ERROR">;
|
|
1371
|
+
FAILED_TO_CONSTRUCT_STRIPE_EVENT: better_auth.RawError<"FAILED_TO_CONSTRUCT_STRIPE_EVENT">;
|
|
1372
|
+
FAILED_TO_FETCH_PLANS: better_auth.RawError<"FAILED_TO_FETCH_PLANS">;
|
|
1373
|
+
EMAIL_VERIFICATION_REQUIRED: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED">;
|
|
1374
|
+
SUBSCRIPTION_NOT_ACTIVE: better_auth.RawError<"SUBSCRIPTION_NOT_ACTIVE">;
|
|
1375
|
+
SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: better_auth.RawError<"SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION">;
|
|
1376
|
+
SUBSCRIPTION_NOT_PENDING_CHANGE: better_auth.RawError<"SUBSCRIPTION_NOT_PENDING_CHANGE">;
|
|
1377
|
+
ORGANIZATION_NOT_FOUND: better_auth.RawError<"ORGANIZATION_NOT_FOUND">;
|
|
1378
|
+
ORGANIZATION_SUBSCRIPTION_NOT_ENABLED: better_auth.RawError<"ORGANIZATION_SUBSCRIPTION_NOT_ENABLED">;
|
|
1379
|
+
AUTHORIZE_REFERENCE_REQUIRED: better_auth.RawError<"AUTHORIZE_REFERENCE_REQUIRED">;
|
|
1380
|
+
ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION: better_auth.RawError<"ORGANIZATION_HAS_ACTIVE_SUBSCRIPTION">;
|
|
1381
|
+
ORGANIZATION_REFERENCE_ID_REQUIRED: better_auth.RawError<"ORGANIZATION_REFERENCE_ID_REQUIRED">;
|
|
1382
|
+
PRODUCT_NOT_FOUND: better_auth.RawError<"PRODUCT_NOT_FOUND">;
|
|
1383
|
+
PAYMENT_NOT_FOUND: better_auth.RawError<"PAYMENT_NOT_FOUND">;
|
|
1384
|
+
};
|
|
1385
|
+
};
|
|
1386
|
+
type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
|
|
1387
|
+
|
|
1388
|
+
export { type AuthorizeReferenceAction, type CustomerType, type InputPayment, type Payment, type PaymentAction, type StripeCtxSession, type StripeOptions, type StripePlan, type StripePlugin, type StripeProduct, type Subscription, type SubscriptionAction, type SubscriptionOptions, type WithActiveOrganizationId, type WithStripeCustomerId, stripe };
|