| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import { parseCurrencyDisplayType } from '@/lib/currency'
- import type { BillingSettings } from '../types'
- import { createSectionRegistry } from '../utils/section-registry'
- import { CheckinSettingsSection } from '../general/checkin-settings-section'
- import { PricingSection } from '../general/pricing-section'
- import { QuotaSettingsSection } from '../general/quota-settings-section'
- import { PaymentSettingsSection } from '../integrations/payment-settings-section'
- import { RatioSettingsCard } from '../models/ratio-settings-card'
- const getModelDefaults = (settings: BillingSettings) => ({
- ModelPrice: settings.ModelPrice,
- ModelRatio: settings.ModelRatio,
- CacheRatio: settings.CacheRatio,
- CreateCacheRatio: settings.CreateCacheRatio,
- CompletionRatio: settings.CompletionRatio,
- ImageRatio: settings.ImageRatio,
- AudioRatio: settings.AudioRatio,
- AudioCompletionRatio: settings.AudioCompletionRatio,
- ExposeRatioEnabled: settings.ExposeRatioEnabled,
- BillingMode: settings['billing_setting.billing_mode'],
- BillingExpr: settings['billing_setting.billing_expr'],
- })
- const getGroupDefaults = (settings: BillingSettings) => ({
- TopupGroupRatio: settings.TopupGroupRatio,
- GroupRatio: settings.GroupRatio,
- UserUsableGroups: settings.UserUsableGroups,
- GroupGroupRatio: settings.GroupGroupRatio,
- AutoGroups: settings.AutoGroups,
- DefaultUseAutoGroup: settings.DefaultUseAutoGroup,
- GroupSpecialUsableGroup:
- settings['group_ratio_setting.group_special_usable_group'],
- })
- const BILLING_SECTIONS = [
- {
- id: 'quota',
- titleKey: 'Quota Settings',
- descriptionKey: 'Configure user quota allocation and rewards',
- build: (settings: BillingSettings) => (
- <QuotaSettingsSection
- defaultValues={{
- QuotaForNewUser: settings.QuotaForNewUser,
- PreConsumedQuota: settings.PreConsumedQuota,
- QuotaForInviter: settings.QuotaForInviter,
- QuotaForInvitee: settings.QuotaForInvitee,
- TopUpLink: settings.TopUpLink,
- general_setting: {
- docs_link: settings['general_setting.docs_link'],
- },
- quota_setting: {
- enable_free_model_pre_consume:
- settings['quota_setting.enable_free_model_pre_consume'],
- },
- }}
- />
- ),
- },
- {
- id: 'currency',
- titleKey: 'Currency & Display',
- descriptionKey: 'Configure currency conversion and quota display options',
- build: (settings: BillingSettings) => (
- <PricingSection
- defaultValues={{
- QuotaPerUnit: settings.QuotaPerUnit,
- USDExchangeRate: settings.USDExchangeRate,
- DisplayInCurrencyEnabled: settings.DisplayInCurrencyEnabled,
- DisplayTokenStatEnabled: settings.DisplayTokenStatEnabled,
- general_setting: {
- quota_display_type: parseCurrencyDisplayType(
- settings['general_setting.quota_display_type']
- ),
- custom_currency_symbol:
- settings['general_setting.custom_currency_symbol'] ?? '¤',
- custom_currency_exchange_rate:
- settings['general_setting.custom_currency_exchange_rate'] ?? 1,
- },
- }}
- />
- ),
- },
- {
- id: 'model-pricing',
- titleKey: 'Model Pricing',
- descriptionKey: 'Configure model pricing ratios and tool prices',
- build: (settings: BillingSettings) => (
- <RatioSettingsCard
- titleKey='Model Pricing'
- descriptionKey='Configure model pricing ratios and tool prices'
- modelDefaults={getModelDefaults(settings)}
- groupDefaults={getGroupDefaults(settings)}
- toolPricesDefault={settings['tool_price_setting.prices']}
- visibleTabs={['models', 'tool-prices', 'upstream-sync']}
- />
- ),
- },
- {
- id: 'group-pricing',
- titleKey: 'Group Pricing',
- descriptionKey: 'Configure group ratios and group-specific pricing rules',
- build: (settings: BillingSettings) => (
- <RatioSettingsCard
- titleKey='Group Pricing'
- descriptionKey='Configure group ratios and group-specific pricing rules'
- modelDefaults={getModelDefaults(settings)}
- groupDefaults={getGroupDefaults(settings)}
- toolPricesDefault={settings['tool_price_setting.prices']}
- visibleTabs={['groups']}
- />
- ),
- },
- {
- id: 'payment',
- titleKey: 'Payment Gateway',
- descriptionKey: 'Configure payment gateway integrations',
- build: (settings: BillingSettings) => (
- <PaymentSettingsSection
- defaultValues={{
- PayAddress: settings.PayAddress,
- EpayId: settings.EpayId,
- EpayKey: settings.EpayKey,
- Price: settings.Price,
- MinTopUp: settings.MinTopUp,
- CustomCallbackAddress: settings.CustomCallbackAddress,
- PayMethods: settings.PayMethods,
- AmountOptions: settings['payment_setting.amount_options'],
- AmountDiscount: settings['payment_setting.amount_discount'],
- StripeApiSecret: settings.StripeApiSecret,
- StripeWebhookSecret: settings.StripeWebhookSecret,
- StripePriceId: settings.StripePriceId,
- StripeUnitPrice: settings.StripeUnitPrice,
- StripeMinTopUp: settings.StripeMinTopUp,
- StripePromotionCodesEnabled: settings.StripePromotionCodesEnabled,
- CreemApiKey: settings.CreemApiKey,
- CreemWebhookSecret: settings.CreemWebhookSecret,
- CreemTestMode: settings.CreemTestMode,
- CreemProducts: settings.CreemProducts,
- }}
- waffoDefaultValues={{
- WaffoEnabled: settings.WaffoEnabled ?? false,
- WaffoApiKey: settings.WaffoApiKey ?? '',
- WaffoPrivateKey: settings.WaffoPrivateKey ?? '',
- WaffoPublicCert: settings.WaffoPublicCert ?? '',
- WaffoSandboxPublicCert: settings.WaffoSandboxPublicCert ?? '',
- WaffoSandboxApiKey: settings.WaffoSandboxApiKey ?? '',
- WaffoSandboxPrivateKey: settings.WaffoSandboxPrivateKey ?? '',
- WaffoSandbox: settings.WaffoSandbox ?? false,
- WaffoMerchantId: settings.WaffoMerchantId ?? '',
- WaffoCurrency: settings.WaffoCurrency ?? 'USD',
- WaffoUnitPrice: settings.WaffoUnitPrice ?? 1,
- WaffoMinTopUp: settings.WaffoMinTopUp ?? 1,
- WaffoNotifyUrl: settings.WaffoNotifyUrl ?? '',
- WaffoReturnUrl: settings.WaffoReturnUrl ?? '',
- WaffoPayMethods: settings.WaffoPayMethods ?? '[]',
- }}
- waffoPancakeDefaultValues={{
- WaffoPancakeEnabled: settings.WaffoPancakeEnabled ?? false,
- WaffoPancakeSandbox: settings.WaffoPancakeSandbox ?? false,
- WaffoPancakeMerchantID: settings.WaffoPancakeMerchantID ?? '',
- WaffoPancakePrivateKey: settings.WaffoPancakePrivateKey ?? '',
- WaffoPancakeWebhookPublicKey:
- settings.WaffoPancakeWebhookPublicKey ?? '',
- WaffoPancakeWebhookTestKey:
- settings.WaffoPancakeWebhookTestKey ?? '',
- WaffoPancakeStoreID: settings.WaffoPancakeStoreID ?? '',
- WaffoPancakeProductID: settings.WaffoPancakeProductID ?? '',
- WaffoPancakeReturnURL: settings.WaffoPancakeReturnURL ?? '',
- WaffoPancakeCurrency: settings.WaffoPancakeCurrency ?? 'USD',
- WaffoPancakeUnitPrice: settings.WaffoPancakeUnitPrice ?? 1,
- WaffoPancakeMinTopUp: settings.WaffoPancakeMinTopUp ?? 1,
- }}
- />
- ),
- },
- {
- id: 'checkin',
- titleKey: 'Check-in Rewards',
- descriptionKey: 'Configure daily check-in rewards for users',
- build: (settings: BillingSettings) => (
- <CheckinSettingsSection
- defaultValues={{
- enabled: settings['checkin_setting.enabled'],
- minQuota: settings['checkin_setting.min_quota'],
- maxQuota: settings['checkin_setting.max_quota'],
- }}
- />
- ),
- },
- ] as const
- export type BillingSectionId = (typeof BILLING_SECTIONS)[number]['id']
- const billingRegistry = createSectionRegistry<BillingSectionId, BillingSettings>(
- {
- sections: BILLING_SECTIONS,
- defaultSection: 'quota',
- basePath: '/system-settings/billing',
- urlStyle: 'path',
- }
- )
- export const BILLING_SECTION_IDS = billingRegistry.sectionIds
- export const BILLING_DEFAULT_SECTION = billingRegistry.defaultSection
- export const getBillingSectionNavItems = billingRegistry.getSectionNavItems
- export const getBillingSectionContent = billingRegistry.getSectionContent
|