@better-auth/stripe 1.2.3 → 1.2.4-beta.10
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 +134 -63
- package/dist/index.d.cts +72 -8
- package/dist/index.d.mts +72 -8
- package/dist/index.d.ts +72 -8
- package/dist/index.mjs +135 -64
- package/package.json +2 -2
- package/src/client.ts +2 -2
- package/src/hooks.ts +3 -3
- package/src/index.ts +172 -72
- package/src/stripe.test.ts +15 -7
- package/src/types.ts +11 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/stripe@1.2.
|
|
2
|
+
> @better-auth/stripe@1.2.4-beta.10 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:
|
|
8
|
+
[log] dist/index.cjs (total size: 33.3 kB, chunk size: 33.3 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:
|
|
12
|
+
[log] dist/index.mjs (total size: 33 kB, chunk size: 33 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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const betterAuth = require('better-auth');
|
|
3
4
|
const plugins = require('better-auth/plugins');
|
|
4
5
|
const zod = require('zod');
|
|
5
6
|
const api = require('better-auth/api');
|
|
6
7
|
const crypto = require('better-auth/crypto');
|
|
7
|
-
const betterAuth = require('better-auth');
|
|
8
8
|
|
|
9
9
|
async function getPlans(options) {
|
|
10
10
|
return typeof options?.subscription?.plans === "function" ? await options.subscription?.plans() : options.subscription?.plans;
|
|
@@ -95,11 +95,11 @@ async function onSubscriptionUpdated(ctx, options, event) {
|
|
|
95
95
|
const subscriptionUpdated = event.data.object;
|
|
96
96
|
const priceId = subscriptionUpdated.items.data[0].price.id;
|
|
97
97
|
const plan = await getPlanByPriceId(options, priceId);
|
|
98
|
-
const
|
|
98
|
+
const subscriptionId = subscriptionUpdated.metadata?.subscriptionId;
|
|
99
99
|
const customerId = subscriptionUpdated.customer?.toString();
|
|
100
100
|
let subscription = await ctx.context.adapter.findOne({
|
|
101
101
|
model: "subscription",
|
|
102
|
-
where:
|
|
102
|
+
where: subscriptionId ? [{ field: "id", value: subscriptionId }] : [{ field: "stripeSubscriptionId", value: subscriptionUpdated.id }]
|
|
103
103
|
});
|
|
104
104
|
if (!subscription) {
|
|
105
105
|
const subs = await ctx.context.adapter.findMany({
|
|
@@ -313,25 +313,64 @@ const stripe = (options) => {
|
|
|
313
313
|
{
|
|
314
314
|
method: "POST",
|
|
315
315
|
body: zod.z.object({
|
|
316
|
+
/**
|
|
317
|
+
* The name of the plan to subscribe
|
|
318
|
+
*/
|
|
316
319
|
plan: zod.z.string({
|
|
317
320
|
description: "The name of the plan to upgrade to"
|
|
318
321
|
}),
|
|
322
|
+
/**
|
|
323
|
+
* If annual plan should be applied.
|
|
324
|
+
*/
|
|
319
325
|
annual: zod.z.boolean({
|
|
320
326
|
description: "Whether to upgrade to an annual plan"
|
|
321
327
|
}).optional(),
|
|
322
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Reference id of the subscription to upgrade
|
|
330
|
+
* This is used to identify the subscription to upgrade
|
|
331
|
+
* If not provided, the user's id will be used
|
|
332
|
+
*/
|
|
333
|
+
referenceId: zod.z.string({
|
|
334
|
+
description: "Reference id of the subscription to upgrade"
|
|
335
|
+
}).optional(),
|
|
336
|
+
/**
|
|
337
|
+
* This is to allow a specific subscription to be upgrade.
|
|
338
|
+
* If subscription id is provided, and subscription isn't found,
|
|
339
|
+
* it'll throw an error.
|
|
340
|
+
*/
|
|
341
|
+
subscriptionId: zod.z.string({
|
|
342
|
+
description: "The id of the subscription to upgrade"
|
|
343
|
+
}).optional(),
|
|
344
|
+
/**
|
|
345
|
+
* Any additional data you want to store in your database
|
|
346
|
+
* subscriptions
|
|
347
|
+
*/
|
|
323
348
|
metadata: zod.z.record(zod.z.string(), zod.z.any()).optional(),
|
|
349
|
+
/**
|
|
350
|
+
* If a subscription
|
|
351
|
+
*/
|
|
324
352
|
seats: zod.z.number({
|
|
325
353
|
description: "Number of seats to upgrade to (if applicable)"
|
|
326
354
|
}).optional(),
|
|
327
|
-
|
|
355
|
+
/**
|
|
356
|
+
* Success url to redirect back after successful subscription
|
|
357
|
+
*/
|
|
328
358
|
successUrl: zod.z.string({
|
|
329
359
|
description: "callback url to redirect back after successful subscription"
|
|
330
360
|
}).default("/"),
|
|
361
|
+
/**
|
|
362
|
+
* Cancel URL
|
|
363
|
+
*/
|
|
331
364
|
cancelUrl: zod.z.string({
|
|
332
365
|
description: "callback url to redirect back after successful subscription"
|
|
333
366
|
}).default("/"),
|
|
367
|
+
/**
|
|
368
|
+
* Return URL
|
|
369
|
+
*/
|
|
334
370
|
returnUrl: zod.z.string().optional(),
|
|
371
|
+
/**
|
|
372
|
+
* Disable Redirect
|
|
373
|
+
*/
|
|
335
374
|
disableRedirect: zod.z.boolean().default(false)
|
|
336
375
|
}),
|
|
337
376
|
use: [
|
|
@@ -356,7 +395,16 @@ const stripe = (options) => {
|
|
|
356
395
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_PLAN_NOT_FOUND
|
|
357
396
|
});
|
|
358
397
|
}
|
|
359
|
-
|
|
398
|
+
const subscriptionToUpdate = ctx.body.subscriptionId ? await ctx.context.adapter.findOne({
|
|
399
|
+
model: "subscription",
|
|
400
|
+
where: [{ field: "id", value: ctx.body.subscriptionId }]
|
|
401
|
+
}) : null;
|
|
402
|
+
if (ctx.body.subscriptionId && !subscriptionToUpdate) {
|
|
403
|
+
throw new api.APIError("BAD_REQUEST", {
|
|
404
|
+
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
let customerId = subscriptionToUpdate?.stripeCustomerId || user.stripeCustomerId;
|
|
360
408
|
if (!customerId) {
|
|
361
409
|
try {
|
|
362
410
|
const stripeCustomer = await client.customers.create(
|
|
@@ -396,7 +444,7 @@ const stripe = (options) => {
|
|
|
396
444
|
customer: customerId,
|
|
397
445
|
status: "active"
|
|
398
446
|
}).then((res) => res.data[0]).catch((e) => null) : null;
|
|
399
|
-
const subscriptions = await ctx.context.adapter.findMany({
|
|
447
|
+
const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.context.adapter.findMany({
|
|
400
448
|
model: "subscription",
|
|
401
449
|
where: [
|
|
402
450
|
{
|
|
@@ -486,7 +534,7 @@ const stripe = (options) => {
|
|
|
486
534
|
ctx,
|
|
487
535
|
`${ctx.context.baseURL}/subscription/success?callbackURL=${encodeURIComponent(
|
|
488
536
|
ctx.body.successUrl
|
|
489
|
-
)}&
|
|
537
|
+
)}&subscriptionId=${encodeURIComponent(subscription.id)}`
|
|
490
538
|
),
|
|
491
539
|
cancel_url: getUrl(ctx, ctx.body.cancelUrl),
|
|
492
540
|
line_items: [
|
|
@@ -525,10 +573,11 @@ const stripe = (options) => {
|
|
|
525
573
|
"/subscription/cancel/callback",
|
|
526
574
|
{
|
|
527
575
|
method: "GET",
|
|
528
|
-
query: zod.z.record(zod.z.string(), zod.z.any()).optional()
|
|
576
|
+
query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
|
|
577
|
+
use: [api.originCheck((ctx) => ctx.query.callbackURL)]
|
|
529
578
|
},
|
|
530
579
|
async (ctx) => {
|
|
531
|
-
if (!ctx.query || !ctx.query.callbackURL || !ctx.query.
|
|
580
|
+
if (!ctx.query || !ctx.query.callbackURL || !ctx.query.subscriptionId) {
|
|
532
581
|
throw ctx.redirect(getUrl(ctx, ctx.query?.callbackURL || "/"));
|
|
533
582
|
}
|
|
534
583
|
const session = await api.getSessionFromCtx(
|
|
@@ -538,15 +587,15 @@ const stripe = (options) => {
|
|
|
538
587
|
throw ctx.redirect(getUrl(ctx, ctx.query?.callbackURL || "/"));
|
|
539
588
|
}
|
|
540
589
|
const { user } = session;
|
|
541
|
-
const { callbackURL,
|
|
590
|
+
const { callbackURL, subscriptionId } = ctx.query;
|
|
542
591
|
if (user?.stripeCustomerId) {
|
|
543
592
|
try {
|
|
544
593
|
const subscription = await ctx.context.adapter.findOne({
|
|
545
594
|
model: "subscription",
|
|
546
595
|
where: [
|
|
547
596
|
{
|
|
548
|
-
field: "
|
|
549
|
-
value:
|
|
597
|
+
field: "id",
|
|
598
|
+
value: subscriptionId
|
|
550
599
|
}
|
|
551
600
|
]
|
|
552
601
|
});
|
|
@@ -569,8 +618,8 @@ const stripe = (options) => {
|
|
|
569
618
|
},
|
|
570
619
|
where: [
|
|
571
620
|
{
|
|
572
|
-
field: "
|
|
573
|
-
value:
|
|
621
|
+
field: "id",
|
|
622
|
+
value: subscription.id
|
|
574
623
|
}
|
|
575
624
|
]
|
|
576
625
|
});
|
|
@@ -597,6 +646,7 @@ const stripe = (options) => {
|
|
|
597
646
|
method: "POST",
|
|
598
647
|
body: zod.z.object({
|
|
599
648
|
referenceId: zod.z.string().optional(),
|
|
649
|
+
subscriptionId: zod.z.string().optional(),
|
|
600
650
|
returnUrl: zod.z.string()
|
|
601
651
|
}),
|
|
602
652
|
use: [
|
|
@@ -607,15 +657,22 @@ const stripe = (options) => {
|
|
|
607
657
|
},
|
|
608
658
|
async (ctx) => {
|
|
609
659
|
const referenceId = ctx.body?.referenceId || ctx.context.session.user.id;
|
|
610
|
-
const subscription = await ctx.context.adapter.findOne({
|
|
660
|
+
const subscription = ctx.body.subscriptionId ? await ctx.context.adapter.findOne({
|
|
611
661
|
model: "subscription",
|
|
612
662
|
where: [
|
|
613
663
|
{
|
|
614
|
-
field: "
|
|
615
|
-
value:
|
|
664
|
+
field: "id",
|
|
665
|
+
value: ctx.body.subscriptionId
|
|
616
666
|
}
|
|
617
667
|
]
|
|
618
|
-
})
|
|
668
|
+
}) : await ctx.context.adapter.findMany({
|
|
669
|
+
model: "subscription",
|
|
670
|
+
where: [{ field: "referenceId", value: referenceId }]
|
|
671
|
+
}).then(
|
|
672
|
+
(subs) => subs.find(
|
|
673
|
+
(sub) => sub.status === "active" || sub.status === "trialing"
|
|
674
|
+
)
|
|
675
|
+
);
|
|
619
676
|
if (!subscription || !subscription.stripeCustomerId) {
|
|
620
677
|
throw ctx.error("BAD_REQUEST", {
|
|
621
678
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
@@ -656,7 +713,7 @@ const stripe = (options) => {
|
|
|
656
713
|
ctx,
|
|
657
714
|
`${ctx.context.baseURL}/subscription/cancel/callback?callbackURL=${encodeURIComponent(
|
|
658
715
|
ctx.body?.returnUrl || "/"
|
|
659
|
-
)}&
|
|
716
|
+
)}&subscriptionId=${encodeURIComponent(subscription.id)}`
|
|
660
717
|
),
|
|
661
718
|
flow_data: {
|
|
662
719
|
type: "subscription_cancel",
|
|
@@ -738,10 +795,11 @@ const stripe = (options) => {
|
|
|
738
795
|
"/subscription/success",
|
|
739
796
|
{
|
|
740
797
|
method: "GET",
|
|
741
|
-
query: zod.z.record(zod.z.string(), zod.z.any()).optional()
|
|
798
|
+
query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
|
|
799
|
+
use: [api.originCheck((ctx) => ctx.query.callbackURL)]
|
|
742
800
|
},
|
|
743
801
|
async (ctx) => {
|
|
744
|
-
if (!ctx.query || !ctx.query.callbackURL || !ctx.query.
|
|
802
|
+
if (!ctx.query || !ctx.query.callbackURL || !ctx.query.subscriptionId) {
|
|
745
803
|
throw ctx.redirect(getUrl(ctx, ctx.query?.callbackURL || "/"));
|
|
746
804
|
}
|
|
747
805
|
const session = await api.getSessionFromCtx(
|
|
@@ -751,38 +809,24 @@ const stripe = (options) => {
|
|
|
751
809
|
throw ctx.redirect(getUrl(ctx, ctx.query?.callbackURL || "/"));
|
|
752
810
|
}
|
|
753
811
|
const { user } = session;
|
|
754
|
-
const { callbackURL,
|
|
755
|
-
const
|
|
812
|
+
const { callbackURL, subscriptionId } = ctx.query;
|
|
813
|
+
const subscription = await ctx.context.adapter.findOne({
|
|
756
814
|
model: "subscription",
|
|
757
815
|
where: [
|
|
758
816
|
{
|
|
759
|
-
field: "
|
|
760
|
-
value:
|
|
817
|
+
field: "id",
|
|
818
|
+
value: subscriptionId
|
|
761
819
|
}
|
|
762
820
|
]
|
|
763
821
|
});
|
|
764
|
-
|
|
765
|
-
(sub) => sub.status === "active" || sub.status === "trialing"
|
|
766
|
-
);
|
|
767
|
-
if (activeSubscription) {
|
|
822
|
+
if (subscription?.status === "active" || subscription?.status === "trialing") {
|
|
768
823
|
return ctx.redirect(getUrl(ctx, callbackURL));
|
|
769
824
|
}
|
|
770
|
-
|
|
825
|
+
const customerId = subscription?.stripeCustomerId || user.stripeCustomerId;
|
|
826
|
+
if (customerId) {
|
|
771
827
|
try {
|
|
772
|
-
const subscription = await ctx.context.adapter.findOne({
|
|
773
|
-
model: "subscription",
|
|
774
|
-
where: [
|
|
775
|
-
{
|
|
776
|
-
field: "referenceId",
|
|
777
|
-
value: reference
|
|
778
|
-
}
|
|
779
|
-
]
|
|
780
|
-
});
|
|
781
|
-
if (!subscription || subscription.status === "active") {
|
|
782
|
-
throw ctx.redirect(getUrl(ctx, callbackURL));
|
|
783
|
-
}
|
|
784
828
|
const stripeSubscription = await client.subscriptions.list({
|
|
785
|
-
customer:
|
|
829
|
+
customer: customerId,
|
|
786
830
|
status: "active"
|
|
787
831
|
}).then((res) => res.data[0]);
|
|
788
832
|
if (stripeSubscription) {
|
|
@@ -790,21 +834,33 @@ const stripe = (options) => {
|
|
|
790
834
|
options,
|
|
791
835
|
stripeSubscription.items.data[0]?.plan.id
|
|
792
836
|
);
|
|
793
|
-
if (plan &&
|
|
837
|
+
if (plan && subscription) {
|
|
794
838
|
await ctx.context.adapter.update({
|
|
795
839
|
model: "subscription",
|
|
796
840
|
update: {
|
|
797
841
|
status: stripeSubscription.status,
|
|
798
842
|
seats: stripeSubscription.items.data[0]?.quantity || 1,
|
|
799
843
|
plan: plan.name.toLowerCase(),
|
|
800
|
-
periodEnd:
|
|
801
|
-
|
|
802
|
-
|
|
844
|
+
periodEnd: new Date(
|
|
845
|
+
stripeSubscription.current_period_end * 1e3
|
|
846
|
+
),
|
|
847
|
+
periodStart: new Date(
|
|
848
|
+
stripeSubscription.current_period_start * 1e3
|
|
849
|
+
),
|
|
850
|
+
stripeSubscriptionId: stripeSubscription.id,
|
|
851
|
+
...stripeSubscription.trial_start && stripeSubscription.trial_end ? {
|
|
852
|
+
trialStart: new Date(
|
|
853
|
+
stripeSubscription.trial_start * 1e3
|
|
854
|
+
),
|
|
855
|
+
trialEnd: new Date(
|
|
856
|
+
stripeSubscription.trial_end * 1e3
|
|
857
|
+
)
|
|
858
|
+
} : {}
|
|
803
859
|
},
|
|
804
860
|
where: [
|
|
805
861
|
{
|
|
806
|
-
field: "
|
|
807
|
-
value:
|
|
862
|
+
field: "id",
|
|
863
|
+
value: subscription.id
|
|
808
864
|
}
|
|
809
865
|
]
|
|
810
866
|
});
|
|
@@ -847,7 +903,11 @@ const stripe = (options) => {
|
|
|
847
903
|
message: "Stripe webhook secret not found"
|
|
848
904
|
});
|
|
849
905
|
}
|
|
850
|
-
event = client.webhooks.
|
|
906
|
+
event = await client.webhooks.constructEventAsync(
|
|
907
|
+
buf,
|
|
908
|
+
sig,
|
|
909
|
+
webhookSecret
|
|
910
|
+
);
|
|
851
911
|
} catch (err) {
|
|
852
912
|
ctx.context.logger.error(`${err.message}`);
|
|
853
913
|
throw new api.APIError("BAD_REQUEST", {
|
|
@@ -900,18 +960,29 @@ const stripe = (options) => {
|
|
|
900
960
|
userId: user.id
|
|
901
961
|
}
|
|
902
962
|
});
|
|
903
|
-
await ctx2.context.adapter.update(
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
963
|
+
const customer = await ctx2.context.adapter.update(
|
|
964
|
+
{
|
|
965
|
+
model: "user",
|
|
966
|
+
update: {
|
|
967
|
+
stripeCustomerId: stripeCustomer.id
|
|
968
|
+
},
|
|
969
|
+
where: [
|
|
970
|
+
{
|
|
971
|
+
field: "id",
|
|
972
|
+
value: user.id
|
|
973
|
+
}
|
|
974
|
+
]
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
if (!customer) {
|
|
978
|
+
betterAuth.logger.error("#BETTER_AUTH: Failed to create customer");
|
|
979
|
+
} else {
|
|
980
|
+
await options.onCustomerCreate?.({
|
|
981
|
+
customer,
|
|
982
|
+
stripeCustomer,
|
|
983
|
+
user
|
|
984
|
+
});
|
|
985
|
+
}
|
|
915
986
|
}
|
|
916
987
|
}
|
|
917
988
|
}
|
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;
|
|
@@ -330,8 +337,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
330
337
|
metadata?: Record<string, any> | undefined;
|
|
331
338
|
annual?: boolean | undefined;
|
|
332
339
|
referenceId?: string | undefined;
|
|
340
|
+
subscriptionId?: string | undefined;
|
|
333
341
|
seats?: number | undefined;
|
|
334
|
-
uiMode?: "embedded" | "hosted" | undefined;
|
|
335
342
|
successUrl?: string | undefined;
|
|
336
343
|
cancelUrl?: string | undefined;
|
|
337
344
|
returnUrl?: string | undefined;
|
|
@@ -503,25 +510,60 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
503
510
|
options: {
|
|
504
511
|
method: "POST";
|
|
505
512
|
body: z.ZodObject<{
|
|
513
|
+
/**
|
|
514
|
+
* The name of the plan to subscribe
|
|
515
|
+
*/
|
|
506
516
|
plan: z.ZodString;
|
|
517
|
+
/**
|
|
518
|
+
* If annual plan should be applied.
|
|
519
|
+
*/
|
|
507
520
|
annual: z.ZodOptional<z.ZodBoolean>;
|
|
521
|
+
/**
|
|
522
|
+
* Reference id of the subscription to upgrade
|
|
523
|
+
* This is used to identify the subscription to upgrade
|
|
524
|
+
* If not provided, the user's id will be used
|
|
525
|
+
*/
|
|
508
526
|
referenceId: z.ZodOptional<z.ZodString>;
|
|
527
|
+
/**
|
|
528
|
+
* This is to allow a specific subscription to be upgrade.
|
|
529
|
+
* If subscription id is provided, and subscription isn't found,
|
|
530
|
+
* it'll throw an error.
|
|
531
|
+
*/
|
|
532
|
+
subscriptionId: z.ZodOptional<z.ZodString>;
|
|
533
|
+
/**
|
|
534
|
+
* Any additional data you want to store in your database
|
|
535
|
+
* subscriptions
|
|
536
|
+
*/
|
|
509
537
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
538
|
+
/**
|
|
539
|
+
* If a subscription
|
|
540
|
+
*/
|
|
510
541
|
seats: z.ZodOptional<z.ZodNumber>;
|
|
511
|
-
|
|
542
|
+
/**
|
|
543
|
+
* Success url to redirect back after successful subscription
|
|
544
|
+
*/
|
|
512
545
|
successUrl: z.ZodDefault<z.ZodString>;
|
|
546
|
+
/**
|
|
547
|
+
* Cancel URL
|
|
548
|
+
*/
|
|
513
549
|
cancelUrl: z.ZodDefault<z.ZodString>;
|
|
550
|
+
/**
|
|
551
|
+
* Return URL
|
|
552
|
+
*/
|
|
514
553
|
returnUrl: z.ZodOptional<z.ZodString>;
|
|
554
|
+
/**
|
|
555
|
+
* Disable Redirect
|
|
556
|
+
*/
|
|
515
557
|
disableRedirect: z.ZodDefault<z.ZodBoolean>;
|
|
516
558
|
}, "strip", z.ZodTypeAny, {
|
|
517
559
|
plan: string;
|
|
518
|
-
uiMode: "embedded" | "hosted";
|
|
519
560
|
successUrl: string;
|
|
520
561
|
cancelUrl: string;
|
|
521
562
|
disableRedirect: boolean;
|
|
522
563
|
metadata?: Record<string, any> | undefined;
|
|
523
564
|
annual?: boolean | undefined;
|
|
524
565
|
referenceId?: string | undefined;
|
|
566
|
+
subscriptionId?: string | undefined;
|
|
525
567
|
seats?: number | undefined;
|
|
526
568
|
returnUrl?: string | undefined;
|
|
527
569
|
}, {
|
|
@@ -529,8 +571,8 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
529
571
|
metadata?: Record<string, any> | undefined;
|
|
530
572
|
annual?: boolean | undefined;
|
|
531
573
|
referenceId?: string | undefined;
|
|
574
|
+
subscriptionId?: string | undefined;
|
|
532
575
|
seats?: number | undefined;
|
|
533
|
-
uiMode?: "embedded" | "hosted" | undefined;
|
|
534
576
|
successUrl?: string | undefined;
|
|
535
577
|
cancelUrl?: string | undefined;
|
|
536
578
|
returnUrl?: string | undefined;
|
|
@@ -603,6 +645,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
603
645
|
options: {
|
|
604
646
|
method: "GET";
|
|
605
647
|
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
648
|
+
use: ((inputContext: {
|
|
649
|
+
body?: any;
|
|
650
|
+
query?: Record<string, any> | undefined;
|
|
651
|
+
request?: Request | undefined;
|
|
652
|
+
headers?: Headers | undefined;
|
|
653
|
+
asResponse?: boolean | undefined;
|
|
654
|
+
returnHeaders?: boolean | undefined;
|
|
655
|
+
use?: better_call.Middleware[] | undefined;
|
|
656
|
+
}) => Promise<void>)[];
|
|
606
657
|
} & {
|
|
607
658
|
use: any[];
|
|
608
659
|
};
|
|
@@ -613,6 +664,7 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
613
664
|
body: {
|
|
614
665
|
returnUrl: string;
|
|
615
666
|
referenceId?: string | undefined;
|
|
667
|
+
subscriptionId?: string | undefined;
|
|
616
668
|
};
|
|
617
669
|
method?: "POST" | undefined;
|
|
618
670
|
query?: Record<string, any> | undefined;
|
|
@@ -641,13 +693,16 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
641
693
|
method: "POST";
|
|
642
694
|
body: z.ZodObject<{
|
|
643
695
|
referenceId: z.ZodOptional<z.ZodString>;
|
|
696
|
+
subscriptionId: z.ZodOptional<z.ZodString>;
|
|
644
697
|
returnUrl: z.ZodString;
|
|
645
698
|
}, "strip", z.ZodTypeAny, {
|
|
646
699
|
returnUrl: string;
|
|
647
700
|
referenceId?: string | undefined;
|
|
701
|
+
subscriptionId?: string | undefined;
|
|
648
702
|
}, {
|
|
649
703
|
returnUrl: string;
|
|
650
704
|
referenceId?: string | undefined;
|
|
705
|
+
subscriptionId?: string | undefined;
|
|
651
706
|
}>;
|
|
652
707
|
use: (((inputContext: {
|
|
653
708
|
body?: any;
|
|
@@ -823,6 +878,15 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
|
|
|
823
878
|
options: {
|
|
824
879
|
method: "GET";
|
|
825
880
|
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
881
|
+
use: ((inputContext: {
|
|
882
|
+
body?: any;
|
|
883
|
+
query?: Record<string, any> | undefined;
|
|
884
|
+
request?: Request | undefined;
|
|
885
|
+
headers?: Headers | undefined;
|
|
886
|
+
asResponse?: boolean | undefined;
|
|
887
|
+
returnHeaders?: boolean | undefined;
|
|
888
|
+
use?: better_call.Middleware[] | undefined;
|
|
889
|
+
}) => Promise<void>)[];
|
|
826
890
|
} & {
|
|
827
891
|
use: any[];
|
|
828
892
|
};
|