Openstatus www.openstatus.dev
at 4c0f4c00a38753a5d0dfd7e7b7b7706dec6f1503 103 lines 2.5 kB view raw
1// Shamelessly stolen from dub.co 2 3import type { WorkspacePlan } from "@openstatus/db/src/schema"; 4import type { Addons } from "@openstatus/db/src/schema/plan/schema"; 5 6export const getPlanFromPriceId = (priceId: string) => { 7 const env = 8 process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test"; 9 return PLANS.find((plan) => plan.price.monthly.priceIds[env] === priceId); 10}; 11 12export const getFeatureFromPriceId = (priceId: string) => { 13 const env = 14 process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test"; 15 return FEATURES.find( 16 (feature) => feature.price.monthly.priceIds[env] === priceId, 17 ); 18}; 19 20export const getPriceIdForPlan = (plan: WorkspacePlan) => { 21 const env = 22 process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test"; 23 return PLANS.find((p) => p.plan === plan)?.price.monthly.priceIds[env]; 24}; 25 26export const getPriceIdForFeature = (feature: keyof Addons) => { 27 const env = 28 process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test"; 29 return FEATURES.find((f) => f.feature === feature)?.price.monthly.priceIds[ 30 env 31 ]; 32}; 33 34export const PLANS = [ 35 { 36 plan: "team", 37 price: { 38 monthly: { 39 priceIds: { 40 test: "price_1OVHQDBXJcTfzsyJjfiXl10Y", 41 production: "price_1RxsLNBXJcTfzsyJ7La5Jn5y", 42 }, 43 }, 44 }, 45 }, 46 { 47 plan: "starter", 48 price: { 49 monthly: { 50 priceIds: { 51 test: "price_1OVHPlBXJcTfzsyJvPlB1kNb", 52 production: "price_1RxsJzBXJcTfzsyJBOztaKlR", 53 }, 54 }, 55 }, 56 }, 57] satisfies Array<{ 58 plan: WorkspacePlan; 59 price: { 60 monthly: { priceIds: { test: string; production: string } }; 61 }; 62}>; 63 64export const FEATURES = [ 65 { 66 feature: "email-domain-protection", 67 price: { 68 monthly: { 69 priceIds: { 70 test: "price_1Sl4xqBXJcTfzsyJlzpD1DDm", 71 production: "price_1Sl6oqBXJcTfzsyJCxtzDIx5", 72 }, 73 }, 74 }, 75 }, 76 { 77 feature: "white-label", 78 price: { 79 monthly: { 80 priceIds: { 81 test: "price_1SlbQsBXJcTfzsyJ1awtpOno", 82 production: "price_1SlbSdBXJcTfzsyJahJiFE8D", 83 }, 84 }, 85 }, 86 }, 87 { 88 feature: "status-pages", 89 price: { 90 monthly: { 91 priceIds: { 92 test: "price_1Slrk8BXJcTfzsyJXQxshFU4", 93 production: "price_1SlrkHBXJcTfzsyJIxHeKUYe", 94 }, 95 }, 96 }, 97 }, 98] satisfies Array<{ 99 feature: keyof Addons; 100 price: { 101 monthly: { priceIds: { test: string; production: string } }; 102 }; 103}>;