|
| 1 | +export const SUBSCRIPTION_DISPLAY_NAME = 'Strong' as const |
| 2 | + |
| 3 | +export interface TierConfig { |
| 4 | + monthlyPrice: number |
| 5 | + creditsPerBlock: number |
| 6 | + blockDurationHours: number |
| 7 | + weeklyCreditsLimit: number |
| 8 | +} |
| 9 | + |
| 10 | +export const SUBSCRIPTION_TIERS = { |
| 11 | + 100: { |
| 12 | + monthlyPrice: 100, |
| 13 | + creditsPerBlock: 400, |
| 14 | + blockDurationHours: 5, |
| 15 | + weeklyCreditsLimit: 4000, |
| 16 | + }, |
| 17 | + 200: { |
| 18 | + monthlyPrice: 200, |
| 19 | + creditsPerBlock: 1200, |
| 20 | + blockDurationHours: 5, |
| 21 | + weeklyCreditsLimit: 12000, |
| 22 | + }, |
| 23 | + 500: { |
| 24 | + monthlyPrice: 500, |
| 25 | + creditsPerBlock: 3200, |
| 26 | + blockDurationHours: 5, |
| 27 | + weeklyCreditsLimit: 32000, |
| 28 | + }, |
| 29 | +} as const satisfies Record<number, TierConfig> |
| 30 | + |
| 31 | +export type SubscriptionTierPrice = keyof typeof SUBSCRIPTION_TIERS |
| 32 | + |
| 33 | +export const DEFAULT_TIER = SUBSCRIPTION_TIERS[200] |
| 34 | + |
| 35 | +export function createSubscriptionPriceMappings(priceIds: Record<SubscriptionTierPrice, string>) { |
| 36 | + const priceToTier = Object.fromEntries( |
| 37 | + Object.entries(priceIds).map(([tier, priceId]) => [priceId, Number(tier) as SubscriptionTierPrice]), |
| 38 | + ) as Record<string, SubscriptionTierPrice> |
| 39 | + |
| 40 | + function getTierFromPriceId(priceId: string): SubscriptionTierPrice | null { |
| 41 | + return priceToTier[priceId] ?? null |
| 42 | + } |
| 43 | + |
| 44 | + function getPriceIdFromTier(tier: SubscriptionTierPrice): string | null { |
| 45 | + return priceIds[tier] ?? null |
| 46 | + } |
| 47 | + |
| 48 | + return { getTierFromPriceId, getPriceIdFromTier } |
| 49 | +} |
0 commit comments