Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Midway hooking up API for subscription preview

Joshen Limd68193ceb551
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.constant.ts b/studio/components/interfaces/Billing/AddOns/AddOns.constant.ts
deleted file mode 100644
index 73d71e95349..00000000000
--- a/studio/components/interfaces/Billing/AddOns/AddOns.constant.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS } from 'lib/constants'
-
-// Temp hard-code, should fetch all available add ons from API
-export const COMPUTE_SIZES = [
- {
- id: STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS.SMALL,
- name: 'Small',
- description: 'Great for personal projects and experiments',
- specs: '2 CPUs • 1GB memory • 2,085Mbps Disk IO',
- price: 0,
- },
- {
- id: STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS.MEDIUM,
- name: 'Medium',
- description: 'Great for projects that are starting to gain traction',
- specs: '2 CPUs • 4GB memory • 2,085Mbps Disk IO',
- price: 50,
- },
- {
- id: STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS.LARGE,
- name: 'Large',
- description: 'For a large project that receives a decent amount of traffic',
- specs: '2 CPUs • 8GB memory • 4,750Mbps Disk IO',
- price: 100,
- },
- {
- id: STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS.XLARGE,
- name: 'X-Large',
- description: 'For a large project that receives a sizeable amount of traffic',
- specs: '4 CPUs • 16GB memory • 4,750Mbps Disk IO',
- price: 200,
- },
- {
- id: STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS.XXLARGE,
- name: 'XX-Large',
- description: 'For a huge project that receives heavy amount of traffic',
- specs: '8 CPUs • 32GB memory • 4,750Mbps Disk IO',
- price: 400,
- },
-]
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
new file mode 100644
index 00000000000..6132e51d4e4
--- /dev/null
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
@@ -0,0 +1,10 @@
+export const formatComputeSizes = (computeSizes: any[]) => {
+ // Just need to order the options - ideally if the API can filter this that'll be great
+ // but for now just let FE order to get things moving quickly
+ return computeSizes
+ .filter((option: any) => option.name.includes('[Small]'))
+ .concat(computeSizes.filter((option: any) => option.name.includes('[Medium]')))
+ .concat(computeSizes.filter((option: any) => option.name.includes('[Large]')))
+ .concat(computeSizes.filter((option: any) => option.name.includes('[XLarge]')))
+ .concat(computeSizes.filter((option: any) => option.name.includes('[XXLarge]')))
+}
diff --git a/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
index 709beeb7e37..c4ac0877143 100644
--- a/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
+++ b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
@@ -1,15 +1,17 @@
import { FC } from 'react'
import { Radio } from '@supabase/ui'
-import { COMPUTE_SIZES } from './AddOns.constant'
+import { formatComputeSizes } from './AddOns.utils'
// [TODO] please type the vairables properly
interface Props {
+ computeSizes: any[]
selectedComputeSize: any
onSelectOption: (option: any) => void
}
-const ComputeSizeSelection: FC<Props> = ({ selectedComputeSize, onSelectOption }) => {
+const ComputeSizeSelection: FC<Props> = ({ computeSizes, selectedComputeSize, onSelectOption }) => {
+ const formattedComputeSizes = formatComputeSizes(computeSizes)
return (
<div className="space-y-4">
<div>
@@ -19,7 +21,7 @@ const ComputeSizeSelection: FC<Props> = ({ selectedComputeSize, onSelectOption }
</p>
</div>
<Radio.Group type="cards" className="billing-compute-radio">
- {COMPUTE_SIZES.map((option: any) => (
+ {formattedComputeSizes.map((option: any) => (
<Radio
hidden
key={option.id}
@@ -29,11 +31,11 @@ const ComputeSizeSelection: FC<Props> = ({ selectedComputeSize, onSelectOption }
description={
<div>
<p>{option.description}</p>
- <p>{option.specs}</p>
+ <p>{option.metadata.features}</p>
</div>
}
value={option.id}
- optionalLabel={<div>${option.price} / month</div>}
+ optionalLabel={<div>${option.prices[0].unit_amount / 100} / month</div>}
checked={selectedComputeSize?.id === option.id}
onChange={() => onSelectOption(option)}
/>
diff --git a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx
index 6d984e449c3..b7bc9c903cc 100644
--- a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx
+++ b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx
@@ -5,7 +5,7 @@ import { Button, Form, Input, IconArrowLeft } from '@supabase/ui'
import { useStore } from 'hooks'
import { post, patch } from 'lib/common/fetch'
-import { API_URL, STRIPE_TIER_PRICE_IDS } from 'lib/constants'
+import { API_URL } from 'lib/constants'
import { CANCELLATION_REASONS } from '../Billing.constants'
import { generateFeedbackMessage } from './ExitSurvey.utils'
@@ -48,7 +48,8 @@ const ExitSurvey: FC<Props> = ({ onSelectBack }) => {
// })
// Trigger subscription downgrade
- const tier = STRIPE_TIER_PRICE_IDS.FREE
+ // [TODO] please use from API please
+ const tier = 'price_1KCawmJDPojXS6LNahIn31Mr'
const addons: string[] = []
const proration_date = Math.floor(Date.now() / 1000)
const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, {
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx
index 987f13cc044..723197ca741 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx
@@ -56,7 +56,9 @@ const PaymentTotal: FC<Props> = ({
<p>Amount due today</p>
<div className="flex justify-end items-end relative -top-[5px]">
<p className="text-scale-1100 relative -top-[1px]">$</p>
- <p className="text-2xl">{amountDueImmediately.toFixed(2)}</p>
+ <p className="text-2xl">
+ {!hasChangesToPlan ? '0.00' : amountDueImmediately.toFixed(2)}
+ </p>
</div>
</div>
{hasCreditsBalance && (
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
index c73131be329..c37bd0996a8 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
@@ -3,7 +3,6 @@ import { Listbox, IconLoader, Button, Loading, IconPlus } from '@supabase/ui'
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
import { StripeProduct } from '..'
-import { BillingPlan } from '../PlanSelection/Plans/Plans.types'
import { SubscriptionPreview } from '../Billing.types'
import PaymentTotal from './PaymentTotal'
@@ -12,7 +11,7 @@ interface Props {
subscriptionPreview?: SubscriptionPreview
currentPlan: StripeProduct
currentComputeSize: any
- selectedPlan?: BillingPlan
+ selectedPlan?: any
selectedComputeSize: any
isSpendCapEnabled: boolean
paymentMethods?: any
@@ -80,9 +79,9 @@ const PaymentSummaryPanel: FC<Props> = ({
{isChangingPlan && (
<div className="flex items-center justify-between">
<p className="text-sm">
- {selectedPlan?.name} tier {!isSpendCapEnabled ? '(Spend cap disabled)' : ''}
+ {selectedPlan?.name} {!isSpendCapEnabled ? '(Spend cap disabled)' : ''}
</p>
- <p className="text-sm">${selectedPlan?.price?.toFixed(2)}</p>
+ <p className="text-sm">${(selectedPlan.prices[0].unit_amount / 100).toFixed(2)}</p>
</div>
)}
</div>
@@ -96,17 +95,19 @@ const PaymentSummaryPanel: FC<Props> = ({
{currentComputeSize !== undefined && (
<div className="flex items-center justify-between">
<p className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}>
- Optimized database instance ({currentComputeSize.name})
+ {currentComputeSize.name}
</p>
<p className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}>
- ${currentComputeSize.price.toFixed(2)}
+ ${(currentComputeSize.prices[0].unit_amount / 100).toFixed(2)}
</p>
</div>
)}
{isChangingComputeSize && (
<div className="flex items-center justify-between">
- <p className="text-sm">Optimized database instance ({selectedComputeSize.name})</p>
- <p className="text-sm">${selectedComputeSize.price}</p>
+ <p className="text-sm">{selectedComputeSize.name}</p>
+ <p className="text-sm">
+ ${(selectedComputeSize.prices[0].unit_amount / 100).toFixed(2)}
+ </p>
</div>
)}
</div>
diff --git a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx
index 84b4d3fc053..7c13f3b0cdb 100644
--- a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx
+++ b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx
@@ -2,18 +2,21 @@ import Link from 'next/link'
import { FC } from 'react'
import { Transition } from '@headlessui/react'
+import { StripeProduct } from '..'
import Plans from './Plans/Plans'
import { BillingPlan } from './Plans/Plans.types'
-import { StripeProduct } from '..'
+import { formatTierOptions } from './PlanSelection.utils'
interface Props {
visible: boolean
- billingPlans: BillingPlan[]
+ tiers: any[]
currentPlan?: StripeProduct
onSelectPlan: (plan: BillingPlan) => void
}
-const PlanSelection: FC<Props> = ({ visible, billingPlans, currentPlan, onSelectPlan }) => {
+const PlanSelection: FC<Props> = ({ visible, tiers, currentPlan, onSelectPlan }) => {
+ const formattedTiers = formatTierOptions(tiers)
+
return (
<Transition
show={visible}
@@ -24,7 +27,7 @@ const PlanSelection: FC<Props> = ({ visible, billingPlans, currentPlan, onSelect
<div className="space-y-8">
<h4 className="text-lg">Change your project's subscription</h4>
{/* FE will make a call to fetch all plans first at the page level */}
- <Plans plans={billingPlans} currentPlan={currentPlan} onSelectPlan={onSelectPlan} />
+ <Plans plans={formattedTiers} currentPlan={currentPlan} onSelectPlan={onSelectPlan} />
<div className="flex justify-center items-center">
<Link href="https://supabase.com/pricing">
<a target="_blank" className="text-sm text-scale-1100 hover:text-scale-1200 transition">
diff --git a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts
new file mode 100644
index 00000000000..b16d59a0c92
--- /dev/null
+++ b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts
@@ -0,0 +1,21 @@
+import { STRIPE_PRODUCT_IDS } from 'lib/constants'
+
+// On the UI, we hide PAYG, and add an Enterprise option
+export const formatTierOptions = (tiers: any[]) => {
+ const enterpriseOption = {
+ id: 'Enterprise',
+ name: 'Enterprise',
+ description: 'Custom tailored services to suit your specific business needs',
+ metadata: {
+ features:
+ 'Point in time recovery\\nDesignated Support manager & SLAs\\nSSO / SAML + SOC2\\nCustom contracts & invoicing\\n24×7×365 premium enterprise support',
+ },
+ prices: [],
+ }
+
+ // Fix the order of plans here
+ return tiers
+ .filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.FREE)
+ .concat(tiers.filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.PRO))
+ .concat([enterpriseOption])
+}
diff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.constants.ts b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.constants.ts
deleted file mode 100644
index 114876e83fc..00000000000
--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.constants.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { STRIPE_PRODUCT_IDS, STRIPE_TIER_PRICE_IDS } from 'lib/constants'
-import { BillingPlan } from './Plans.types'
-
-// [Joshen] The idea is that API fetch plans will probably receive StripeProduct[]
-// FE will keep the other meta information like description, pointers, but everything else
-// should be from the API (e.g price) and name
-
-export const BILLING_PLANS: BillingPlan[] = [
- {
- id: STRIPE_PRODUCT_IDS.FREE,
- priceId: STRIPE_TIER_PRICE_IDS.FREE,
- name: 'Free',
- price: 0,
- description: 'Zero commitment, perfect for hobby projects and experiments',
- isPopular: false,
- pointers: [
- '500MB database & 1GB file storage',
- '2000 monthly active auth users',
- 'Community support',
- ],
- },
- {
- id: STRIPE_PRODUCT_IDS.PRO,
- priceId: STRIPE_TIER_PRICE_IDS.PRO,
- name: 'Pro',
- price: 25,
- description: 'Designated support team, account manager and technical specialist',
- isPopular: true,
- pointers: [
- '8GB database & 100GB file storage',
- '10,000 monthly active auth users',
- 'Daily backups',
- 'Compute booster packs',
- '7-day log retention',
- ],
- },
- {
- id: 'Enterprise',
- priceId: '',
- name: 'Enterprise',
- price: null,
- description: 'Custom tailored services to suit your specific business needs',
- isPopular: false,
- pointers: [
- 'Point in time recovery',
- 'Designated Support manager & SLAs',
- 'SSO / SAML + SOC2',
- 'Custom contracts & invoicing',
- '24×7×365 premium enterprise support',
- ],
- },
-]
diff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
index 3d315a8502e..2ba7a615f6b 100644
--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
@@ -7,7 +7,7 @@ import { BillingPlan } from './Plans.types'
import PlanCTAButton from './PlanCTAButton'
interface Props {
- plans: BillingPlan[]
+ plans: any[]
currentPlan?: StripeProduct
onSelectPlan: (plan: BillingPlan) => void
}
@@ -41,6 +41,7 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {
(plan.id === STRIPE_PRODUCT_IDS.PRO && currentPlan?.prod_id === STRIPE_PRODUCT_IDS.PRO) ||
(plan.id === STRIPE_PRODUCT_IDS.PRO && currentPlan?.prod_id === STRIPE_PRODUCT_IDS.PAYG)
+ const pointers = plan.metadata.features.split('\\n').map((x: string) => x.trim())
return (
<div
key={plan.name}
@@ -63,17 +64,17 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {
</div>
<p className="text-scale-1100 text-sm mt-2">{plan.description}</p>
<div className="py-8">
- {plan.price === null ? (
+ {plan.prices.length === 0 ? (
<p className="text-2xl text-center">Contact us</p>
) : (
<div className="flex items-end justify-center">
- <p className="text-3xl">${plan.price}</p>
+ <p className="text-3xl">${plan.prices[0].unit_amount / 100}</p>
<p className="text-sm text-scale-1100 relative -top-[2px]"> /month</p>
</div>
)}
</div>
<ul className="space-y-4">
- {plan.pointers.map((pointer: string, idx: number) => (
+ {pointers.map((pointer: string, idx: number) => (
<li key={`pointer-${idx}`} className="text-sm flex">
<div className="w-[15%]">
<svg
diff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.types.ts b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.types.ts
index 4c07e3556b2..6508f12baac 100644
--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.types.ts
+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.types.ts
@@ -1,8 +1,6 @@
export interface BillingPlan {
id?: string
- priceId?: string
name: string
- price: number | null
description: string
pointers: string[]
isPopular: boolean
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index f4d790ecb0d..dd0a91482f6 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -6,7 +6,7 @@ import { Badge, Button, IconArrowLeft, IconHelpCircle, Toggle, Modal } from '@su
import { useStore } from 'hooks'
import { getURL, timeout } from 'lib/helpers'
import { post, patch } from 'lib/common/fetch'
-import { API_URL, STRIPE_TIER_PRICE_IDS } from 'lib/constants'
+import { API_URL } from 'lib/constants'
import Divider from 'components/ui/Divider'
import {
PaymentSummaryPanel,
@@ -15,12 +15,13 @@ import {
AddNewPaymentMethodModal,
} from '.'
import { BillingPlan } from './PlanSelection/Plans/Plans.types'
-import { COMPUTE_SIZES } from './AddOns/AddOns.constant'
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
import { SubscriptionPreview } from './Billing.types'
interface Props {
visible: boolean
+ products: { tiers: any[]; addons: any[] }
+
currentSubscription: StripeSubscription
selectedPlan?: BillingPlan
paymentMethods?: any[]
@@ -30,6 +31,7 @@ interface Props {
const ProUpgrade: FC<Props> = ({
visible,
+ products,
currentSubscription,
selectedPlan,
paymentMethods,
@@ -39,11 +41,12 @@ const ProUpgrade: FC<Props> = ({
const { ui } = useStore()
const router = useRouter()
+ const { tiers, addons } = products
const projectRef = ui.selectedProject?.ref
const currentComputeSize =
- COMPUTE_SIZES.find((options) => options.id === currentSubscription?.addons[0]?.prod_id) ||
- COMPUTE_SIZES[0]
+ addons.find((option: any) => option.id === currentSubscription?.addons[0]?.prod_id) ||
+ addons.find((option: any) => option.name.includes('[Small]'))
const isManagingProSubscription =
currentSubscription.tier.prod_id === STRIPE_PRODUCT_IDS.PRO ||
@@ -102,37 +105,57 @@ const ProUpgrade: FC<Props> = ({
}
const getSubscriptionPreview = async () => {
- const tier = !isSpendCapEnabled ? STRIPE_TIER_PRICE_IDS.PAYG : selectedPlan?.priceId
+ const selectedTier = !isSpendCapEnabled
+ ? tiers.find((tier: any) => tier.id === STRIPE_PRODUCT_IDS.PAYG)
+ : tiers.find((tier: any) => tier.id === selectedPlan?.id)
+
// [TODO] Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
- const addons = selectedComputeSize.name === 'Small' ? [] : [selectedComputeSize.id]
+ // [UPDATE] it now has, just verify if attaching a Small will mess things up
+ const addons = selectedComputeSize.name.includes('[Small]')
+ ? []
+ : [selectedComputeSize.prices[0].id]
const proration_date = Math.floor(Date.now() / 1000)
+ if (!selectedTier) return
+
setIsRefreshingPreview(true)
const preview = await post(`${API_URL}/projects/${projectRef}/subscription/preview`, {
- tier,
+ tier: selectedTier.prices[0].id,
addons,
proration_date,
})
+ if (preview.error) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to fetch subscription preview: ${preview.error.message}`,
+ })
+ }
setSubscriptionPreview(preview)
setIsRefreshingPreview(false)
console.log('Preview retrieved', preview)
}
+ // Exact same thing as getSubscriptionpreview, can we make them into one
const onConfirmPayment = async () => {
- const tier = !isSpendCapEnabled ? STRIPE_TIER_PRICE_IDS.PAYG : selectedPlan?.priceId
+ const selectedTier = !isSpendCapEnabled
+ ? tiers.find((tier: any) => tier.id === STRIPE_PRODUCT_IDS.PAYG)
+ : tiers.find((tier: any) => tier.id === selectedPlan?.id)
+
// [TODO] Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
- const addons = selectedComputeSize.name === 'Small' ? [] : [selectedComputeSize.id]
+ // [UPDATE] it now has, just verify if attaching a Small will mess things up
+ const addons = selectedComputeSize.name.includes('[Small]')
+ ? []
+ : [selectedComputeSize.prices[0].id]
const proration_date = Math.floor(Date.now() / 1000)
setIsSubmitting(true)
await timeout(1000)
const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, {
- tier: 'asd',
+ tier: selectedTier.prices[0].id,
addons,
proration_date,
})
if (res?.error) {
- // [TODO] probably better error handling here to guide the users
ui.setNotification({
category: 'error',
message: `Failed to update subscription: ${res?.error?.message}`,
@@ -212,6 +235,7 @@ const ProUpgrade: FC<Props> = ({
<Badge color="green">Optional</Badge>
</div>
<ComputeSizeSelection
+ computeSizes={addons || []}
selectedComputeSize={selectedComputeSize}
onSelectOption={onSelectComputeSizeOption}
/>
diff --git a/studio/lib/constants/infrastructure.ts b/studio/lib/constants/infrastructure.ts
index f383ce83bd2..0b9c5a2e428 100644
--- a/studio/lib/constants/infrastructure.ts
+++ b/studio/lib/constants/infrastructure.ts
@@ -99,34 +99,12 @@ export const PROJECT_STATUS = {
RESTORING: 'RESTORING',
}
-// Probably should deprecate to just use price ids?
export const STRIPE_PRODUCT_IDS = {
FREE: process?.env?.NEXT_PUBLIC_STRIPE_FREE_TIER_ID,
PRO: process?.env?.NEXT_PUBLIC_STRIPE_PRO_TIER_ID,
PAYG: process?.env?.NEXT_PUBLIC_STRIPE_PAYG_TIER_ID,
}
-export const STRIPE_TIER_PRICE_IDS = {
- FREE: process?.env.NEXT_PUBLIC_STRIPE_FREE_PRICE_ID ?? 'price_1KCawmJDPojXS6LNahIn31Mr',
- PRO: process?.env.NEXT_PUBLIC_STRIPE_PRO_PRICE_ID ?? 'price_1IdYPAJDPojXS6LNRVCC1LAV',
- PAYG: process?.env.NEXT_PUBLIC_STRIPE_PAYG_PRICE_ID ?? 'price_1KCFZCJDPojXS6LNjTEjcXgU',
-}
-
-export const STRIPE_COMPUTE_SIZE_ADD_ON_PRICE_IDS = {
- SMALL: process?.env.NEXT_PUBLIC_STRIPE_COMPUTE_SIZE_SMALL_PRICE_ID ?? 'small',
- MEDIUM:
- process?.env.NEXT_PUBLIC_STRIPE_COMPUTE_SIZE_MEDIUM_PRICE_ID ??
- 'price_1KCFarJDPojXS6LNlS2pAp36',
- LARGE:
- process?.env.NEXT_PUBLIC_STRIPE_COMPUTE_SIZE_LARGE_PRICE_ID ?? 'price_1KCFaNJDPojXS6LNKg8Gy6pS',
- XLARGE:
- process?.env.NEXT_PUBLIC_STRIPE_COMPUTE_SIZE_XLARGE_PRICE_ID ??
- 'price_1Jaem9JDPojXS6LN62rrj5al',
- XXLARGE:
- process?.env.NEXT_PUBLIC_STRIPE_COMPUTE_SIZE_XXLARGE_PRICE_ID ??
- 'price_1KCFbVJDPojXS6LNmlyzusY8',
-}
-
export const DEFAULT_MINIMUM_PASSWORD_STRENGTH = 4
export const PASSWORD_STRENGTH = {
diff --git a/studio/pages/project/[ref]/settings/billing/update/index.tsx b/studio/pages/project/[ref]/settings/billing/update/index.tsx
index d6c0d5e59a5..97a167351a7 100644
--- a/studio/pages/project/[ref]/settings/billing/update/index.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update/index.tsx
@@ -5,14 +5,14 @@ import { observer } from 'mobx-react-lite'
import { Button, Modal } from '@supabase/ui'
import { withAuth, useStore, useSubscriptionStats } from 'hooks'
-import { post } from 'lib/common/fetch'
+import { get, post } from 'lib/common/fetch'
import { API_URL, DEFAULT_FREE_PROJECTS_LIMIT, STRIPE_PRODUCT_IDS } from 'lib/constants'
import { BillingLayout } from 'components/layouts'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import { PlanSelection, ProUpgrade, StripeSubscription } from 'components/interfaces/Billing'
import { BillingPlan } from 'components/interfaces/Billing/PlanSelection/Plans/Plans.types'
-import { BILLING_PLANS } from 'components/interfaces/Billing/PlanSelection/Plans/Plans.constants'
+import Connecting from 'components/ui/Loading/Loading'
/**
* [Joshen] Right now everything is scaffolded without any API calls
@@ -20,6 +20,8 @@ import { BILLING_PLANS } from 'components/interfaces/Billing/PlanSelection/Plans
* once I'm working with proper data
*/
+// [CURRENTLY: Hooking up products from API, and removing all the constants crap]
+
const BillingUpdate: NextPage = () => {
const { ui } = useStore()
const router = useRouter()
@@ -30,22 +32,42 @@ const BillingUpdate: NextPage = () => {
const freeProjectsLimit = ui?.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
const freeProjectsOwned = subscriptionStats.total_free_projects ?? 0
+ const [isLoadingProducts, setIsLoadingProducts] = useState(false)
const [isLoadingPaymentMethods, setIsLoadingPaymentMethods] = useState(false)
const [showConfirmDowngrade, setShowConfirmDowngrade] = useState(false)
const [showDowngradeError, setShowDowngradeError] = useState(false)
+ const [products, setProducts] = useState<{ tiers: any[]; addons: any[] }>()
const [subscription, setSubscription] = useState<StripeSubscription>()
const [paymentMethods, setPaymentMethods] = useState<any>()
const [selectedPlan, setSelectedPlan] = useState<BillingPlan>()
useEffect(() => {
- if (projectRef) getSubscription()
+ if (projectRef) {
+ getStripeProducts()
+ getSubscription()
+ }
}, [projectRef])
useEffect(() => {
if (stripeCustomerId) getStripeAccount()
}, [stripeCustomerId])
+ const getStripeProducts = async () => {
+ try {
+ setIsLoadingProducts(true)
+ const products = await get(`${API_URL}/stripe/products`)
+ setProducts(products)
+ setIsLoadingProducts(false)
+ } catch (error: any) {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Failed to get products: ${error.message}`,
+ })
+ }
+ }
+
const getStripeAccount = async () => {
try {
setIsLoadingPaymentMethods(true)
@@ -106,23 +128,32 @@ const BillingUpdate: NextPage = () => {
}
}
+ if (isLoadingProducts) {
+ return (
+ <div className="w-full h-full flex items-center justify-center">
+ <Connecting />
+ </div>
+ )
+ }
+
return (
<BillingLayout>
<div className="mx-auto max-w-5xl my-10">
<PlanSelection
visible={!selectedPlan || (selectedPlan && showConfirmDowngrade)}
- billingPlans={BILLING_PLANS}
+ tiers={products?.tiers ?? []}
currentPlan={subscription?.tier}
onSelectPlan={onSelectPlan}
/>
</div>
- {subscription !== undefined && (
+ {subscription !== undefined && products !== undefined && (
<ProUpgrade
visible={
selectedPlan?.id === STRIPE_PRODUCT_IDS.PRO ||
selectedPlan?.id === STRIPE_PRODUCT_IDS.PAYG
}
+ products={products}
currentSubscription={subscription}
selectedPlan={selectedPlan}
isLoadingPaymentMethods={isLoadingPaymentMethods}