Skip to content

Commit 99a57f9

Browse files
committed
feat(billing): enhance billing plan management with product and pricing configurations
- Added support for billing plan products and pricing settings, allowing for detailed configuration of subscription plans. - Introduced new constants and types for managing billing plan overrides, products, and pricing. - Updated the SystemSettingService to handle new billing-related settings and integrated them into the admin interface. - Enhanced the BillingPlanService to retrieve and apply product and pricing information for tenant plans. - Updated UI components to reflect the new billing plan configurations and ensure proper display of pricing details. Signed-off-by: Innei <tukon479@gmail.com>
1 parent af3b5b9 commit 99a57f9

File tree

32 files changed

+2677
-231
lines changed

32 files changed

+2677
-231
lines changed

be/apps/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@afilmory/task-queue": "workspace:*",
2626
"@afilmory/utils": "workspace:*",
2727
"@aws-sdk/client-s3": "3.929.0",
28+
"@creem_io/better-auth": "0.0.8",
2829
"@hono/node-server": "^1.19.6",
2930
"@resvg/resvg-js": "2.6.2",
3031
"better-auth": "1.3.34",

be/apps/core/src/modules/configuration/system-setting/system-setting.constants.ts

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import { DEFAULT_BASE_DOMAIN } from '@afilmory/utils'
2+
import {
3+
BILLING_PLAN_DEFINITIONS,
4+
BILLING_PLAN_IDS,
5+
BILLING_PLAN_OVERRIDES_SETTING_KEY,
6+
BILLING_PLAN_PRICING_SETTING_KEY,
7+
BILLING_PLAN_PRODUCTS_SETTING_KEY,
8+
} from 'core/modules/platform/billing/billing-plan.constants'
9+
import type { BillingPlanId, BillingPlanQuota } from 'core/modules/platform/billing/billing-plan.types'
210
import { z } from 'zod'
311

412
const nonEmptyString = z.string().trim().min(1)
@@ -88,9 +96,74 @@ export const SYSTEM_SETTING_DEFINITIONS = {
8896
defaultValue: null as string | null,
8997
isSensitive: true,
9098
},
99+
billingPlanOverrides: {
100+
key: BILLING_PLAN_OVERRIDES_SETTING_KEY,
101+
schema: z.record(z.string(), z.any()),
102+
defaultValue: {},
103+
isSensitive: false,
104+
},
105+
billingPlanProducts: {
106+
key: BILLING_PLAN_PRODUCTS_SETTING_KEY,
107+
schema: z.record(z.string(), z.any()),
108+
defaultValue: {},
109+
isSensitive: false,
110+
},
111+
billingPlanPricing: {
112+
key: BILLING_PLAN_PRICING_SETTING_KEY,
113+
schema: z.record(z.string(), z.any()),
114+
defaultValue: {},
115+
isSensitive: false,
116+
},
91117
} as const
92118

93-
export type SystemSettingField = keyof typeof SYSTEM_SETTING_DEFINITIONS
94-
export type SystemSettingKey = (typeof SYSTEM_SETTING_DEFINITIONS)[SystemSettingField]['key']
119+
const BILLING_PLAN_QUOTA_KEYS = [
120+
'monthlyAssetProcessLimit',
121+
'libraryItemLimit',
122+
'maxUploadSizeMb',
123+
'maxSyncObjectSizeMb',
124+
] as const
125+
export type BillingPlanQuotaFieldKey = (typeof BILLING_PLAN_QUOTA_KEYS)[number]
126+
127+
const BILLING_PLAN_PRICING_KEYS = ['monthlyPrice', 'currency'] as const
128+
export type BillingPlanPricingFieldKey = (typeof BILLING_PLAN_PRICING_KEYS)[number]
129+
130+
const BILLING_PLAN_PAYMENT_KEYS = ['creemProductId'] as const
131+
export type BillingPlanPaymentFieldKey = (typeof BILLING_PLAN_PAYMENT_KEYS)[number]
132+
133+
export type BillingPlanQuotaField = `billingPlan.${BillingPlanId}.quota.${BillingPlanQuotaFieldKey}`
134+
export type BillingPlanPricingField = `billingPlan.${BillingPlanId}.pricing.${BillingPlanPricingFieldKey}`
135+
export type BillingPlanPaymentField = `billingPlan.${BillingPlanId}.payment.${BillingPlanPaymentFieldKey}`
136+
137+
export type BillingPlanSettingField = BillingPlanQuotaField | BillingPlanPricingField | BillingPlanPaymentField
138+
139+
export type SystemSettingDbField = keyof typeof SYSTEM_SETTING_DEFINITIONS
140+
141+
export type SystemSettingField = SystemSettingDbField | BillingPlanSettingField
142+
export type SystemSettingKey = (typeof SYSTEM_SETTING_DEFINITIONS)[SystemSettingDbField]['key']
143+
144+
export const BILLING_PLAN_FIELD_DESCRIPTORS = {
145+
quotas: BILLING_PLAN_IDS.flatMap((planId) =>
146+
BILLING_PLAN_QUOTA_KEYS.map((key) => ({
147+
planId,
148+
key,
149+
field: `billingPlan.${planId}.quota.${key}` as BillingPlanQuotaField,
150+
defaultValue: BILLING_PLAN_DEFINITIONS[planId].quotas[key as keyof BillingPlanQuota],
151+
})),
152+
),
153+
pricing: BILLING_PLAN_IDS.flatMap((planId) =>
154+
BILLING_PLAN_PRICING_KEYS.map((key) => ({
155+
planId,
156+
key,
157+
field: `billingPlan.${planId}.pricing.${key}` as BillingPlanPricingField,
158+
})),
159+
),
160+
payment: BILLING_PLAN_IDS.flatMap((planId) =>
161+
BILLING_PLAN_PAYMENT_KEYS.map((key) => ({
162+
planId,
163+
key,
164+
field: `billingPlan.${planId}.payment.${key}` as BillingPlanPaymentField,
165+
})),
166+
),
167+
} as const
95168

96169
export const SYSTEM_SETTING_KEYS = Object.values(SYSTEM_SETTING_DEFINITIONS).map((definition) => definition.key)

0 commit comments

Comments
 (0)