mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-21 08:21:32 +03:00
feat(server): ai trial support (#9031)
This commit is contained in:
parent
5bf8ed1095
commit
4c39b89b98
@ -148,6 +148,15 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
||||
return { allow_promotion_codes: true };
|
||||
})();
|
||||
|
||||
const trials = (() => {
|
||||
if (lookupKey.plan === SubscriptionPlan.AI && !strategy.aiSubscribed) {
|
||||
return {
|
||||
trial_period_days: 7,
|
||||
} as Stripe.Checkout.SessionCreateParams.SubscriptionData;
|
||||
}
|
||||
return undefined;
|
||||
})();
|
||||
|
||||
// mode: 'subscription' or 'payment' for lifetime and onetime payment
|
||||
const mode =
|
||||
lookupKey.recurring === SubscriptionRecurring.Lifetime ||
|
||||
@ -169,11 +178,17 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
customer_update: {
|
||||
name: 'auto',
|
||||
},
|
||||
tax_id_collection: {
|
||||
enabled: true,
|
||||
},
|
||||
...discounts,
|
||||
...mode,
|
||||
subscription_data: {
|
||||
...trials,
|
||||
},
|
||||
success_url: this.url.link(params.successCallbackLink, {
|
||||
session_id: '{CHECKOUT_SESSION_ID}',
|
||||
}),
|
||||
|
@ -115,6 +115,7 @@ export class WorkspaceSubscriptionManager extends SubscriptionManager {
|
||||
success_url: this.url.link(params.successCallbackLink),
|
||||
customer: customer.stripeCustomerId,
|
||||
subscription_data: {
|
||||
trial_period_days: 15,
|
||||
metadata: {
|
||||
workspaceId: args.workspaceId,
|
||||
},
|
||||
|
@ -279,7 +279,7 @@ export class SubscriptionResolver {
|
||||
throw new FailedToCheckout();
|
||||
}
|
||||
|
||||
return session;
|
||||
return session.url;
|
||||
}
|
||||
|
||||
@Mutation(() => String, {
|
||||
@ -322,7 +322,7 @@ export class SubscriptionResolver {
|
||||
|
||||
return this.service.cancelSubscription(
|
||||
{
|
||||
targetId: user.id,
|
||||
userId: user.id,
|
||||
// @ts-expect-error exam inside
|
||||
plan,
|
||||
},
|
||||
@ -363,7 +363,7 @@ export class SubscriptionResolver {
|
||||
|
||||
return this.service.resumeSubscription(
|
||||
{
|
||||
targetId: user.id,
|
||||
userId: user.id,
|
||||
// @ts-expect-error exam inside
|
||||
plan,
|
||||
},
|
||||
@ -433,7 +433,9 @@ export class UserSubscriptionResolver {
|
||||
const subscriptions = await this.db.subscription.findMany({
|
||||
where: {
|
||||
targetId: user.id,
|
||||
status: SubscriptionStatus.Active,
|
||||
status: {
|
||||
in: [SubscriptionStatus.Active, SubscriptionStatus.Trialing],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user