Skip to content

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

feat: free plan for org level billing

Kevin Grüneberg92e67688f335
diff --git a/packages/ui/src/lib/Layout/FormLayout/FormLayout.tsx b/packages/ui/src/lib/Layout/FormLayout/FormLayout.tsx
index 9715d795b1d..7a8fe25e9ae 100644
--- a/packages/ui/src/lib/Layout/FormLayout/FormLayout.tsx
+++ b/packages/ui/src/lib/Layout/FormLayout/FormLayout.tsx
@@ -125,12 +125,12 @@ export function FormLayout({
)
const renderDescription = descriptionText && (
- <p
+ <div
className={[__styles.description.base, __styles.description.size[size]].join(' ')}
id={id + '-description'}
>
{descriptionText}
- </p>
+ </div>
)
return (
diff --git a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
index 12bcbc13e2a..021c17371be 100644
--- a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
+++ b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
@@ -49,7 +49,7 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
const [newOrgLoading, setNewOrgLoading] = useState(false)
const [paymentMethod, setPaymentMethod] = useState<PaymentMethod>()
- const [dbPricingTierKey, setDbPricingTierKey] = useState('PRO')
+ const [dbPricingTierKey, setDbPricingTierKey] = useState('FREE')
function validateOrgName(name: any) {
const value = name ? name.trim() : ''
@@ -72,7 +72,7 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
setDbPricingTierKey(value)
}
- async function createOrg(paymentMethodId: string) {
+ async function createOrg(paymentMethodId?: string) {
const response = await post(
`${API_URL}/organizations`,
{
@@ -118,7 +118,9 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
}
setNewOrgLoading(true)
- if (!paymentMethod) {
+ if (dbPricingTierKey === 'FREE') {
+ await createOrg()
+ } else if (!paymentMethod) {
const { error, setupIntent } = await stripe.confirmSetup({
elements,
redirect: 'if_required',
@@ -290,41 +292,43 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
</Listbox>
</Panel.Content>
- <Panel.Content>
- {paymentMethod?.card !== undefined ? (
- <div key={paymentMethod.id} className="flex items-center justify-between">
- <div className="flex items-center space-x-8">
- <img
- alt="Card"
- src={`${BASE_PATH}/img/payment-methods/${paymentMethod.card.brand
- .replace(' ', '-')
- .toLowerCase()}.png`}
- width="32"
- />
- <Input
- readOnly
- className="w-64"
- size="small"
- value={`•••• •••• •••• ${paymentMethod.card.last4}`}
- />
- <p className="text-sm tabular-nums">
- Expires: {paymentMethod.card.exp_month}/{paymentMethod.card.exp_year}
- </p>
+ {dbPricingTierKey !== 'FREE' && (
+ <Panel.Content>
+ {paymentMethod?.card !== undefined ? (
+ <div key={paymentMethod.id} className="flex items-center justify-between">
+ <div className="flex items-center space-x-8">
+ <img
+ alt="Card"
+ src={`${BASE_PATH}/img/payment-methods/${paymentMethod.card.brand
+ .replace(' ', '-')
+ .toLowerCase()}.png`}
+ width="32"
+ />
+ <Input
+ readOnly
+ className="w-64"
+ size="small"
+ value={`•••• •••• •••• ${paymentMethod.card.last4}`}
+ />
+ <p className="text-sm tabular-nums">
+ Expires: {paymentMethod.card.exp_month}/{paymentMethod.card.exp_year}
+ </p>
+ </div>
+ <div>
+ <Button
+ type="outline"
+ icon={<IconEdit2 />}
+ onClick={() => resetPaymentMethod()}
+ disabled={newOrgLoading}
+ className="hover:border-gray-500"
+ />
+ </div>
</div>
- <div>
- <Button
- type="outline"
- icon={<IconEdit2 />}
- onClick={() => resetPaymentMethod()}
- disabled={newOrgLoading}
- className="hover:border-gray-500"
- />
- </div>
- </div>
- ) : (
- <PaymentElement />
- )}
- </Panel.Content>
+ ) : (
+ <PaymentElement />
+ )}
+ </Panel.Content>
+ )}
</Panel>
</form>
</>
diff --git a/studio/components/ui/PasswordStrengthBar.tsx b/studio/components/ui/PasswordStrengthBar.tsx
index 2c472fad53a..4bd35b7b473 100644
--- a/studio/components/ui/PasswordStrengthBar.tsx
+++ b/studio/components/ui/PasswordStrengthBar.tsx
@@ -1,8 +1,4 @@
-import {
- DEFAULT_MINIMUM_PASSWORD_STRENGTH,
- PASSWORD_STRENGTH_COLOR,
- PASSWORD_STRENGTH_PERCENTAGE,
-} from 'lib/constants'
+import { PASSWORD_STRENGTH_COLOR, PASSWORD_STRENGTH_PERCENTAGE } from 'lib/constants'
interface Props {
passwordStrengthScore: number
diff --git a/studio/data/subscriptions/keys.ts b/studio/data/subscriptions/keys.ts
index c8f1fddaead..16b4998d66d 100644
--- a/studio/data/subscriptions/keys.ts
+++ b/studio/data/subscriptions/keys.ts
@@ -3,6 +3,8 @@
export const subscriptionKeys = {
subscriptionV2: (projectRef: string | undefined) =>
['projects', projectRef, 'subscriptionV2'] as const,
+ orgSubscription: (orgSlug: string | undefined) =>
+ ['organizations', orgSlug, 'subscription'] as const,
addons: (projectRef: string | undefined) => ['projects', projectRef, 'addons'] as const,
plans: (projectRef: string | undefined) => ['projects', projectRef, 'plans'] as const,
preview: (projectRef: string | undefined) =>
diff --git a/studio/data/subscriptions/org-subscription-query.ts b/studio/data/subscriptions/org-subscription-query.ts
new file mode 100644
index 00000000000..3429664c4ae
--- /dev/null
+++ b/studio/data/subscriptions/org-subscription-query.ts
@@ -0,0 +1,90 @@
+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+import { get } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import { useCallback } from 'react'
+import { subscriptionKeys } from './keys'
+
+export type OrgSubscriptionVariables = {
+ orgSlug?: string
+}
+
+export type PlanId = 'free' | 'pro' | 'team' | 'enterprise'
+
+export type OrgSubscriptionResponse = {
+ billing_cycle_anchor: number
+ current_period_start: number
+ current_period_end: number
+ next_invoice_at: number
+ usage_billing_enabled: boolean
+ plan: {
+ id: PlanId
+ name: string
+ price: number
+ }
+ addons: {
+ name: string
+ supabase_prod_id: string
+ price: number
+ }[]
+ usage_fees: {
+ metric: string
+ pricingStrategy: 'UNIT' | 'PACKAGE'
+ pricingOptions: {
+ perUnitPrice?: number
+ packagePrice?: number
+ packageSize?: number
+ freeUnits: number
+ }
+ }[]
+ payment_method_id?: string
+ payment_method_type: 'invoice' | 'card' | 'none'
+ payment_method_card_details?: {
+ last_4_digits: string
+ brand: string
+ expiry_month: number
+ expiry_year: number
+ }
+}
+
+export async function getOrgSubscription(
+ { orgSlug }: OrgSubscriptionVariables,
+ signal?: AbortSignal
+) {
+ if (!orgSlug) throw new Error('orgSlug is required')
+
+ const response = await get(`${API_URL}/organizations/${orgSlug}/billing/subscription`, { signal })
+ if (response.error) throw response.error
+
+ return response as OrgSubscriptionResponse
+}
+
+export type OrgSubscriptionData = Awaited<ReturnType<typeof getOrgSubscription>>
+export type OrgSubscriptionError = unknown
+
+export const useOrgSubscriptionQuery = <TData = OrgSubscriptionData>(
+ { orgSlug }: OrgSubscriptionVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<OrgSubscriptionData, OrgSubscriptionError, TData> = {}
+) =>
+ useQuery<OrgSubscriptionData, OrgSubscriptionError, TData>(
+ subscriptionKeys.orgSubscription(orgSlug),
+ ({ signal }) => getOrgSubscription({ orgSlug }, signal),
+ {
+ enabled: enabled && typeof orgSlug !== 'undefined',
+ ...options,
+ }
+ )
+
+export const useOrgSubscriptionPrefetch = ({ orgSlug }: OrgSubscriptionVariables) => {
+ const client = useQueryClient()
+
+ return useCallback(() => {
+ if (orgSlug) {
+ client.prefetchQuery(subscriptionKeys.orgSubscription(orgSlug), ({ signal }) =>
+ getOrgSubscription({ orgSlug }, signal)
+ )
+ }
+ }, [orgSlug])
+}
diff --git a/studio/lib/constants/infrastructure.ts b/studio/lib/constants/infrastructure.ts
index eed060ab177..e283bf68e19 100644
--- a/studio/lib/constants/infrastructure.ts
+++ b/studio/lib/constants/infrastructure.ts
@@ -38,6 +38,7 @@ export const PRICING_TIER_LABELS = {
}
export const PRICING_TIER_LABELS_ORG = {
+ FREE: 'Free - $0/month',
PRO: 'Pro - $25/month',
TEAM: 'Team - $599/month',
}
diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsx
index fe03cf0ddc3..4b61f61c060 100644
--- a/studio/pages/new/[slug].tsx
+++ b/studio/pages/new/[slug].tsx
@@ -37,6 +37,7 @@ import {
} from 'components/interfaces/Organization/NewProject'
import SpendCapModal from 'components/interfaces/Billing/SpendCapModal'
import InformationBox from 'components/ui/InformationBox'
+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
const Wizard: NextPageWithLayout = () => {
const router = useRouter()
@@ -70,6 +71,11 @@ const Wizard: NextPageWithLayout = () => {
const currentOrg = organizations.find((o: any) => o.slug === slug)
const billedViaOrg = Boolean(currentOrg?.subscription_id)
+ const { data: orgSubscription } = useOrgSubscriptionQuery(
+ { orgSlug: slug },
+ { enabled: billedViaOrg }
+ )
+
const [availableRegions, setAvailableRegions] = useState(
getAvailableRegions(PROVIDERS[cloudProvider].id)
)
@@ -83,8 +89,10 @@ const Wizard: NextPageWithLayout = () => {
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
- const canCreateProject =
- isAdmin && (!isSelectFreeTier || (isSelectFreeTier && !hasMembersExceedingFreeTierLimit))
+ const freePlanWithExceedingLimits =
+ (isSelectFreeTier || orgSubscription?.plan?.id === 'free') && hasMembersExceedingFreeTierLimit
+
+ const canCreateProject = isAdmin && !freePlanWithExceedingLimits
const canSubmit =
projectName !== '' &&
@@ -465,55 +473,57 @@ const Wizard: NextPageWithLayout = () => {
</>
)}
- {isAdmin && !billedViaOrg && (
+ {isAdmin && (
<Panel.Content>
- <Listbox
- label="Pricing Plan"
- layout="horizontal"
- value={dbPricingTierKey}
- onChange={onDbPricingPlanChange}
- descriptionText={
- <>
- Select a plan that suits your needs.&nbsp;
- <a
- className="underline"
- target="_blank"
- rel="noreferrer"
- href="https://supabase.com/pricing"
- >
- More details
- </a>
- {!isSelectFreeTier && !isEmptyPaymentMethod && (
- <Alert
- title="Your payment method will be charged"
- variant="warning"
- withIcon
- className="mt-3"
+ {!billedViaOrg && (
+ <Listbox
+ label="Pricing Plan"
+ layout="horizontal"
+ value={dbPricingTierKey}
+ onChange={onDbPricingPlanChange}
+ descriptionText={
+ <>
+ Select a plan that suits your needs.&nbsp;
+ <a
+ className="underline"
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/pricing"
>
- <p>
- By creating a new Pro Project, there will be an immediate charge of $25
- once the project has been created.
- </p>
- </Alert>
- )}
- </>
- }
- >
- {Object.entries(PRICING_TIER_LABELS).map(([k, v]) => {
- const label = `${v}${k === 'PRO' ? ' - $25/month' : ' - $0/month'}`
- return (
- <Listbox.Option key={k} label={label} value={k}>
- {label}
- </Listbox.Option>
- )
- })}
- </Listbox>
+ More details
+ </a>
+ {!isSelectFreeTier && !isEmptyPaymentMethod && (
+ <Alert
+ title="Your payment method will be charged"
+ variant="warning"
+ withIcon
+ className="mt-3"
+ >
+ <p>
+ By creating a new Pro Project, there will be an immediate charge of
+ $25 once the project has been created.
+ </p>
+ </Alert>
+ )}
+ </>
+ }
+ >
+ {Object.entries(PRICING_TIER_LABELS).map(([k, v]) => {
+ const label = `${v}${k === 'PRO' ? ' - $25/month' : ' - $0/month'}`
+ return (
+ <Listbox.Option key={k} label={label} value={k}>
+ {label}
+ </Listbox.Option>
+ )
+ })}
+ </Listbox>
+ )}
- {isSelectFreeTier && hasMembersExceedingFreeTierLimit && (
+ {freePlanWithExceedingLimits && (
<FreeProjectLimitWarning membersExceededLimit={membersExceededLimit || []} />
)}
- {!isSelectFreeTier && isEmptyPaymentMethod && (
+ {!billedViaOrg && !isSelectFreeTier && isEmptyPaymentMethod && (
<EmptyPaymentMethodWarning onPaymentMethodAdded={onPaymentMethodAdded} />
)}
</Panel.Content>