From 0945e7cfd63fe44a28cd4407b379db88bca51bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Wed, 14 Jun 2023 13:11:04 +0200 Subject: [PATCH] fix: disallow self-serve downgrades from Enterprise/Team --- .../[ref]/settings/billing/update/enterprise.tsx | 16 +++++++++++++--- .../[ref]/settings/billing/update/free.tsx | 11 +++++++++-- .../[ref]/settings/billing/update/pro.tsx | 15 +++++++++++++++ .../[ref]/settings/billing/update/team.tsx | 16 ++++++++++++++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx b/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx index 07e07e49304..07ed3f3ba42 100644 --- a/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx +++ b/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx @@ -41,10 +41,20 @@ const BillingUpdateEnterprise: NextPageWithLayout = () => { }, [orgSlug]) useEffect(() => { - if (subscription !== undefined && !isEnterprise) { - router.push(`/project/${projectRef}/settings/billing/update`) + if (subscription && !isEnterprise) { + if (subscription.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.TEAM) { + router.push(`/project/${projectRef}/settings/billing/update/team`) + } else if ( + [PRICING_TIER_PRODUCT_IDS.PAYG, PRICING_TIER_PRODUCT_IDS.PRO].includes( + subscription.tier.supabase_prod_id + ) + ) { + router.push(`/project/${projectRef}/settings/billing/update/pro`) + } else { + router.push(`/project/${projectRef}/settings/billing/update`) + } } - }, [subscription]) + }, [subscription, isEnterprise, projectRef, router]) const getStripeProducts = async () => { try { diff --git a/studio/pages/project/[ref]/settings/billing/update/free.tsx b/studio/pages/project/[ref]/settings/billing/update/free.tsx index efd5b49a206..4a6f6205aa5 100644 --- a/studio/pages/project/[ref]/settings/billing/update/free.tsx +++ b/studio/pages/project/[ref]/settings/billing/update/free.tsx @@ -30,10 +30,17 @@ const BillingUpdateFree: NextPageWithLayout = () => { }, [projectRef]) useEffect(() => { - if (isEnterprise) { + if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE) { + // no self-serve downgrade from Enterprise router.push(`/project/${projectRef}/settings/billing/update/enterprise`) + } else if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.TEAM) { + // no self-serve downgrade from Team + router.push(`/project/${projectRef}/settings/billing/update/team`) + } else if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.FREE) { + // Downgrade from free to free is not possible, so let's redirect + router.push(`/project/${projectRef}/settings/billing/update`) } - }, [subscription]) + }, [subscription, projectRef, router]) const getStripeProducts = async () => { try { diff --git a/studio/pages/project/[ref]/settings/billing/update/pro.tsx b/studio/pages/project/[ref]/settings/billing/update/pro.tsx index 7884a282b3a..5bcb5c11768 100644 --- a/studio/pages/project/[ref]/settings/billing/update/pro.tsx +++ b/studio/pages/project/[ref]/settings/billing/update/pro.tsx @@ -36,6 +36,21 @@ const BillingUpdatePro: NextPageWithLayout = () => { } }, []) + useEffect(() => { + if ( + subscription && + ![PRICING_TIER_PRODUCT_IDS.PAYG, PRICING_TIER_PRODUCT_IDS.PRO].includes( + subscription.tier.supabase_prod_id + ) + ) { + if (subscription.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE) { + router.push(`/project/${projectRef}/settings/billing/update/enterprise`) + } else if (subscription.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.TEAM) { + router.push(`/project/${projectRef}/settings/billing/update/team`) + } + } + }, [subscription, projectRef, router]) + useEffect(() => { if (projectRef) { getStripeProducts() diff --git a/studio/pages/project/[ref]/settings/billing/update/team.tsx b/studio/pages/project/[ref]/settings/billing/update/team.tsx index 5907f56e72f..31d04f8547b 100644 --- a/studio/pages/project/[ref]/settings/billing/update/team.tsx +++ b/studio/pages/project/[ref]/settings/billing/update/team.tsx @@ -50,10 +50,22 @@ const BillingUpdateTeam: NextPageWithLayout = () => { }, [orgSlug]) useEffect(() => { - if (isEnterprise) { + if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE) { router.push(`/project/${projectRef}/settings/billing/update/enterprise`) + } else if ( + subscription && + [PRICING_TIER_PRODUCT_IDS.PAYG, PRICING_TIER_PRODUCT_IDS.PRO].includes( + subscription.tier.supabase_prod_id + ) + ) { + router.push(`/project/${projectRef}/settings/billing/update/pro`) + } else if ( + subscription && + subscription.tier.supabase_prod_id !== PRICING_TIER_PRODUCT_IDS.TEAM + ) { + router.push(`/project/${projectRef}/settings/billing/update`) } - }, [subscription]) + }, [subscription, projectRef, router]) const getStripeProducts = async () => { try {