a tool for shared writing and social publishing
at main 44 lines 1.1 kB view raw
1export const PRODUCT_DEF_ID = "leaflet_pro_v1"; 2 3export const PRODUCT_DEFINITION = { 4 name: "Leaflet Pro", 5 metadata: { 6 product_def_id: PRODUCT_DEF_ID, 7 entitlements: JSON.stringify({ publication_analytics: true, pro_plan_visible: true }), 8 }, 9}; 10 11export const PRICE_DEFINITIONS = { 12 month: { 13 lookup_key: "leaflet_pro_monthly_v1_usd", 14 unit_amount: 1200, 15 currency: "usd", 16 recurring: { interval: "month" as const }, 17 }, 18 year: { 19 lookup_key: "leaflet_pro_yearly_v1_usd", 20 unit_amount: 12000, 21 currency: "usd", 22 recurring: { interval: "year" as const }, 23 }, 24}; 25 26export async function getPriceId( 27 cadence: "month" | "year", 28): Promise<string | null> { 29 const { getStripe } = await import("./client"); 30 const key = PRICE_DEFINITIONS[cadence].lookup_key; 31 const prices = await getStripe().prices.list({ lookup_keys: [key] }); 32 return prices.data[0]?.id ?? null; 33} 34 35export function parseEntitlements( 36 metadata: Record<string, string> | null, 37): Record<string, boolean> { 38 if (!metadata?.entitlements) return {}; 39 try { 40 return JSON.parse(metadata.entitlements); 41 } catch { 42 return {}; 43 } 44}