@better-auth/stripe 1.2.4-beta.8 → 1.2.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 +4 -4
- package/dist/client.d.cts +2 -2
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/index.cjs +8 -3
- package/dist/index.d.cts +11 -4
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +8 -3
- package/package.json +2 -2
- package/src/client.ts +2 -2
- package/src/index.ts +9 -3
- package/src/types.ts +11 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/stripe@1.2.4
|
|
2
|
+
> @better-auth/stripe@1.2.4 build /home/runner/work/better-auth/better-auth/packages/stripe
|
|
3
3
|
> unbuild
|
|
4
4
|
|
|
5
5
|
[info] Automatically detected entries: src/index, src/client [esm] [cjs] [dts]
|
|
6
6
|
[info] Building stripe
|
|
7
7
|
[success] Build succeeded for stripe
|
|
8
|
-
[log] dist/index.cjs (total size: 33.
|
|
8
|
+
[log] dist/index.cjs (total size: 33.4 kB, chunk size: 33.4 kB, exports: stripe)
|
|
9
9
|
|
|
10
10
|
[log] dist/client.cjs (total size: 160 B, chunk size: 160 B, exports: stripeClient)
|
|
11
11
|
|
|
12
|
-
[log] dist/index.mjs (total size: 33 kB, chunk size: 33 kB, exports: stripe)
|
|
12
|
+
[log] dist/index.mjs (total size: 33.1 kB, chunk size: 33.1 kB, exports: stripe)
|
|
13
13
|
|
|
14
14
|
[log] dist/client.mjs (total size: 133 B, chunk size: 133 B, exports: stripeClient)
|
|
15
15
|
|
|
16
|
-
Σ Total dist size (byte size):
|
|
16
|
+
Σ Total dist size (byte size): 184 kB
|
|
17
17
|
[log]
|
package/dist/client.d.cts
CHANGED
|
@@ -11,14 +11,14 @@ declare const stripeClient: <O extends {
|
|
|
11
11
|
id: "stripe-client";
|
|
12
12
|
$InferServerPlugin: ReturnType<typeof stripe<O["subscription"] extends true ? {
|
|
13
13
|
stripeClient: any;
|
|
14
|
-
stripeWebhookSecret:
|
|
14
|
+
stripeWebhookSecret: string;
|
|
15
15
|
subscription: {
|
|
16
16
|
enabled: true;
|
|
17
17
|
plans: [];
|
|
18
18
|
};
|
|
19
19
|
} : {
|
|
20
20
|
stripeClient: any;
|
|
21
|
-
stripeWebhookSecret:
|
|
21
|
+
stripeWebhookSecret: string;
|
|
22
22
|
}>>;
|
|
23
23
|
};
|
|
24
24
|
|
package/dist/client.d.mts
CHANGED
|
@@ -11,14 +11,14 @@ declare const stripeClient: <O extends {
|
|
|
11
11
|
id: "stripe-client";
|
|
12
12
|
$InferServerPlugin: ReturnType<typeof stripe<O["subscription"] extends true ? {
|
|
13
13
|
stripeClient: any;
|
|
14
|
-
stripeWebhookSecret:
|
|
14
|
+
stripeWebhookSecret: string;
|
|
15
15
|
subscription: {
|
|
16
16
|
enabled: true;
|
|
17
17
|
plans: [];
|
|
18
18
|
};
|
|
19
19
|
} : {
|
|
20
20
|
stripeClient: any;
|
|
21
|
-
stripeWebhookSecret:
|
|
21
|
+
stripeWebhookSecret: string;
|
|
22
22
|
}>>;
|
|
23
23
|
};
|
|
24
24
|
|
package/dist/client.d.ts
CHANGED
|
@@ -11,14 +11,14 @@ declare const stripeClient: <O extends {
|
|
|
11
11
|
id: "stripe-client";
|
|
12
12
|
$InferServerPlugin: ReturnType<typeof stripe<O["subscription"] extends true ? {
|
|
13
13
|
stripeClient: any;
|
|
14
|
-
stripeWebhookSecret:
|
|
14
|
+
stripeWebhookSecret: string;
|
|
15
15
|
subscription: {
|
|
16
16
|
enabled: true;
|
|
17
17
|
plans: [];
|
|
18
18
|
};
|
|
19
19
|
} : {
|
|
20
20
|
stripeClient: any;
|
|
21
|
-
stripeWebhookSecret:
|
|
21
|
+
stripeWebhookSecret: string;
|
|
22
22
|
}>>;
|
|
23
23
|
};
|
|
24
24
|
|
package/dist/index.cjs
CHANGED
|
@@ -443,7 +443,11 @@ const stripe = (options) => {
|
|
|
443
443
|
const activeSubscription = customerId ? await client.subscriptions.list({
|
|
444
444
|
customer: customerId,
|
|
445
445
|
status: "active"
|
|
446
|
-
}).then(
|
|
446
|
+
}).then(
|
|
447
|
+
(res) => res.data.find(
|
|
448
|
+
(subscription2) => subscription2.id === ctx.body.subscriptionId
|
|
449
|
+
)
|
|
450
|
+
).catch((e) => null) : null;
|
|
447
451
|
const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.context.adapter.findMany({
|
|
448
452
|
model: "subscription",
|
|
449
453
|
where: [
|
|
@@ -822,10 +826,11 @@ const stripe = (options) => {
|
|
|
822
826
|
if (subscription?.status === "active" || subscription?.status === "trialing") {
|
|
823
827
|
return ctx.redirect(getUrl(ctx, callbackURL));
|
|
824
828
|
}
|
|
825
|
-
|
|
829
|
+
const customerId = subscription?.stripeCustomerId || user.stripeCustomerId;
|
|
830
|
+
if (customerId) {
|
|
826
831
|
try {
|
|
827
832
|
const stripeSubscription = await client.subscriptions.list({
|
|
828
|
-
customer:
|
|
833
|
+
customer: customerId,
|
|
829
834
|
status: "active"
|
|
830
835
|
}).then((res) => res.data[0]);
|
|
831
836
|
if (stripeSubscription) {
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import Stripe from 'stripe';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
-
type
|
|
8
|
+
type StripePlan = {
|
|
9
9
|
/**
|
|
10
10
|
* Monthly price id
|
|
11
11
|
*/
|
|
@@ -24,6 +24,13 @@ type Plan = {
|
|
|
24
24
|
* yearly subscription
|
|
25
25
|
*/
|
|
26
26
|
annualDiscountPriceId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* To use lookup key instead of price id
|
|
29
|
+
*
|
|
30
|
+
* https://docs.stripe.com/products-prices/
|
|
31
|
+
* manage-prices#lookup-keys
|
|
32
|
+
*/
|
|
33
|
+
annualDiscountLookupKey?: string;
|
|
27
34
|
/**
|
|
28
35
|
* Plan name
|
|
29
36
|
*/
|
|
@@ -186,7 +193,7 @@ interface StripeOptions {
|
|
|
186
193
|
/**
|
|
187
194
|
* List of plan
|
|
188
195
|
*/
|
|
189
|
-
plans:
|
|
196
|
+
plans: StripePlan[] | (() => Promise<StripePlan[]>);
|
|
190
197
|
/**
|
|
191
198
|
* Require email verification before a user is allowed to upgrade
|
|
192
199
|
* their subscriptions
|
|
@@ -204,7 +211,7 @@ interface StripeOptions {
|
|
|
204
211
|
event: Stripe.Event;
|
|
205
212
|
stripeSubscription: Stripe.Subscription;
|
|
206
213
|
subscription: Subscription;
|
|
207
|
-
plan:
|
|
214
|
+
plan: StripePlan;
|
|
208
215
|
}, request?: Request) => Promise<void>;
|
|
209
216
|
/**
|
|
210
217
|
* A callback to run after a user is about to cancel their subscription
|
|
@@ -256,7 +263,7 @@ interface StripeOptions {
|
|
|
256
263
|
getCheckoutSessionParams?: (data: {
|
|
257
264
|
user: User & Record<string, any>;
|
|
258
265
|
session: Session & Record<string, any>;
|
|
259
|
-
plan:
|
|
266
|
+
plan: StripePlan;
|
|
260
267
|
subscription: Subscription;
|
|
261
268
|
}, request?: Request) => Promise<{
|
|
262
269
|
params?: Stripe.Checkout.SessionCreateParams;
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import Stripe from 'stripe';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
-
type
|
|
8
|
+
type StripePlan = {
|
|
9
9
|
/**
|
|
10
10
|
* Monthly price id
|
|
11
11
|
*/
|
|
@@ -24,6 +24,13 @@ type Plan = {
|
|
|
24
24
|
* yearly subscription
|
|
25
25
|
*/
|
|
26
26
|
annualDiscountPriceId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* To use lookup key instead of price id
|
|
29
|
+
*
|
|
30
|
+
* https://docs.stripe.com/products-prices/
|
|
31
|
+
* manage-prices#lookup-keys
|
|
32
|
+
*/
|
|
33
|
+
annualDiscountLookupKey?: string;
|
|
27
34
|
/**
|
|
28
35
|
* Plan name
|
|
29
36
|
*/
|
|
@@ -186,7 +193,7 @@ interface StripeOptions {
|
|
|
186
193
|
/**
|
|
187
194
|
* List of plan
|
|
188
195
|
*/
|
|
189
|
-
plans:
|
|
196
|
+
plans: StripePlan[] | (() => Promise<StripePlan[]>);
|
|
190
197
|
/**
|
|
191
198
|
* Require email verification before a user is allowed to upgrade
|
|
192
199
|
* their subscriptions
|
|
@@ -204,7 +211,7 @@ interface StripeOptions {
|
|
|
204
211
|
event: Stripe.Event;
|
|
205
212
|
stripeSubscription: Stripe.Subscription;
|
|
206
213
|
subscription: Subscription;
|
|
207
|
-
plan:
|
|
214
|
+
plan: StripePlan;
|
|
208
215
|
}, request?: Request) => Promise<void>;
|
|
209
216
|
/**
|
|
210
217
|
* A callback to run after a user is about to cancel their subscription
|
|
@@ -256,7 +263,7 @@ interface StripeOptions {
|
|
|
256
263
|
getCheckoutSessionParams?: (data: {
|
|
257
264
|
user: User & Record<string, any>;
|
|
258
265
|
session: Session & Record<string, any>;
|
|
259
|
-
plan:
|
|
266
|
+
plan: StripePlan;
|
|
260
267
|
subscription: Subscription;
|
|
261
268
|
}, request?: Request) => Promise<{
|
|
262
269
|
params?: Stripe.Checkout.SessionCreateParams;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import Stripe from 'stripe';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { APIError } from 'better-auth/api';
|
|
7
7
|
|
|
8
|
-
type
|
|
8
|
+
type StripePlan = {
|
|
9
9
|
/**
|
|
10
10
|
* Monthly price id
|
|
11
11
|
*/
|
|
@@ -24,6 +24,13 @@ type Plan = {
|
|
|
24
24
|
* yearly subscription
|
|
25
25
|
*/
|
|
26
26
|
annualDiscountPriceId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* To use lookup key instead of price id
|
|
29
|
+
*
|
|
30
|
+
* https://docs.stripe.com/products-prices/
|
|
31
|
+
* manage-prices#lookup-keys
|
|
32
|
+
*/
|
|
33
|
+
annualDiscountLookupKey?: string;
|
|
27
34
|
/**
|
|
28
35
|
* Plan name
|
|
29
36
|
*/
|
|
@@ -186,7 +193,7 @@ interface StripeOptions {
|
|
|
186
193
|
/**
|
|
187
194
|
* List of plan
|
|
188
195
|
*/
|
|
189
|
-
plans:
|
|
196
|
+
plans: StripePlan[] | (() => Promise<StripePlan[]>);
|
|
190
197
|
/**
|
|
191
198
|
* Require email verification before a user is allowed to upgrade
|
|
192
199
|
* their subscriptions
|
|
@@ -204,7 +211,7 @@ interface StripeOptions {
|
|
|
204
211
|
event: Stripe.Event;
|
|
205
212
|
stripeSubscription: Stripe.Subscription;
|
|
206
213
|
subscription: Subscription;
|
|
207
|
-
plan:
|
|
214
|
+
plan: StripePlan;
|
|
208
215
|
}, request?: Request) => Promise<void>;
|
|
209
216
|
/**
|
|
210
217
|
* A callback to run after a user is about to cancel their subscription
|
|
@@ -256,7 +263,7 @@ interface StripeOptions {
|
|
|
256
263
|
getCheckoutSessionParams?: (data: {
|
|
257
264
|
user: User & Record<string, any>;
|
|
258
265
|
session: Session & Record<string, any>;
|
|
259
|
-
plan:
|
|
266
|
+
plan: StripePlan;
|
|
260
267
|
subscription: Subscription;
|
|
261
268
|
}, request?: Request) => Promise<{
|
|
262
269
|
params?: Stripe.Checkout.SessionCreateParams;
|
package/dist/index.mjs
CHANGED
|
@@ -441,7 +441,11 @@ const stripe = (options) => {
|
|
|
441
441
|
const activeSubscription = customerId ? await client.subscriptions.list({
|
|
442
442
|
customer: customerId,
|
|
443
443
|
status: "active"
|
|
444
|
-
}).then(
|
|
444
|
+
}).then(
|
|
445
|
+
(res) => res.data.find(
|
|
446
|
+
(subscription2) => subscription2.id === ctx.body.subscriptionId
|
|
447
|
+
)
|
|
448
|
+
).catch((e) => null) : null;
|
|
445
449
|
const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.context.adapter.findMany({
|
|
446
450
|
model: "subscription",
|
|
447
451
|
where: [
|
|
@@ -820,10 +824,11 @@ const stripe = (options) => {
|
|
|
820
824
|
if (subscription?.status === "active" || subscription?.status === "trialing") {
|
|
821
825
|
return ctx.redirect(getUrl(ctx, callbackURL));
|
|
822
826
|
}
|
|
823
|
-
|
|
827
|
+
const customerId = subscription?.stripeCustomerId || user.stripeCustomerId;
|
|
828
|
+
if (customerId) {
|
|
824
829
|
try {
|
|
825
830
|
const stripeSubscription = await client.subscriptions.list({
|
|
826
|
-
customer:
|
|
831
|
+
customer: customerId,
|
|
827
832
|
status: "active"
|
|
828
833
|
}).then((res) => res.data[0]);
|
|
829
834
|
if (stripeSubscription) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/stripe",
|
|
3
3
|
"author": "Bereket Engida",
|
|
4
|
-
"version": "1.2.4
|
|
4
|
+
"version": "1.2.4",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"zod": "^3.24.1",
|
|
38
|
-
"better-auth": "^1.2.4
|
|
38
|
+
"better-auth": "^1.2.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/better-sqlite3": "^7.6.12",
|
package/src/client.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const stripeClient = <
|
|
|
15
15
|
O["subscription"] extends true
|
|
16
16
|
? {
|
|
17
17
|
stripeClient: any;
|
|
18
|
-
stripeWebhookSecret:
|
|
18
|
+
stripeWebhookSecret: string;
|
|
19
19
|
subscription: {
|
|
20
20
|
enabled: true;
|
|
21
21
|
plans: [];
|
|
@@ -23,7 +23,7 @@ export const stripeClient = <
|
|
|
23
23
|
}
|
|
24
24
|
: {
|
|
25
25
|
stripeClient: any;
|
|
26
|
-
stripeWebhookSecret:
|
|
26
|
+
stripeWebhookSecret: string;
|
|
27
27
|
}
|
|
28
28
|
>
|
|
29
29
|
>,
|
package/src/index.ts
CHANGED
|
@@ -240,7 +240,11 @@ export const stripe = <O extends StripeOptions>(options: O) => {
|
|
|
240
240
|
customer: customerId,
|
|
241
241
|
status: "active",
|
|
242
242
|
})
|
|
243
|
-
.then((res) =>
|
|
243
|
+
.then((res) =>
|
|
244
|
+
res.data.find(
|
|
245
|
+
(subscription) => subscription.id === ctx.body.subscriptionId,
|
|
246
|
+
),
|
|
247
|
+
)
|
|
244
248
|
.catch((e) => null)
|
|
245
249
|
: null;
|
|
246
250
|
|
|
@@ -687,12 +691,14 @@ export const stripe = <O extends StripeOptions>(options: O) => {
|
|
|
687
691
|
) {
|
|
688
692
|
return ctx.redirect(getUrl(ctx, callbackURL));
|
|
689
693
|
}
|
|
694
|
+
const customerId =
|
|
695
|
+
subscription?.stripeCustomerId || user.stripeCustomerId;
|
|
690
696
|
|
|
691
|
-
if (
|
|
697
|
+
if (customerId) {
|
|
692
698
|
try {
|
|
693
699
|
const stripeSubscription = await client.subscriptions
|
|
694
700
|
.list({
|
|
695
|
-
customer:
|
|
701
|
+
customer: customerId,
|
|
696
702
|
status: "active",
|
|
697
703
|
})
|
|
698
704
|
.then((res) => res.data[0]);
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Session, User } from "better-auth";
|
|
2
2
|
import type Stripe from "stripe";
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type StripePlan = {
|
|
5
5
|
/**
|
|
6
6
|
* Monthly price id
|
|
7
7
|
*/
|
|
@@ -20,6 +20,13 @@ export type Plan = {
|
|
|
20
20
|
* yearly subscription
|
|
21
21
|
*/
|
|
22
22
|
annualDiscountPriceId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* To use lookup key instead of price id
|
|
25
|
+
*
|
|
26
|
+
* https://docs.stripe.com/products-prices/
|
|
27
|
+
* manage-prices#lookup-keys
|
|
28
|
+
*/
|
|
29
|
+
annualDiscountLookupKey?: string;
|
|
23
30
|
/**
|
|
24
31
|
* Plan name
|
|
25
32
|
*/
|
|
@@ -204,7 +211,7 @@ export interface StripeOptions {
|
|
|
204
211
|
/**
|
|
205
212
|
* List of plan
|
|
206
213
|
*/
|
|
207
|
-
plans:
|
|
214
|
+
plans: StripePlan[] | (() => Promise<StripePlan[]>);
|
|
208
215
|
/**
|
|
209
216
|
* Require email verification before a user is allowed to upgrade
|
|
210
217
|
* their subscriptions
|
|
@@ -223,7 +230,7 @@ export interface StripeOptions {
|
|
|
223
230
|
event: Stripe.Event;
|
|
224
231
|
stripeSubscription: Stripe.Subscription;
|
|
225
232
|
subscription: Subscription;
|
|
226
|
-
plan:
|
|
233
|
+
plan: StripePlan;
|
|
227
234
|
},
|
|
228
235
|
request?: Request,
|
|
229
236
|
) => Promise<void>;
|
|
@@ -284,7 +291,7 @@ export interface StripeOptions {
|
|
|
284
291
|
data: {
|
|
285
292
|
user: User & Record<string, any>;
|
|
286
293
|
session: Session & Record<string, any>;
|
|
287
|
-
plan:
|
|
294
|
+
plan: StripePlan;
|
|
288
295
|
subscription: Subscription;
|
|
289
296
|
},
|
|
290
297
|
request?: Request,
|