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