import type { SubscriptionTier } from '@/lib/entitlements'; export type BillingTier = 'PRO' | 'BUSINESS'; export type BillingInterval = 'month' | 'year'; export function resolvePriceId(tier: BillingTier, interval: BillingInterval): string { const map: Record> = { PRO: { month: process.env.STRIPE_PRICE_PRO_MONTHLY!, year: process.env.STRIPE_PRICE_PRO_ANNUAL!, }, BUSINESS: { month: process.env.STRIPE_PRICE_BUSINESS_MONTHLY!, year: process.env.STRIPE_PRICE_BUSINESS_ANNUAL!, }, }; const priceId = map[tier][interval]; if (!priceId) { throw new Error(`No Stripe price ID configured for ${tier}/${interval}`); } return priceId; } export function priceIdToTier(priceId: string): SubscriptionTier | null { const entries: Array<[string | undefined, SubscriptionTier]> = [ [process.env.STRIPE_PRICE_PRO_MONTHLY, 'PRO'], [process.env.STRIPE_PRICE_PRO_ANNUAL, 'PRO'], [process.env.STRIPE_PRICE_BUSINESS_MONTHLY, 'BUSINESS'], [process.env.STRIPE_PRICE_BUSINESS_ANNUAL, 'BUSINESS'], ]; for (const [envPriceId, tier] of entries) { if (envPriceId && envPriceId === priceId) return tier; } return null; }