mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat(server): add lifetime plan flag (#7443)
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import type { Stripe } from 'stripe';
|
||||
|
||||
import { defineStartupConfig, ModuleConfig } from '../../fundamentals/config';
|
||||
import {
|
||||
defineRuntimeConfig,
|
||||
defineStartupConfig,
|
||||
ModuleConfig,
|
||||
} from '../../fundamentals/config';
|
||||
|
||||
export interface PaymentStartupConfig {
|
||||
stripe?: {
|
||||
@@ -11,10 +15,20 @@ export interface PaymentStartupConfig {
|
||||
} & Stripe.StripeConfig;
|
||||
}
|
||||
|
||||
export interface PaymentRuntimeConfig {
|
||||
showLifetimePrice: boolean;
|
||||
}
|
||||
|
||||
declare module '../config' {
|
||||
interface PluginsConfig {
|
||||
payment: ModuleConfig<PaymentStartupConfig>;
|
||||
payment: ModuleConfig<PaymentStartupConfig, PaymentRuntimeConfig>;
|
||||
}
|
||||
}
|
||||
|
||||
defineStartupConfig('plugins.payment', {});
|
||||
defineRuntimeConfig('plugins.payment', {
|
||||
showLifetimePrice: {
|
||||
desc: 'Whether enable lifetime price and allow user to pay for it.',
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -121,8 +121,14 @@ export class SubscriptionService {
|
||||
});
|
||||
}
|
||||
|
||||
const lifetimePriceEnabled = await this.config.runtime.fetch(
|
||||
'plugins.payment/showLifetimePrice'
|
||||
);
|
||||
|
||||
const list = await this.stripe.prices.list({
|
||||
active: true,
|
||||
// only list recurring prices if lifetime price is not enabled
|
||||
...(lifetimePriceEnabled ? {} : { type: 'recurring' }),
|
||||
});
|
||||
|
||||
return list.data.filter(price => {
|
||||
@@ -807,6 +813,16 @@ export class SubscriptionService {
|
||||
recurring: SubscriptionRecurring,
|
||||
variant?: SubscriptionPriceVariant
|
||||
): Promise<string> {
|
||||
if (recurring === SubscriptionRecurring.Lifetime) {
|
||||
const lifetimePriceEnabled = await this.config.runtime.fetch(
|
||||
'plugins.payment/showLifetimePrice'
|
||||
);
|
||||
|
||||
if (!lifetimePriceEnabled) {
|
||||
throw new ActionForbidden();
|
||||
}
|
||||
}
|
||||
|
||||
const prices = await this.stripe.prices.list({
|
||||
lookup_keys: [encodeLookupKey(plan, recurring, variant)],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user