@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.
@@ -1,480 +0,0 @@
1
- import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
2
- import { Organization } from "better-auth/plugins/organization";
3
- import Stripe from "stripe";
4
-
5
- //#region src/schema.d.ts
6
- declare const subscriptions: {
7
- subscription: {
8
- fields: {
9
- plan: {
10
- type: "string";
11
- required: true;
12
- };
13
- referenceId: {
14
- type: "string";
15
- required: true;
16
- };
17
- stripeCustomerId: {
18
- type: "string";
19
- required: false;
20
- };
21
- stripeSubscriptionId: {
22
- type: "string";
23
- required: false;
24
- };
25
- status: {
26
- type: "string";
27
- defaultValue: string;
28
- };
29
- periodStart: {
30
- type: "date";
31
- required: false;
32
- };
33
- periodEnd: {
34
- type: "date";
35
- required: false;
36
- };
37
- trialStart: {
38
- type: "date";
39
- required: false;
40
- };
41
- trialEnd: {
42
- type: "date";
43
- required: false;
44
- };
45
- cancelAtPeriodEnd: {
46
- type: "boolean";
47
- required: false;
48
- defaultValue: false;
49
- };
50
- cancelAt: {
51
- type: "date";
52
- required: false;
53
- };
54
- canceledAt: {
55
- type: "date";
56
- required: false;
57
- };
58
- endedAt: {
59
- type: "date";
60
- required: false;
61
- };
62
- seats: {
63
- type: "number";
64
- required: false;
65
- };
66
- billingInterval: {
67
- type: "string";
68
- required: false;
69
- };
70
- stripeScheduleId: {
71
- type: "string";
72
- required: false;
73
- };
74
- };
75
- };
76
- };
77
- declare const user: {
78
- user: {
79
- fields: {
80
- stripeCustomerId: {
81
- type: "string";
82
- required: false;
83
- };
84
- };
85
- };
86
- };
87
- declare const organization: {
88
- organization: {
89
- fields: {
90
- stripeCustomerId: {
91
- type: "string";
92
- required: false;
93
- };
94
- };
95
- };
96
- };
97
- //#endregion
98
- //#region src/types.d.ts
99
- type AuthorizeReferenceAction = "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
100
- type CustomerType = "user" | "organization";
101
- type WithStripeCustomerId = {
102
- stripeCustomerId?: string;
103
- };
104
- type WithActiveOrganizationId = {
105
- activeOrganizationId?: string;
106
- };
107
- type StripeCtxSession = {
108
- session: Session & WithActiveOrganizationId;
109
- user: User & WithStripeCustomerId;
110
- };
111
- type StripePlan = {
112
- /**
113
- * Monthly price id
114
- */
115
- priceId?: string | undefined;
116
- /**
117
- * To use lookup key instead of price id
118
- *
119
- * https://docs.stripe.com/products-prices/
120
- * manage-prices#lookup-keys
121
- */
122
- lookupKey?: string | undefined;
123
- /**
124
- * A yearly discount price id
125
- *
126
- * useful when you want to offer a discount for
127
- * yearly subscription
128
- */
129
- annualDiscountPriceId?: string | undefined;
130
- /**
131
- * To use lookup key instead of price id
132
- *
133
- * https://docs.stripe.com/products-prices/
134
- * manage-prices#lookup-keys
135
- */
136
- annualDiscountLookupKey?: string | undefined;
137
- /**
138
- * Plan name
139
- */
140
- name: string;
141
- /**
142
- * Limits for the plan
143
- *
144
- * useful when you want to define plan-specific metadata.
145
- */
146
- limits?: Record<string, unknown> | undefined;
147
- /**
148
- * Plan group name
149
- *
150
- * useful when you want to group plans or
151
- * when a user can subscribe to multiple plans.
152
- */
153
- group?: string | undefined;
154
- /**
155
- * Per-seat billing price ID
156
- *
157
- * Requires the `organization` plugin. Member changes
158
- * automatically sync the seat quantity in Stripe.
159
- */
160
- seatPriceId?: string | undefined;
161
- /**
162
- * Additional line items to include in the checkout session.
163
- *
164
- * All line items must use the same billing interval as the base price (e.g. all monthly or all yearly).
165
- * Stripe does not support mixed-interval subscriptions via Checkout Sessions.
166
- *
167
- * @see https://docs.stripe.com/billing/subscriptions/mixed-interval#limitations
168
- */
169
- lineItems?: Stripe.Checkout.SessionCreateParams.LineItem[] | undefined;
170
- /**
171
- * Free trial days
172
- */
173
- freeTrial?: {
174
- /**
175
- * Number of days
176
- */
177
- days: number;
178
- /**
179
- * A function that will be called when the trial
180
- * starts.
181
- *
182
- * @param subscription
183
- * @returns
184
- */
185
- onTrialStart?: (subscription: Subscription) => Promise<void>;
186
- /**
187
- * A function that will be called when the trial
188
- * ends
189
- *
190
- * @param subscription - Subscription
191
- * @returns
192
- */
193
- onTrialEnd?: (data: {
194
- subscription: Subscription;
195
- }, ctx: GenericEndpointContext) => Promise<void>;
196
- /**
197
- * A function that will be called when the trial
198
- * expired.
199
- * @param subscription - Subscription
200
- * @returns
201
- */
202
- onTrialExpired?: (subscription: Subscription, ctx: GenericEndpointContext) => Promise<void>;
203
- } | undefined;
204
- };
205
- interface Subscription {
206
- /**
207
- * Database identifier
208
- */
209
- id: string;
210
- /**
211
- * The plan name
212
- */
213
- plan: string;
214
- /**
215
- * Stripe customer id
216
- */
217
- stripeCustomerId?: string | undefined;
218
- /**
219
- * Stripe subscription id
220
- */
221
- stripeSubscriptionId?: string | undefined;
222
- /**
223
- * Trial start date
224
- */
225
- trialStart?: Date | undefined;
226
- /**
227
- * Trial end date
228
- */
229
- trialEnd?: Date | undefined;
230
- /**
231
- * Price Id for the subscription
232
- */
233
- priceId?: string | undefined;
234
- /**
235
- * To what reference id the subscription belongs to
236
- * @example
237
- * - userId for a user
238
- * - workspace id for a saas platform
239
- * - website id for a hosting platform
240
- *
241
- * @default - userId
242
- */
243
- referenceId: string;
244
- /**
245
- * Subscription status
246
- */
247
- status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
248
- /**
249
- * The billing cycle start date
250
- */
251
- periodStart?: Date | undefined;
252
- /**
253
- * The billing cycle end date
254
- */
255
- periodEnd?: Date | undefined;
256
- /**
257
- * Whether this subscription will (if status=active)
258
- * or did (if status=canceled) cancel at the end of the current billing period.
259
- */
260
- cancelAtPeriodEnd?: boolean | undefined;
261
- /**
262
- * If the subscription is scheduled to be canceled,
263
- * this is the time at which the cancellation will take effect.
264
- */
265
- cancelAt?: Date | undefined;
266
- /**
267
- * If the subscription has been canceled, this is the time when it was canceled.
268
- *
269
- * Note: If the subscription was canceled with `cancel_at_period_end`,
270
- * this reflects the cancellation request time, not when the subscription actually ends.
271
- */
272
- canceledAt?: Date | undefined;
273
- /**
274
- * If the subscription has ended, the date the subscription ended.
275
- */
276
- endedAt?: Date | undefined;
277
- /**
278
- * A field to group subscriptions so you can have multiple subscriptions
279
- * for one reference id
280
- */
281
- groupId?: string | undefined;
282
- /**
283
- * Number of seats for the subscription (useful for team plans)
284
- */
285
- seats?: number | undefined;
286
- /**
287
- * The billing interval for this subscription.
288
- * Indicates how often the subscription is billed.
289
- * @see https://docs.stripe.com/api/plans/object#plan_object-interval
290
- */
291
- billingInterval?: "day" | "week" | "month" | "year" | undefined;
292
- /**
293
- * Stripe Subscription Schedule ID, present when a scheduled
294
- * plan change is pending for this subscription.
295
- */
296
- stripeScheduleId?: string | undefined;
297
- }
298
- type SubscriptionOptions = {
299
- /**
300
- * Subscription Configuration
301
- */
302
- /**
303
- * List of plan
304
- */
305
- plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
306
- /**
307
- * Require email verification before a user is allowed to upgrade
308
- * their subscriptions
309
- *
310
- * @default false
311
- */
312
- requireEmailVerification?: boolean | undefined;
313
- /**
314
- * A callback to run after a user has subscribed to a package
315
- * @param event - Stripe Event
316
- * @param subscription - Subscription Data
317
- * @returns
318
- */
319
- onSubscriptionComplete?: ((data: {
320
- event: Stripe.Event;
321
- stripeSubscription: Stripe.Subscription;
322
- subscription: Subscription;
323
- plan: StripePlan;
324
- }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
325
- /**
326
- * A callback to run after a user is about to cancel their subscription
327
- * @returns
328
- */
329
- onSubscriptionUpdate?: ((data: {
330
- event: Stripe.Event;
331
- subscription: Subscription;
332
- }) => Promise<void>) | undefined;
333
- /**
334
- * A callback to run after a user is about to cancel their subscription
335
- * @returns
336
- */
337
- onSubscriptionCancel?: ((data: {
338
- event?: Stripe.Event;
339
- subscription: Subscription;
340
- stripeSubscription: Stripe.Subscription;
341
- cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
342
- }) => Promise<void>) | undefined;
343
- /**
344
- * A function to check if the reference id is valid
345
- * and belongs to the user
346
- *
347
- * @param data - data containing user, session and referenceId
348
- * @param ctx - the context object
349
- * @returns
350
- */
351
- authorizeReference?: ((data: {
352
- user: User & Record<string, any>;
353
- session: Session & Record<string, any>;
354
- referenceId: string;
355
- action: AuthorizeReferenceAction;
356
- }, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
357
- /**
358
- * A callback to run after a user has deleted their subscription
359
- * @returns
360
- */
361
- onSubscriptionDeleted?: ((data: {
362
- event: Stripe.Event;
363
- stripeSubscription: Stripe.Subscription;
364
- subscription: Subscription;
365
- }) => Promise<void>) | undefined;
366
- /**
367
- * A callback to run when a subscription is created
368
- * @returns
369
- */
370
- onSubscriptionCreated?: ((data: {
371
- event: Stripe.Event;
372
- stripeSubscription: Stripe.Subscription;
373
- subscription: Subscription;
374
- plan: StripePlan;
375
- }) => Promise<void>) | undefined;
376
- /**
377
- * parameters for session create params
378
- *
379
- * @param data - data containing user, session and plan
380
- * @param req - the request object
381
- * @param ctx - the context object
382
- */
383
- getCheckoutSessionParams?: ((data: {
384
- user: User & Record<string, any>;
385
- session: Session & Record<string, any>;
386
- plan: StripePlan;
387
- subscription: Subscription;
388
- }, req: GenericEndpointContext["request"], ctx: GenericEndpointContext) => Promise<{
389
- params?: Stripe.Checkout.SessionCreateParams;
390
- options?: Stripe.RequestOptions;
391
- }> | {
392
- params?: Stripe.Checkout.SessionCreateParams;
393
- options?: Stripe.RequestOptions;
394
- }) | undefined;
395
- };
396
- interface StripeOptions {
397
- /**
398
- * Stripe Client
399
- */
400
- stripeClient: Stripe;
401
- /**
402
- * Stripe Webhook Secret
403
- *
404
- * @description Stripe webhook secret key
405
- */
406
- stripeWebhookSecret: string;
407
- /**
408
- * Enable customer creation when a user signs up
409
- */
410
- createCustomerOnSignUp?: boolean | undefined;
411
- /**
412
- * A callback to run after a customer has been created
413
- * @param customer - Customer Data
414
- * @param stripeCustomer - Stripe Customer Data
415
- * @returns
416
- */
417
- onCustomerCreate?: ((data: {
418
- stripeCustomer: Stripe.Customer;
419
- user: User & WithStripeCustomerId;
420
- }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
421
- /**
422
- * A custom function to get the customer create
423
- * params
424
- * @param data - data containing user and session
425
- * @returns
426
- */
427
- getCustomerCreateParams?: ((user: User, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
428
- /**
429
- * Subscriptions
430
- */
431
- subscription?: ({
432
- enabled: false;
433
- } | ({
434
- enabled: true;
435
- } & SubscriptionOptions)) | undefined;
436
- /**
437
- * Organization Stripe integration
438
- *
439
- * Enable organizations to have their own Stripe customer ID
440
- */
441
- organization?: {
442
- /**
443
- * Enable organization Stripe customer
444
- */
445
- enabled: true;
446
- /**
447
- * A custom function to get the customer create params
448
- * for organization customers.
449
- *
450
- * @param organization - the organization
451
- * @param ctx - the context object
452
- * @returns
453
- */
454
- getCustomerCreateParams?: ((organization: Organization, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
455
- /**
456
- * A callback to run after an organization customer has been created
457
- *
458
- * @param data - data containing stripeCustomer and organization
459
- * @param ctx - the context object
460
- * @returns
461
- */
462
- onCustomerCreate?: ((data: {
463
- stripeCustomer: Stripe.Customer;
464
- organization: Organization & WithStripeCustomerId;
465
- }, ctx: GenericEndpointContext) => Promise<void>) | undefined;
466
- } | undefined;
467
- /**
468
- * A callback to run after a stripe event is received
469
- * @param event - Stripe Event
470
- * @returns
471
- */
472
- onEvent?: ((event: Stripe.Event) => Promise<void>) | undefined;
473
- /**
474
- * Schema for the stripe plugin
475
- */
476
- schema?: InferOptionSchema<typeof subscriptions & typeof user & typeof organization> | undefined;
477
- }
478
- //#endregion
479
- export { StripePlan as a, WithActiveOrganizationId as c, StripeOptions as i, WithStripeCustomerId as l, CustomerType as n, Subscription as o, StripeCtxSession as r, SubscriptionOptions as s, AuthorizeReferenceAction as t };
480
- //# sourceMappingURL=types-OT6L84x4.d.mts.map