@better-auth/stripe 1.4.4-beta.1 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/dist/client.d.mts +1 -1
- package/dist/index-aXzLoFtK.d.mts +807 -0
- package/dist/index.d.mts +2 -2
- package/package.json +7 -8
- package/src/index.ts +1 -1
- package/dist/index-5aJ_8K6g.d.mts +0 -465
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/stripe@1.4.4
|
|
2
|
+
> @better-auth/stripe@1.4.4 build /home/runner/work/better-auth/better-auth/packages/stripe
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
|
-
[34mℹ[39m tsdown [2mv0.16.
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.16.5[22m powered by rolldown [2mv1.0.0-beta.50[22m
|
|
6
6
|
[34mℹ[39m Using tsdown config: [4m/home/runner/work/better-auth/better-auth/packages/stripe/tsdown.config.ts[24m
|
|
7
7
|
[34mℹ[39m entry: [34msrc/index.ts, src/client.ts[39m
|
|
8
8
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m37.60 kB[22m [2m│ gzip: 7.24 kB[22m
|
|
11
11
|
[34mℹ[39m [2mdist/[22m[1mclient.mjs[22m [2m 0.26 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
12
12
|
[34mℹ[39m [2mdist/[22m[32m[1mclient.d.mts[22m[39m [2m 0.62 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[32mindex-
|
|
15
|
-
[34mℹ[39m 5 files, total:
|
|
16
|
-
[32m✔[39m Build complete in [
|
|
13
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.17 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[32mindex-aXzLoFtK.d.mts[39m [2m26.02 kB[22m [2m│ gzip: 5.01 kB[22m
|
|
15
|
+
[34mℹ[39m 5 files, total: 64.67 kB
|
|
16
|
+
[32m✔[39m Build complete in [32m12463ms[39m
|
package/dist/client.d.mts
CHANGED
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import * as better_auth0 from "better-auth";
|
|
2
|
+
import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
|
|
3
|
+
import * as z from "zod/v4";
|
|
4
|
+
import * as better_call0 from "better-call";
|
|
5
|
+
import Stripe from "stripe";
|
|
6
|
+
|
|
7
|
+
//#region src/schema.d.ts
|
|
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
|
+
seats: {
|
|
53
|
+
type: "number";
|
|
54
|
+
required: false;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
declare const user: {
|
|
60
|
+
user: {
|
|
61
|
+
fields: {
|
|
62
|
+
stripeCustomerId: {
|
|
63
|
+
type: "string";
|
|
64
|
+
required: false;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/types.d.ts
|
|
71
|
+
type StripePlan = {
|
|
72
|
+
/**
|
|
73
|
+
* Monthly price id
|
|
74
|
+
*/
|
|
75
|
+
priceId?: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* To use lookup key instead of price id
|
|
78
|
+
*
|
|
79
|
+
* https://docs.stripe.com/products-prices/
|
|
80
|
+
* manage-prices#lookup-keys
|
|
81
|
+
*/
|
|
82
|
+
lookupKey?: string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* A yearly discount price id
|
|
85
|
+
*
|
|
86
|
+
* useful when you want to offer a discount for
|
|
87
|
+
* yearly subscription
|
|
88
|
+
*/
|
|
89
|
+
annualDiscountPriceId?: string | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* To use lookup key instead of price id
|
|
92
|
+
*
|
|
93
|
+
* https://docs.stripe.com/products-prices/
|
|
94
|
+
* manage-prices#lookup-keys
|
|
95
|
+
*/
|
|
96
|
+
annualDiscountLookupKey?: string | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Plan name
|
|
99
|
+
*/
|
|
100
|
+
name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Limits for the plan
|
|
103
|
+
*
|
|
104
|
+
* useful when you want to define plan-specific metadata.
|
|
105
|
+
*/
|
|
106
|
+
limits?: Record<string, unknown> | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Plan group name
|
|
109
|
+
*
|
|
110
|
+
* useful when you want to group plans or
|
|
111
|
+
* when a user can subscribe to multiple plans.
|
|
112
|
+
*/
|
|
113
|
+
group?: string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Free trial days
|
|
116
|
+
*/
|
|
117
|
+
freeTrial?: {
|
|
118
|
+
/**
|
|
119
|
+
* Number of days
|
|
120
|
+
*/
|
|
121
|
+
days: number;
|
|
122
|
+
/**
|
|
123
|
+
* A function that will be called when the trial
|
|
124
|
+
* starts.
|
|
125
|
+
*
|
|
126
|
+
* @param subscription
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
onTrialStart?: (subscription: Subscription) => Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* A function that will be called when the trial
|
|
132
|
+
* ends
|
|
133
|
+
*
|
|
134
|
+
* @param subscription - Subscription
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
onTrialEnd?: (data: {
|
|
138
|
+
subscription: Subscription;
|
|
139
|
+
}, ctx: GenericEndpointContext) => Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* A function that will be called when the trial
|
|
142
|
+
* expired.
|
|
143
|
+
* @param subscription - Subscription
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
onTrialExpired?: (subscription: Subscription, ctx: GenericEndpointContext) => Promise<void>;
|
|
147
|
+
} | undefined;
|
|
148
|
+
};
|
|
149
|
+
interface Subscription {
|
|
150
|
+
/**
|
|
151
|
+
* Database identifier
|
|
152
|
+
*/
|
|
153
|
+
id: string;
|
|
154
|
+
/**
|
|
155
|
+
* The plan name
|
|
156
|
+
*/
|
|
157
|
+
plan: string;
|
|
158
|
+
/**
|
|
159
|
+
* Stripe customer id
|
|
160
|
+
*/
|
|
161
|
+
stripeCustomerId?: string | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Stripe subscription id
|
|
164
|
+
*/
|
|
165
|
+
stripeSubscriptionId?: string | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Trial start date
|
|
168
|
+
*/
|
|
169
|
+
trialStart?: Date | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Trial end date
|
|
172
|
+
*/
|
|
173
|
+
trialEnd?: Date | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Price Id for the subscription
|
|
176
|
+
*/
|
|
177
|
+
priceId?: string | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* To what reference id the subscription belongs to
|
|
180
|
+
* @example
|
|
181
|
+
* - userId for a user
|
|
182
|
+
* - workspace id for a saas platform
|
|
183
|
+
* - website id for a hosting platform
|
|
184
|
+
*
|
|
185
|
+
* @default - userId
|
|
186
|
+
*/
|
|
187
|
+
referenceId: string;
|
|
188
|
+
/**
|
|
189
|
+
* Subscription status
|
|
190
|
+
*/
|
|
191
|
+
status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
|
|
192
|
+
/**
|
|
193
|
+
* The billing cycle start date
|
|
194
|
+
*/
|
|
195
|
+
periodStart?: Date | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* The billing cycle end date
|
|
198
|
+
*/
|
|
199
|
+
periodEnd?: Date | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Cancel at period end
|
|
202
|
+
*/
|
|
203
|
+
cancelAtPeriodEnd?: boolean | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* A field to group subscriptions so you can have multiple subscriptions
|
|
206
|
+
* for one reference id
|
|
207
|
+
*/
|
|
208
|
+
groupId?: string | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Number of seats for the subscription (useful for team plans)
|
|
211
|
+
*/
|
|
212
|
+
seats?: number | undefined;
|
|
213
|
+
}
|
|
214
|
+
type SubscriptionOptions = {
|
|
215
|
+
/**
|
|
216
|
+
* Subscription Configuration
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* List of plan
|
|
220
|
+
*/
|
|
221
|
+
plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
|
|
222
|
+
/**
|
|
223
|
+
* Require email verification before a user is allowed to upgrade
|
|
224
|
+
* their subscriptions
|
|
225
|
+
*
|
|
226
|
+
* @default false
|
|
227
|
+
*/
|
|
228
|
+
requireEmailVerification?: boolean | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* A callback to run after a user has subscribed to a package
|
|
231
|
+
* @param event - Stripe Event
|
|
232
|
+
* @param subscription - Subscription Data
|
|
233
|
+
* @returns
|
|
234
|
+
*/
|
|
235
|
+
onSubscriptionComplete?: ((data: {
|
|
236
|
+
event: Stripe.Event;
|
|
237
|
+
stripeSubscription: Stripe.Subscription;
|
|
238
|
+
subscription: Subscription;
|
|
239
|
+
plan: StripePlan;
|
|
240
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* A callback to run after a user is about to cancel their subscription
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
onSubscriptionUpdate?: ((data: {
|
|
246
|
+
event: Stripe.Event;
|
|
247
|
+
subscription: Subscription;
|
|
248
|
+
}) => Promise<void>) | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* A callback to run after a user is about to cancel their subscription
|
|
251
|
+
* @returns
|
|
252
|
+
*/
|
|
253
|
+
onSubscriptionCancel?: ((data: {
|
|
254
|
+
event?: Stripe.Event;
|
|
255
|
+
subscription: Subscription;
|
|
256
|
+
stripeSubscription: Stripe.Subscription;
|
|
257
|
+
cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
|
|
258
|
+
}) => Promise<void>) | undefined;
|
|
259
|
+
/**
|
|
260
|
+
* A function to check if the reference id is valid
|
|
261
|
+
* and belongs to the user
|
|
262
|
+
*
|
|
263
|
+
* @param data - data containing user, session and referenceId
|
|
264
|
+
* @param ctx - the context object
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
authorizeReference?: ((data: {
|
|
268
|
+
user: User & Record<string, any>;
|
|
269
|
+
session: Session & Record<string, any>;
|
|
270
|
+
referenceId: string;
|
|
271
|
+
action: "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
|
|
272
|
+
}, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* A callback to run after a user has deleted their subscription
|
|
275
|
+
* @returns
|
|
276
|
+
*/
|
|
277
|
+
onSubscriptionDeleted?: ((data: {
|
|
278
|
+
event: Stripe.Event;
|
|
279
|
+
stripeSubscription: Stripe.Subscription;
|
|
280
|
+
subscription: Subscription;
|
|
281
|
+
}) => Promise<void>) | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* parameters for session create params
|
|
284
|
+
*
|
|
285
|
+
* @param data - data containing user, session and plan
|
|
286
|
+
* @param req - the request object
|
|
287
|
+
* @param ctx - the context object
|
|
288
|
+
*/
|
|
289
|
+
getCheckoutSessionParams?: ((data: {
|
|
290
|
+
user: User & Record<string, any>;
|
|
291
|
+
session: Session & Record<string, any>;
|
|
292
|
+
plan: StripePlan;
|
|
293
|
+
subscription: Subscription;
|
|
294
|
+
}, req: GenericEndpointContext["request"], ctx: GenericEndpointContext) => Promise<{
|
|
295
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
296
|
+
options?: Stripe.RequestOptions;
|
|
297
|
+
}> | {
|
|
298
|
+
params?: Stripe.Checkout.SessionCreateParams;
|
|
299
|
+
options?: Stripe.RequestOptions;
|
|
300
|
+
}) | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Enable organization subscription
|
|
303
|
+
*/
|
|
304
|
+
organization?: {
|
|
305
|
+
enabled: boolean;
|
|
306
|
+
} | undefined;
|
|
307
|
+
};
|
|
308
|
+
interface StripeOptions {
|
|
309
|
+
/**
|
|
310
|
+
* Stripe Client
|
|
311
|
+
*/
|
|
312
|
+
stripeClient: Stripe;
|
|
313
|
+
/**
|
|
314
|
+
* Stripe Webhook Secret
|
|
315
|
+
*
|
|
316
|
+
* @description Stripe webhook secret key
|
|
317
|
+
*/
|
|
318
|
+
stripeWebhookSecret: string;
|
|
319
|
+
/**
|
|
320
|
+
* Enable customer creation when a user signs up
|
|
321
|
+
*/
|
|
322
|
+
createCustomerOnSignUp?: boolean | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* A callback to run after a customer has been created
|
|
325
|
+
* @param customer - Customer Data
|
|
326
|
+
* @param stripeCustomer - Stripe Customer Data
|
|
327
|
+
* @returns
|
|
328
|
+
*/
|
|
329
|
+
onCustomerCreate?: ((data: {
|
|
330
|
+
stripeCustomer: Stripe.Customer;
|
|
331
|
+
user: User & {
|
|
332
|
+
stripeCustomerId: string;
|
|
333
|
+
};
|
|
334
|
+
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
335
|
+
/**
|
|
336
|
+
* A custom function to get the customer create
|
|
337
|
+
* params
|
|
338
|
+
* @param data - data containing user and session
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
341
|
+
getCustomerCreateParams?: ((user: User, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Subscriptions
|
|
344
|
+
*/
|
|
345
|
+
subscription?: ({
|
|
346
|
+
enabled: false;
|
|
347
|
+
} | ({
|
|
348
|
+
enabled: true;
|
|
349
|
+
} & SubscriptionOptions)) | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* A callback to run after a stripe event is received
|
|
352
|
+
* @param event - Stripe Event
|
|
353
|
+
* @returns
|
|
354
|
+
*/
|
|
355
|
+
onEvent?: ((event: Stripe.Event) => Promise<void>) | undefined;
|
|
356
|
+
/**
|
|
357
|
+
* Schema for the stripe plugin
|
|
358
|
+
*/
|
|
359
|
+
schema?: InferOptionSchema<typeof subscriptions & typeof user> | undefined;
|
|
360
|
+
}
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/index.d.ts
|
|
363
|
+
declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
364
|
+
id: "stripe";
|
|
365
|
+
endpoints: {
|
|
366
|
+
stripeWebhook: better_call0.StrictEndpoint<"/stripe/webhook", {
|
|
367
|
+
method: "POST";
|
|
368
|
+
metadata: {
|
|
369
|
+
isAction: false;
|
|
370
|
+
openapi: {
|
|
371
|
+
operationId: string;
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
cloneRequest: true;
|
|
375
|
+
disableBody: true;
|
|
376
|
+
} & {
|
|
377
|
+
use: any[];
|
|
378
|
+
}, {
|
|
379
|
+
success: boolean;
|
|
380
|
+
}>;
|
|
381
|
+
} & (O["subscription"] extends {
|
|
382
|
+
enabled: true;
|
|
383
|
+
} ? {
|
|
384
|
+
/**
|
|
385
|
+
* ### Endpoint
|
|
386
|
+
*
|
|
387
|
+
* POST `/subscription/upgrade`
|
|
388
|
+
*
|
|
389
|
+
* ### API Methods
|
|
390
|
+
*
|
|
391
|
+
* **server:**
|
|
392
|
+
* `auth.api.upgradeSubscription`
|
|
393
|
+
*
|
|
394
|
+
* **client:**
|
|
395
|
+
* `authClient.subscription.upgrade`
|
|
396
|
+
*
|
|
397
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-upgrade)
|
|
398
|
+
*/
|
|
399
|
+
readonly upgradeSubscription: better_call0.StrictEndpoint<"/subscription/upgrade", {
|
|
400
|
+
method: "POST";
|
|
401
|
+
body: z.ZodObject<{
|
|
402
|
+
plan: z.ZodString;
|
|
403
|
+
annual: z.ZodOptional<z.ZodBoolean>;
|
|
404
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
405
|
+
subscriptionId: z.ZodOptional<z.ZodString>;
|
|
406
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
407
|
+
seats: z.ZodOptional<z.ZodNumber>;
|
|
408
|
+
successUrl: z.ZodDefault<z.ZodString>;
|
|
409
|
+
cancelUrl: z.ZodDefault<z.ZodString>;
|
|
410
|
+
returnUrl: z.ZodOptional<z.ZodString>;
|
|
411
|
+
disableRedirect: z.ZodDefault<z.ZodBoolean>;
|
|
412
|
+
}, z.core.$strip>;
|
|
413
|
+
metadata: {
|
|
414
|
+
openapi: {
|
|
415
|
+
operationId: string;
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
419
|
+
session: {
|
|
420
|
+
session: Record<string, any> & {
|
|
421
|
+
id: string;
|
|
422
|
+
createdAt: Date;
|
|
423
|
+
updatedAt: Date;
|
|
424
|
+
userId: string;
|
|
425
|
+
expiresAt: Date;
|
|
426
|
+
token: string;
|
|
427
|
+
ipAddress?: string | null | undefined;
|
|
428
|
+
userAgent?: string | null | undefined;
|
|
429
|
+
};
|
|
430
|
+
user: Record<string, any> & {
|
|
431
|
+
id: string;
|
|
432
|
+
createdAt: Date;
|
|
433
|
+
updatedAt: Date;
|
|
434
|
+
email: string;
|
|
435
|
+
emailVerified: boolean;
|
|
436
|
+
name: string;
|
|
437
|
+
image?: string | null | undefined;
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
441
|
+
} & {
|
|
442
|
+
use: any[];
|
|
443
|
+
}, {
|
|
444
|
+
url: string;
|
|
445
|
+
redirect: boolean;
|
|
446
|
+
} | {
|
|
447
|
+
redirect: boolean;
|
|
448
|
+
id: string;
|
|
449
|
+
object: "checkout.session";
|
|
450
|
+
adaptive_pricing: Stripe.Checkout.Session.AdaptivePricing | null;
|
|
451
|
+
after_expiration: Stripe.Checkout.Session.AfterExpiration | null;
|
|
452
|
+
allow_promotion_codes: boolean | null;
|
|
453
|
+
amount_subtotal: number | null;
|
|
454
|
+
amount_total: number | null;
|
|
455
|
+
automatic_tax: Stripe.Checkout.Session.AutomaticTax;
|
|
456
|
+
billing_address_collection: Stripe.Checkout.Session.BillingAddressCollection | null;
|
|
457
|
+
branding_settings?: Stripe.Checkout.Session.BrandingSettings;
|
|
458
|
+
cancel_url: string | null;
|
|
459
|
+
client_reference_id: string | null;
|
|
460
|
+
client_secret: string | null;
|
|
461
|
+
collected_information: Stripe.Checkout.Session.CollectedInformation | null;
|
|
462
|
+
consent: Stripe.Checkout.Session.Consent | null;
|
|
463
|
+
consent_collection: Stripe.Checkout.Session.ConsentCollection | null;
|
|
464
|
+
created: number;
|
|
465
|
+
currency: string | null;
|
|
466
|
+
currency_conversion: Stripe.Checkout.Session.CurrencyConversion | null;
|
|
467
|
+
custom_fields: Array<Stripe.Checkout.Session.CustomField>;
|
|
468
|
+
custom_text: Stripe.Checkout.Session.CustomText;
|
|
469
|
+
customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
|
|
470
|
+
customer_creation: Stripe.Checkout.Session.CustomerCreation | null;
|
|
471
|
+
customer_details: Stripe.Checkout.Session.CustomerDetails | null;
|
|
472
|
+
customer_email: string | null;
|
|
473
|
+
discounts: Array<Stripe.Checkout.Session.Discount> | null;
|
|
474
|
+
excluded_payment_method_types?: Array<string>;
|
|
475
|
+
expires_at: number;
|
|
476
|
+
invoice: string | Stripe.Invoice | null;
|
|
477
|
+
invoice_creation: Stripe.Checkout.Session.InvoiceCreation | null;
|
|
478
|
+
line_items?: Stripe.ApiList<Stripe.LineItem>;
|
|
479
|
+
livemode: boolean;
|
|
480
|
+
locale: Stripe.Checkout.Session.Locale | null;
|
|
481
|
+
metadata: Stripe.Metadata | null;
|
|
482
|
+
mode: Stripe.Checkout.Session.Mode;
|
|
483
|
+
name_collection?: Stripe.Checkout.Session.NameCollection;
|
|
484
|
+
optional_items?: Array<Stripe.Checkout.Session.OptionalItem> | null;
|
|
485
|
+
origin_context: Stripe.Checkout.Session.OriginContext | null;
|
|
486
|
+
payment_intent: string | Stripe.PaymentIntent | null;
|
|
487
|
+
payment_link: string | Stripe.PaymentLink | null;
|
|
488
|
+
payment_method_collection: Stripe.Checkout.Session.PaymentMethodCollection | null;
|
|
489
|
+
payment_method_configuration_details: Stripe.Checkout.Session.PaymentMethodConfigurationDetails | null;
|
|
490
|
+
payment_method_options: Stripe.Checkout.Session.PaymentMethodOptions | null;
|
|
491
|
+
payment_method_types: Array<string>;
|
|
492
|
+
payment_status: Stripe.Checkout.Session.PaymentStatus;
|
|
493
|
+
permissions: Stripe.Checkout.Session.Permissions | null;
|
|
494
|
+
phone_number_collection?: Stripe.Checkout.Session.PhoneNumberCollection;
|
|
495
|
+
presentment_details?: Stripe.Checkout.Session.PresentmentDetails;
|
|
496
|
+
recovered_from: string | null;
|
|
497
|
+
redirect_on_completion?: Stripe.Checkout.Session.RedirectOnCompletion;
|
|
498
|
+
return_url?: string;
|
|
499
|
+
saved_payment_method_options: Stripe.Checkout.Session.SavedPaymentMethodOptions | null;
|
|
500
|
+
setup_intent: string | Stripe.SetupIntent | null;
|
|
501
|
+
shipping_address_collection: Stripe.Checkout.Session.ShippingAddressCollection | null;
|
|
502
|
+
shipping_cost: Stripe.Checkout.Session.ShippingCost | null;
|
|
503
|
+
shipping_options: Array<Stripe.Checkout.Session.ShippingOption>;
|
|
504
|
+
status: Stripe.Checkout.Session.Status | null;
|
|
505
|
+
submit_type: Stripe.Checkout.Session.SubmitType | null;
|
|
506
|
+
subscription: string | Stripe.Subscription | null;
|
|
507
|
+
success_url: string | null;
|
|
508
|
+
tax_id_collection?: Stripe.Checkout.Session.TaxIdCollection;
|
|
509
|
+
total_details: Stripe.Checkout.Session.TotalDetails | null;
|
|
510
|
+
ui_mode: Stripe.Checkout.Session.UiMode | null;
|
|
511
|
+
url: string | null;
|
|
512
|
+
wallet_options: Stripe.Checkout.Session.WalletOptions | null;
|
|
513
|
+
lastResponse: {
|
|
514
|
+
headers: {
|
|
515
|
+
[key: string]: string;
|
|
516
|
+
};
|
|
517
|
+
requestId: string;
|
|
518
|
+
statusCode: number;
|
|
519
|
+
apiVersion?: string;
|
|
520
|
+
idempotencyKey?: string;
|
|
521
|
+
stripeAccount?: string;
|
|
522
|
+
};
|
|
523
|
+
}>;
|
|
524
|
+
readonly cancelSubscriptionCallback: better_call0.StrictEndpoint<"/subscription/cancel/callback", {
|
|
525
|
+
method: "GET";
|
|
526
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
527
|
+
metadata: {
|
|
528
|
+
openapi: {
|
|
529
|
+
operationId: string;
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
533
|
+
} & {
|
|
534
|
+
use: any[];
|
|
535
|
+
}, never>;
|
|
536
|
+
/**
|
|
537
|
+
* ### Endpoint
|
|
538
|
+
*
|
|
539
|
+
* POST `/subscription/cancel`
|
|
540
|
+
*
|
|
541
|
+
* ### API Methods
|
|
542
|
+
*
|
|
543
|
+
* **server:**
|
|
544
|
+
* `auth.api.cancelSubscription`
|
|
545
|
+
*
|
|
546
|
+
* **client:**
|
|
547
|
+
* `authClient.subscription.cancel`
|
|
548
|
+
*
|
|
549
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-cancel)
|
|
550
|
+
*/
|
|
551
|
+
readonly cancelSubscription: better_call0.StrictEndpoint<"/subscription/cancel", {
|
|
552
|
+
method: "POST";
|
|
553
|
+
body: z.ZodObject<{
|
|
554
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
555
|
+
subscriptionId: z.ZodOptional<z.ZodString>;
|
|
556
|
+
returnUrl: z.ZodString;
|
|
557
|
+
}, z.core.$strip>;
|
|
558
|
+
metadata: {
|
|
559
|
+
openapi: {
|
|
560
|
+
operationId: string;
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
564
|
+
session: {
|
|
565
|
+
session: Record<string, any> & {
|
|
566
|
+
id: string;
|
|
567
|
+
createdAt: Date;
|
|
568
|
+
updatedAt: Date;
|
|
569
|
+
userId: string;
|
|
570
|
+
expiresAt: Date;
|
|
571
|
+
token: string;
|
|
572
|
+
ipAddress?: string | null | undefined;
|
|
573
|
+
userAgent?: string | null | undefined;
|
|
574
|
+
};
|
|
575
|
+
user: Record<string, any> & {
|
|
576
|
+
id: string;
|
|
577
|
+
createdAt: Date;
|
|
578
|
+
updatedAt: Date;
|
|
579
|
+
email: string;
|
|
580
|
+
emailVerified: boolean;
|
|
581
|
+
name: string;
|
|
582
|
+
image?: string | null | undefined;
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
586
|
+
} & {
|
|
587
|
+
use: any[];
|
|
588
|
+
}, {
|
|
589
|
+
url: string;
|
|
590
|
+
redirect: boolean;
|
|
591
|
+
}>;
|
|
592
|
+
readonly restoreSubscription: better_call0.StrictEndpoint<"/subscription/restore", {
|
|
593
|
+
method: "POST";
|
|
594
|
+
body: z.ZodObject<{
|
|
595
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
596
|
+
subscriptionId: z.ZodOptional<z.ZodString>;
|
|
597
|
+
}, z.core.$strip>;
|
|
598
|
+
metadata: {
|
|
599
|
+
openapi: {
|
|
600
|
+
operationId: string;
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
604
|
+
session: {
|
|
605
|
+
session: Record<string, any> & {
|
|
606
|
+
id: string;
|
|
607
|
+
createdAt: Date;
|
|
608
|
+
updatedAt: Date;
|
|
609
|
+
userId: string;
|
|
610
|
+
expiresAt: Date;
|
|
611
|
+
token: string;
|
|
612
|
+
ipAddress?: string | null | undefined;
|
|
613
|
+
userAgent?: string | null | undefined;
|
|
614
|
+
};
|
|
615
|
+
user: Record<string, any> & {
|
|
616
|
+
id: string;
|
|
617
|
+
createdAt: Date;
|
|
618
|
+
updatedAt: Date;
|
|
619
|
+
email: string;
|
|
620
|
+
emailVerified: boolean;
|
|
621
|
+
name: string;
|
|
622
|
+
image?: string | null | undefined;
|
|
623
|
+
};
|
|
624
|
+
};
|
|
625
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
626
|
+
} & {
|
|
627
|
+
use: any[];
|
|
628
|
+
}, Stripe.Response<Stripe.Subscription>>;
|
|
629
|
+
/**
|
|
630
|
+
* ### Endpoint
|
|
631
|
+
*
|
|
632
|
+
* GET `/subscription/list`
|
|
633
|
+
*
|
|
634
|
+
* ### API Methods
|
|
635
|
+
*
|
|
636
|
+
* **server:**
|
|
637
|
+
* `auth.api.listActiveSubscriptions`
|
|
638
|
+
*
|
|
639
|
+
* **client:**
|
|
640
|
+
* `authClient.subscription.list`
|
|
641
|
+
*
|
|
642
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-list)
|
|
643
|
+
*/
|
|
644
|
+
readonly listActiveSubscriptions: better_call0.StrictEndpoint<"/subscription/list", {
|
|
645
|
+
method: "GET";
|
|
646
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
647
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
648
|
+
}, z.core.$strip>>;
|
|
649
|
+
metadata: {
|
|
650
|
+
openapi: {
|
|
651
|
+
operationId: string;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
655
|
+
session: {
|
|
656
|
+
session: Record<string, any> & {
|
|
657
|
+
id: string;
|
|
658
|
+
createdAt: Date;
|
|
659
|
+
updatedAt: Date;
|
|
660
|
+
userId: string;
|
|
661
|
+
expiresAt: Date;
|
|
662
|
+
token: string;
|
|
663
|
+
ipAddress?: string | null | undefined;
|
|
664
|
+
userAgent?: string | null | undefined;
|
|
665
|
+
};
|
|
666
|
+
user: Record<string, any> & {
|
|
667
|
+
id: string;
|
|
668
|
+
createdAt: Date;
|
|
669
|
+
updatedAt: Date;
|
|
670
|
+
email: string;
|
|
671
|
+
emailVerified: boolean;
|
|
672
|
+
name: string;
|
|
673
|
+
image?: string | null | undefined;
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
677
|
+
} & {
|
|
678
|
+
use: any[];
|
|
679
|
+
}, {
|
|
680
|
+
limits: Record<string, unknown> | undefined;
|
|
681
|
+
priceId: string | undefined;
|
|
682
|
+
id: string;
|
|
683
|
+
plan: string;
|
|
684
|
+
stripeCustomerId?: string | undefined;
|
|
685
|
+
stripeSubscriptionId?: string | undefined;
|
|
686
|
+
trialStart?: Date | undefined;
|
|
687
|
+
trialEnd?: Date | undefined;
|
|
688
|
+
referenceId: string;
|
|
689
|
+
status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
|
|
690
|
+
periodStart?: Date | undefined;
|
|
691
|
+
periodEnd?: Date | undefined;
|
|
692
|
+
cancelAtPeriodEnd?: boolean | undefined;
|
|
693
|
+
groupId?: string | undefined;
|
|
694
|
+
seats?: number | undefined;
|
|
695
|
+
}[]>;
|
|
696
|
+
readonly subscriptionSuccess: better_call0.StrictEndpoint<"/subscription/success", {
|
|
697
|
+
method: "GET";
|
|
698
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
699
|
+
metadata: {
|
|
700
|
+
openapi: {
|
|
701
|
+
operationId: string;
|
|
702
|
+
};
|
|
703
|
+
};
|
|
704
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
705
|
+
} & {
|
|
706
|
+
use: any[];
|
|
707
|
+
}, {
|
|
708
|
+
status: ("NOT_FOUND" | "FOUND" | "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call0.Status;
|
|
709
|
+
body: ({
|
|
710
|
+
message?: string;
|
|
711
|
+
code?: string;
|
|
712
|
+
cause?: unknown;
|
|
713
|
+
} & Record<string, any>) | undefined;
|
|
714
|
+
headers: HeadersInit;
|
|
715
|
+
statusCode: number;
|
|
716
|
+
name: string;
|
|
717
|
+
message: string;
|
|
718
|
+
stack?: string;
|
|
719
|
+
cause?: unknown;
|
|
720
|
+
}>;
|
|
721
|
+
readonly createBillingPortal: better_call0.StrictEndpoint<"/subscription/billing-portal", {
|
|
722
|
+
method: "POST";
|
|
723
|
+
body: z.ZodObject<{
|
|
724
|
+
locale: z.ZodOptional<z.ZodCustom<Stripe.Checkout.Session.Locale, Stripe.Checkout.Session.Locale>>;
|
|
725
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
726
|
+
returnUrl: z.ZodDefault<z.ZodString>;
|
|
727
|
+
}, z.core.$strip>;
|
|
728
|
+
metadata: {
|
|
729
|
+
openapi: {
|
|
730
|
+
operationId: string;
|
|
731
|
+
};
|
|
732
|
+
};
|
|
733
|
+
use: (((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
734
|
+
session: {
|
|
735
|
+
session: Record<string, any> & {
|
|
736
|
+
id: string;
|
|
737
|
+
createdAt: Date;
|
|
738
|
+
updatedAt: Date;
|
|
739
|
+
userId: string;
|
|
740
|
+
expiresAt: Date;
|
|
741
|
+
token: string;
|
|
742
|
+
ipAddress?: string | null | undefined;
|
|
743
|
+
userAgent?: string | null | undefined;
|
|
744
|
+
};
|
|
745
|
+
user: Record<string, any> & {
|
|
746
|
+
id: string;
|
|
747
|
+
createdAt: Date;
|
|
748
|
+
updatedAt: Date;
|
|
749
|
+
email: string;
|
|
750
|
+
emailVerified: boolean;
|
|
751
|
+
name: string;
|
|
752
|
+
image?: string | null | undefined;
|
|
753
|
+
};
|
|
754
|
+
};
|
|
755
|
+
}>) | ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>))[];
|
|
756
|
+
} & {
|
|
757
|
+
use: any[];
|
|
758
|
+
}, {
|
|
759
|
+
url: string;
|
|
760
|
+
redirect: boolean;
|
|
761
|
+
}>;
|
|
762
|
+
} : {});
|
|
763
|
+
init(ctx: better_auth0.AuthContext): {
|
|
764
|
+
options: {
|
|
765
|
+
databaseHooks: {
|
|
766
|
+
user: {
|
|
767
|
+
create: {
|
|
768
|
+
after(user: {
|
|
769
|
+
id: string;
|
|
770
|
+
createdAt: Date;
|
|
771
|
+
updatedAt: Date;
|
|
772
|
+
email: string;
|
|
773
|
+
emailVerified: boolean;
|
|
774
|
+
name: string;
|
|
775
|
+
image?: string | null | undefined;
|
|
776
|
+
} & Record<string, unknown>, ctx: GenericEndpointContext | undefined): Promise<void>;
|
|
777
|
+
};
|
|
778
|
+
update: {
|
|
779
|
+
after(user: {
|
|
780
|
+
id: string;
|
|
781
|
+
createdAt: Date;
|
|
782
|
+
updatedAt: Date;
|
|
783
|
+
email: string;
|
|
784
|
+
emailVerified: boolean;
|
|
785
|
+
name: string;
|
|
786
|
+
image?: string | null | undefined;
|
|
787
|
+
} & Record<string, unknown>, ctx: GenericEndpointContext | undefined): Promise<void>;
|
|
788
|
+
};
|
|
789
|
+
};
|
|
790
|
+
};
|
|
791
|
+
};
|
|
792
|
+
};
|
|
793
|
+
schema: {};
|
|
794
|
+
$ERROR_CODES: {
|
|
795
|
+
readonly SUBSCRIPTION_NOT_FOUND: "Subscription not found";
|
|
796
|
+
readonly SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found";
|
|
797
|
+
readonly ALREADY_SUBSCRIBED_PLAN: "You're already subscribed to this plan";
|
|
798
|
+
readonly UNABLE_TO_CREATE_CUSTOMER: "Unable to create customer";
|
|
799
|
+
readonly FAILED_TO_FETCH_PLANS: "Failed to fetch plans";
|
|
800
|
+
readonly EMAIL_VERIFICATION_REQUIRED: "Email verification is required before you can subscribe to a plan";
|
|
801
|
+
readonly SUBSCRIPTION_NOT_ACTIVE: "Subscription is not active";
|
|
802
|
+
readonly SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: "Subscription is not scheduled for cancellation";
|
|
803
|
+
};
|
|
804
|
+
};
|
|
805
|
+
type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
|
|
806
|
+
//#endregion
|
|
807
|
+
export { Subscription as i, stripe as n, StripePlan as r, StripePlugin as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { StripePlan, StripePlugin, Subscription,
|
|
1
|
+
import { i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-aXzLoFtK.mjs";
|
|
2
|
+
export { StripePlan, StripePlugin, Subscription, stripe };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/stripe",
|
|
3
3
|
"author": "Bereket Engida",
|
|
4
|
-
"version": "1.4.4
|
|
4
|
+
"version": "1.4.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,19 +49,18 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"stripe": "^18 || ^19 || ^20",
|
|
52
|
-
"@better-auth/core": "1.4.4
|
|
53
|
-
"better-auth": "1.4.4
|
|
52
|
+
"@better-auth/core": "1.4.4",
|
|
53
|
+
"better-auth": "1.4.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"better-call": "1.1.
|
|
56
|
+
"better-call": "1.1.3",
|
|
57
57
|
"stripe": "^20.0.0",
|
|
58
|
-
"tsdown": "^0.16.
|
|
59
|
-
"better-auth": "1.4.4
|
|
60
|
-
"@better-auth/core": "1.4.4
|
|
58
|
+
"tsdown": "^0.16.0",
|
|
59
|
+
"better-auth": "1.4.4",
|
|
60
|
+
"@better-auth/core": "1.4.4"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"test": "vitest",
|
|
64
|
-
"lint:package": "publint run --strict",
|
|
65
64
|
"build": "tsdown",
|
|
66
65
|
"dev": "tsdown --watch",
|
|
67
66
|
"typecheck": "tsc --project tsconfig.json"
|
package/src/index.ts
CHANGED
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
import * as better_auth0 from "better-auth";
|
|
2
|
-
import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
|
|
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
|
-
seats: {
|
|
51
|
-
type: "number";
|
|
52
|
-
required: false;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
declare const user: {
|
|
58
|
-
user: {
|
|
59
|
-
fields: {
|
|
60
|
-
stripeCustomerId: {
|
|
61
|
-
type: "string";
|
|
62
|
-
required: false;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/types.d.ts
|
|
69
|
-
type StripePlan = {
|
|
70
|
-
/**
|
|
71
|
-
* Monthly price id
|
|
72
|
-
*/
|
|
73
|
-
priceId?: string | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* To use lookup key instead of price id
|
|
76
|
-
*
|
|
77
|
-
* https://docs.stripe.com/products-prices/
|
|
78
|
-
* manage-prices#lookup-keys
|
|
79
|
-
*/
|
|
80
|
-
lookupKey?: string | undefined;
|
|
81
|
-
/**
|
|
82
|
-
* A yearly discount price id
|
|
83
|
-
*
|
|
84
|
-
* useful when you want to offer a discount for
|
|
85
|
-
* yearly subscription
|
|
86
|
-
*/
|
|
87
|
-
annualDiscountPriceId?: string | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* To use lookup key instead of price id
|
|
90
|
-
*
|
|
91
|
-
* https://docs.stripe.com/products-prices/
|
|
92
|
-
* manage-prices#lookup-keys
|
|
93
|
-
*/
|
|
94
|
-
annualDiscountLookupKey?: string | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* Plan name
|
|
97
|
-
*/
|
|
98
|
-
name: string;
|
|
99
|
-
/**
|
|
100
|
-
* Limits for the plan
|
|
101
|
-
*
|
|
102
|
-
* useful when you want to define plan-specific metadata.
|
|
103
|
-
*/
|
|
104
|
-
limits?: Record<string, unknown> | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* Plan group name
|
|
107
|
-
*
|
|
108
|
-
* useful when you want to group plans or
|
|
109
|
-
* when a user can subscribe to multiple plans.
|
|
110
|
-
*/
|
|
111
|
-
group?: string | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Free trial days
|
|
114
|
-
*/
|
|
115
|
-
freeTrial?: {
|
|
116
|
-
/**
|
|
117
|
-
* Number of days
|
|
118
|
-
*/
|
|
119
|
-
days: number;
|
|
120
|
-
/**
|
|
121
|
-
* A function that will be called when the trial
|
|
122
|
-
* starts.
|
|
123
|
-
*
|
|
124
|
-
* @param subscription
|
|
125
|
-
* @returns
|
|
126
|
-
*/
|
|
127
|
-
onTrialStart?: (subscription: Subscription) => Promise<void>;
|
|
128
|
-
/**
|
|
129
|
-
* A function that will be called when the trial
|
|
130
|
-
* ends
|
|
131
|
-
*
|
|
132
|
-
* @param subscription - Subscription
|
|
133
|
-
* @returns
|
|
134
|
-
*/
|
|
135
|
-
onTrialEnd?: (data: {
|
|
136
|
-
subscription: Subscription;
|
|
137
|
-
}, ctx: GenericEndpointContext) => Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* A function that will be called when the trial
|
|
140
|
-
* expired.
|
|
141
|
-
* @param subscription - Subscription
|
|
142
|
-
* @returns
|
|
143
|
-
*/
|
|
144
|
-
onTrialExpired?: (subscription: Subscription, ctx: GenericEndpointContext) => Promise<void>;
|
|
145
|
-
} | undefined;
|
|
146
|
-
};
|
|
147
|
-
interface Subscription {
|
|
148
|
-
/**
|
|
149
|
-
* Database identifier
|
|
150
|
-
*/
|
|
151
|
-
id: string;
|
|
152
|
-
/**
|
|
153
|
-
* The plan name
|
|
154
|
-
*/
|
|
155
|
-
plan: string;
|
|
156
|
-
/**
|
|
157
|
-
* Stripe customer id
|
|
158
|
-
*/
|
|
159
|
-
stripeCustomerId?: string | undefined;
|
|
160
|
-
/**
|
|
161
|
-
* Stripe subscription id
|
|
162
|
-
*/
|
|
163
|
-
stripeSubscriptionId?: string | undefined;
|
|
164
|
-
/**
|
|
165
|
-
* Trial start date
|
|
166
|
-
*/
|
|
167
|
-
trialStart?: Date | undefined;
|
|
168
|
-
/**
|
|
169
|
-
* Trial end date
|
|
170
|
-
*/
|
|
171
|
-
trialEnd?: Date | undefined;
|
|
172
|
-
/**
|
|
173
|
-
* Price Id for the subscription
|
|
174
|
-
*/
|
|
175
|
-
priceId?: string | undefined;
|
|
176
|
-
/**
|
|
177
|
-
* To what reference id the subscription belongs to
|
|
178
|
-
* @example
|
|
179
|
-
* - userId for a user
|
|
180
|
-
* - workspace id for a saas platform
|
|
181
|
-
* - website id for a hosting platform
|
|
182
|
-
*
|
|
183
|
-
* @default - userId
|
|
184
|
-
*/
|
|
185
|
-
referenceId: string;
|
|
186
|
-
/**
|
|
187
|
-
* Subscription status
|
|
188
|
-
*/
|
|
189
|
-
status: "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "trialing" | "unpaid";
|
|
190
|
-
/**
|
|
191
|
-
* The billing cycle start date
|
|
192
|
-
*/
|
|
193
|
-
periodStart?: Date | undefined;
|
|
194
|
-
/**
|
|
195
|
-
* The billing cycle end date
|
|
196
|
-
*/
|
|
197
|
-
periodEnd?: Date | undefined;
|
|
198
|
-
/**
|
|
199
|
-
* Cancel at period end
|
|
200
|
-
*/
|
|
201
|
-
cancelAtPeriodEnd?: boolean | undefined;
|
|
202
|
-
/**
|
|
203
|
-
* A field to group subscriptions so you can have multiple subscriptions
|
|
204
|
-
* for one reference id
|
|
205
|
-
*/
|
|
206
|
-
groupId?: string | undefined;
|
|
207
|
-
/**
|
|
208
|
-
* Number of seats for the subscription (useful for team plans)
|
|
209
|
-
*/
|
|
210
|
-
seats?: number | undefined;
|
|
211
|
-
}
|
|
212
|
-
type SubscriptionOptions = {
|
|
213
|
-
/**
|
|
214
|
-
* Subscription Configuration
|
|
215
|
-
*/
|
|
216
|
-
/**
|
|
217
|
-
* List of plan
|
|
218
|
-
*/
|
|
219
|
-
plans: StripePlan[] | (() => StripePlan[] | Promise<StripePlan[]>);
|
|
220
|
-
/**
|
|
221
|
-
* Require email verification before a user is allowed to upgrade
|
|
222
|
-
* their subscriptions
|
|
223
|
-
*
|
|
224
|
-
* @default false
|
|
225
|
-
*/
|
|
226
|
-
requireEmailVerification?: boolean | undefined;
|
|
227
|
-
/**
|
|
228
|
-
* A callback to run after a user has subscribed to a package
|
|
229
|
-
* @param event - Stripe Event
|
|
230
|
-
* @param subscription - Subscription Data
|
|
231
|
-
* @returns
|
|
232
|
-
*/
|
|
233
|
-
onSubscriptionComplete?: ((data: {
|
|
234
|
-
event: Stripe.Event;
|
|
235
|
-
stripeSubscription: Stripe.Subscription;
|
|
236
|
-
subscription: Subscription;
|
|
237
|
-
plan: StripePlan;
|
|
238
|
-
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
239
|
-
/**
|
|
240
|
-
* A callback to run after a user is about to cancel their subscription
|
|
241
|
-
* @returns
|
|
242
|
-
*/
|
|
243
|
-
onSubscriptionUpdate?: ((data: {
|
|
244
|
-
event: Stripe.Event;
|
|
245
|
-
subscription: Subscription;
|
|
246
|
-
}) => Promise<void>) | undefined;
|
|
247
|
-
/**
|
|
248
|
-
* A callback to run after a user is about to cancel their subscription
|
|
249
|
-
* @returns
|
|
250
|
-
*/
|
|
251
|
-
onSubscriptionCancel?: ((data: {
|
|
252
|
-
event?: Stripe.Event;
|
|
253
|
-
subscription: Subscription;
|
|
254
|
-
stripeSubscription: Stripe.Subscription;
|
|
255
|
-
cancellationDetails?: Stripe.Subscription.CancellationDetails | null;
|
|
256
|
-
}) => Promise<void>) | undefined;
|
|
257
|
-
/**
|
|
258
|
-
* A function to check if the reference id is valid
|
|
259
|
-
* and belongs to the user
|
|
260
|
-
*
|
|
261
|
-
* @param data - data containing user, session and referenceId
|
|
262
|
-
* @param ctx - the context object
|
|
263
|
-
* @returns
|
|
264
|
-
*/
|
|
265
|
-
authorizeReference?: ((data: {
|
|
266
|
-
user: User & Record<string, any>;
|
|
267
|
-
session: Session & Record<string, any>;
|
|
268
|
-
referenceId: string;
|
|
269
|
-
action: "upgrade-subscription" | "list-subscription" | "cancel-subscription" | "restore-subscription" | "billing-portal";
|
|
270
|
-
}, ctx: GenericEndpointContext) => Promise<boolean>) | undefined;
|
|
271
|
-
/**
|
|
272
|
-
* A callback to run after a user has deleted their subscription
|
|
273
|
-
* @returns
|
|
274
|
-
*/
|
|
275
|
-
onSubscriptionDeleted?: ((data: {
|
|
276
|
-
event: Stripe.Event;
|
|
277
|
-
stripeSubscription: Stripe.Subscription;
|
|
278
|
-
subscription: Subscription;
|
|
279
|
-
}) => Promise<void>) | undefined;
|
|
280
|
-
/**
|
|
281
|
-
* parameters for session create params
|
|
282
|
-
*
|
|
283
|
-
* @param data - data containing user, session and plan
|
|
284
|
-
* @param req - the request object
|
|
285
|
-
* @param ctx - the context object
|
|
286
|
-
*/
|
|
287
|
-
getCheckoutSessionParams?: ((data: {
|
|
288
|
-
user: User & Record<string, any>;
|
|
289
|
-
session: Session & Record<string, any>;
|
|
290
|
-
plan: StripePlan;
|
|
291
|
-
subscription: Subscription;
|
|
292
|
-
}, req: GenericEndpointContext["request"], ctx: GenericEndpointContext) => Promise<{
|
|
293
|
-
params?: Stripe.Checkout.SessionCreateParams;
|
|
294
|
-
options?: Stripe.RequestOptions;
|
|
295
|
-
}> | {
|
|
296
|
-
params?: Stripe.Checkout.SessionCreateParams;
|
|
297
|
-
options?: Stripe.RequestOptions;
|
|
298
|
-
}) | undefined;
|
|
299
|
-
/**
|
|
300
|
-
* Enable organization subscription
|
|
301
|
-
*/
|
|
302
|
-
organization?: {
|
|
303
|
-
enabled: boolean;
|
|
304
|
-
} | undefined;
|
|
305
|
-
};
|
|
306
|
-
interface StripeOptions {
|
|
307
|
-
/**
|
|
308
|
-
* Stripe Client
|
|
309
|
-
*/
|
|
310
|
-
stripeClient: Stripe;
|
|
311
|
-
/**
|
|
312
|
-
* Stripe Webhook Secret
|
|
313
|
-
*
|
|
314
|
-
* @description Stripe webhook secret key
|
|
315
|
-
*/
|
|
316
|
-
stripeWebhookSecret: string;
|
|
317
|
-
/**
|
|
318
|
-
* Enable customer creation when a user signs up
|
|
319
|
-
*/
|
|
320
|
-
createCustomerOnSignUp?: boolean | undefined;
|
|
321
|
-
/**
|
|
322
|
-
* A callback to run after a customer has been created
|
|
323
|
-
* @param customer - Customer Data
|
|
324
|
-
* @param stripeCustomer - Stripe Customer Data
|
|
325
|
-
* @returns
|
|
326
|
-
*/
|
|
327
|
-
onCustomerCreate?: ((data: {
|
|
328
|
-
stripeCustomer: Stripe.Customer;
|
|
329
|
-
user: User & {
|
|
330
|
-
stripeCustomerId: string;
|
|
331
|
-
};
|
|
332
|
-
}, ctx: GenericEndpointContext) => Promise<void>) | undefined;
|
|
333
|
-
/**
|
|
334
|
-
* A custom function to get the customer create
|
|
335
|
-
* params
|
|
336
|
-
* @param data - data containing user and session
|
|
337
|
-
* @returns
|
|
338
|
-
*/
|
|
339
|
-
getCustomerCreateParams?: ((user: User, ctx: GenericEndpointContext) => Promise<Partial<Stripe.CustomerCreateParams>>) | undefined;
|
|
340
|
-
/**
|
|
341
|
-
* Subscriptions
|
|
342
|
-
*/
|
|
343
|
-
subscription?: ({
|
|
344
|
-
enabled: false;
|
|
345
|
-
} | ({
|
|
346
|
-
enabled: true;
|
|
347
|
-
} & SubscriptionOptions)) | undefined;
|
|
348
|
-
/**
|
|
349
|
-
* A callback to run after a stripe event is received
|
|
350
|
-
* @param event - Stripe Event
|
|
351
|
-
* @returns
|
|
352
|
-
*/
|
|
353
|
-
onEvent?: ((event: Stripe.Event) => Promise<void>) | undefined;
|
|
354
|
-
/**
|
|
355
|
-
* Schema for the stripe plugin
|
|
356
|
-
*/
|
|
357
|
-
schema?: InferOptionSchema<typeof subscriptions & typeof user> | undefined;
|
|
358
|
-
}
|
|
359
|
-
//#endregion
|
|
360
|
-
//#region src/index.d.ts
|
|
361
|
-
declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
362
|
-
id: "stripe";
|
|
363
|
-
endpoints: {
|
|
364
|
-
stripeWebhook: any;
|
|
365
|
-
} & (O["subscription"] extends {
|
|
366
|
-
enabled: true;
|
|
367
|
-
} ? {
|
|
368
|
-
/**
|
|
369
|
-
* ### Endpoint
|
|
370
|
-
*
|
|
371
|
-
* POST `/subscription/upgrade`
|
|
372
|
-
*
|
|
373
|
-
* ### API Methods
|
|
374
|
-
*
|
|
375
|
-
* **server:**
|
|
376
|
-
* `auth.api.upgradeSubscription`
|
|
377
|
-
*
|
|
378
|
-
* **client:**
|
|
379
|
-
* `authClient.subscription.upgrade`
|
|
380
|
-
*
|
|
381
|
-
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-upgrade)
|
|
382
|
-
*/
|
|
383
|
-
readonly upgradeSubscription: any;
|
|
384
|
-
readonly cancelSubscriptionCallback: any;
|
|
385
|
-
/**
|
|
386
|
-
* ### Endpoint
|
|
387
|
-
*
|
|
388
|
-
* POST `/subscription/cancel`
|
|
389
|
-
*
|
|
390
|
-
* ### API Methods
|
|
391
|
-
*
|
|
392
|
-
* **server:**
|
|
393
|
-
* `auth.api.cancelSubscription`
|
|
394
|
-
*
|
|
395
|
-
* **client:**
|
|
396
|
-
* `authClient.subscription.cancel`
|
|
397
|
-
*
|
|
398
|
-
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-cancel)
|
|
399
|
-
*/
|
|
400
|
-
readonly cancelSubscription: any;
|
|
401
|
-
readonly restoreSubscription: any;
|
|
402
|
-
/**
|
|
403
|
-
* ### Endpoint
|
|
404
|
-
*
|
|
405
|
-
* GET `/subscription/list`
|
|
406
|
-
*
|
|
407
|
-
* ### API Methods
|
|
408
|
-
*
|
|
409
|
-
* **server:**
|
|
410
|
-
* `auth.api.listActiveSubscriptions`
|
|
411
|
-
*
|
|
412
|
-
* **client:**
|
|
413
|
-
* `authClient.subscription.list`
|
|
414
|
-
*
|
|
415
|
-
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/stripe#api-method-subscription-list)
|
|
416
|
-
*/
|
|
417
|
-
readonly listActiveSubscriptions: any;
|
|
418
|
-
readonly subscriptionSuccess: any;
|
|
419
|
-
readonly createBillingPortal: any;
|
|
420
|
-
} : {});
|
|
421
|
-
init(ctx: better_auth0.AuthContext): {
|
|
422
|
-
options: {
|
|
423
|
-
databaseHooks: {
|
|
424
|
-
user: {
|
|
425
|
-
create: {
|
|
426
|
-
after(user: {
|
|
427
|
-
id: string;
|
|
428
|
-
createdAt: Date;
|
|
429
|
-
updatedAt: Date;
|
|
430
|
-
email: string;
|
|
431
|
-
emailVerified: boolean;
|
|
432
|
-
name: string;
|
|
433
|
-
image?: string | null | undefined;
|
|
434
|
-
} & Record<string, unknown>, ctx: any): Promise<void>;
|
|
435
|
-
};
|
|
436
|
-
update: {
|
|
437
|
-
after(user: {
|
|
438
|
-
id: string;
|
|
439
|
-
createdAt: Date;
|
|
440
|
-
updatedAt: Date;
|
|
441
|
-
email: string;
|
|
442
|
-
emailVerified: boolean;
|
|
443
|
-
name: string;
|
|
444
|
-
image?: string | null | undefined;
|
|
445
|
-
} & Record<string, unknown>, ctx: any): Promise<void>;
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
};
|
|
449
|
-
};
|
|
450
|
-
};
|
|
451
|
-
schema: {};
|
|
452
|
-
$ERROR_CODES: {
|
|
453
|
-
readonly SUBSCRIPTION_NOT_FOUND: "Subscription not found";
|
|
454
|
-
readonly SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found";
|
|
455
|
-
readonly ALREADY_SUBSCRIBED_PLAN: "You're already subscribed to this plan";
|
|
456
|
-
readonly UNABLE_TO_CREATE_CUSTOMER: "Unable to create customer";
|
|
457
|
-
readonly FAILED_TO_FETCH_PLANS: "Failed to fetch plans";
|
|
458
|
-
readonly EMAIL_VERIFICATION_REQUIRED: "Email verification is required before you can subscribe to a plan";
|
|
459
|
-
readonly SUBSCRIPTION_NOT_ACTIVE: "Subscription is not active";
|
|
460
|
-
readonly SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION: "Subscription is not scheduled for cancellation";
|
|
461
|
-
};
|
|
462
|
-
};
|
|
463
|
-
type StripePlugin<O extends StripeOptions> = ReturnType<typeof stripe<O>>;
|
|
464
|
-
//#endregion
|
|
465
|
-
export { SubscriptionOptions as a, Subscription as i, stripe as n, StripePlan as r, StripePlugin as t };
|