The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Ensure that the correct price ids are getting used to form the subscription update payload
Joshen Lim0a020805a1b4
diff --git a/studio/components/interfaces/Billing/Billing.utils.ts b/studio/components/interfaces/Billing/Billing.utils.tsindex 644e6e1d7a9..78dad73da32 100644--- a/studio/components/interfaces/Billing/Billing.utils.ts+++ b/studio/components/interfaces/Billing/Billing.utils.ts@@ -7,6 +7,7 @@ import {} from './AddOns/AddOns.utils'import { StripeSubscription } from './Subscription/Subscription.types'+// Retrieve the price based on the default price id of the productexport const getProductPrice = (product: any) => {const defaultPriceId = product.metadata?.default_price_idconst price =@@ -16,6 +17,18 @@ export const getProductPrice = (product: any) => {return price}+// Products can have multiple prices, this is to get the correct one based on the subscription+const getProductPriceId = (+ currentSubscription: StripeSubscription,+ product: any+): string | undefined => {+ const existingAddon = currentSubscription.addons.find((addon) => addon.prod_id === product.id)+ const existingAddonPriceId = product.prices.find(+ (price: any) => price.unit_amount === existingAddon?.unit_amount+ )+ return existingAddonPriceId?.id || getProductPrice(product)?.id+}+export const validateSubscriptionUpdatePayload = (selectedAddons: {computeSize: DatabaseAddonpitrDuration: DatabaseAddon@@ -31,31 +44,38 @@ export const validateSubscriptionUpdatePayload = (selectedAddons: {}export const formSubscriptionUpdatePayload = (+ currentSubscription: StripeSubscription,selectedTier: any,selectedAddons: {computeSize: DatabaseAddonpitrDuration: DatabaseAddoncustomDomains: DatabaseAddon},+ nonChangeableAddons: DatabaseAddon[],selectedPaymentMethod: string,region: string) => {const { computeSize, pitrDuration, customDomains } = selectedAddons- const defaultPrice = selectedTier ? getProductPrice(selectedTier) : undefined++ const computeSizePriceId = getProductPriceId(currentSubscription, computeSize)+ const pitrAddonPriceId = getProductPriceId(currentSubscription, pitrDuration)+ const customDomainPriceId = getProductPriceId(currentSubscription, customDomains)+ const tierPriceId = selectedTier ? getProductPrice(selectedTier) : undefined++ const nonChangeablePriceIds = nonChangeableAddons.map((addon) =>+ getProductPriceId(currentSubscription, addon)+ )+const addons =region === 'af-south-1'? []- : [- computeSize.prices.find((price) => price.id === computeSize.metadata.default_price_id)- ?.id,- pitrDuration.prices.find((price) => price.id === pitrDuration.metadata.default_price_id)- ?.id,- customDomains.prices.find((price) => price.id === customDomains.metadata.default_price_id)- ?.id,- ].filter((x) => x !== undefined)+ : [computeSizePriceId, pitrAddonPriceId, customDomainPriceId]+ .concat(nonChangeablePriceIds)+ .filter((x) => x !== undefined)const proration_date = Math.floor(Date.now() / 1000)+return {- ...(defaultPrice && { tier: defaultPrice.id }),+ ...(tierPriceId && { tier: tierPriceId.id }),addons,proration_date,payment_method: selectedPaymentMethod,diff --git a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx b/studio/components/interfaces/Billing/EnterpriseUpdate.tsxindex 299b9f0cdba..9b143c9732b 100644--- a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx+++ b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx@@ -67,6 +67,11 @@ const EnterpriseUpdate: FC<Props> = ({const [selectedCustomDomainOption, setSelectedCustomDomainOption] = useState<DatabaseAddon>(currentAddons.customDomains)+ // [Joshen TODO] Future - We may need to also include any add ons outside of+ // compute size, pitr, custom domain and support plan, although we dont have any now+ const nonChangeableAddons = [currentAddons.supportPlan].filter(+ (x) => x !== undefined+ ) as DatabaseAddon[]// [Joshen] Scaffolded hereconst selectedAddons = {@@ -87,7 +92,7 @@ const EnterpriseUpdate: FC<Props> = ({useEffect(() => {getSubscriptionPreview()- }, [selectedComputeSize, selectedPITRDuration])+ }, [selectedComputeSize, selectedPITRDuration, selectedCustomDomainOption])useEffect(() => {if (!isLoadingPaymentMethods && paymentMethods && paymentMethods.length > 0) {@@ -100,8 +105,10 @@ const EnterpriseUpdate: FC<Props> = ({// Only allow add-ons changingconst payload = {...formSubscriptionUpdatePayload(+ currentSubscription,null,selectedAddons,+ nonChangeableAddons,selectedPaymentMethodId,projectRegion),@@ -124,8 +131,10 @@ const EnterpriseUpdate: FC<Props> = ({const onConfirmPayment = async () => {const payload = {...formSubscriptionUpdatePayload(+ currentSubscription,null,selectedAddons,+ nonChangeableAddons,selectedPaymentMethodId,projectRegion),diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsxindex ccc8cda5a2b..09ae8c2285c 100644--- a/studio/components/interfaces/Billing/ProUpgrade.tsx+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx@@ -88,6 +88,12 @@ const ProUpgrade: FC<Props> = ({currentAddons.customDomains)+ // [Joshen TODO] Future - We may need to also include any add ons outside of+ // compute size, pitr, custom domain and support plan, although we dont have any now+ const nonChangeableAddons = [currentAddons.supportPlan].filter(+ (x) => x !== undefined+ ) as DatabaseAddon[]+// [Joshen] Scaffolded hereconst selectedAddons = {computeSize: selectedComputeSize,@@ -122,8 +128,10 @@ const ProUpgrade: FC<Props> = ({if (!selectedTier) returnconst payload = formSubscriptionUpdatePayload(+ currentSubscription,selectedTier,selectedAddons,+ nonChangeableAddons,selectedPaymentMethodId,projectRegion)@@ -142,8 +150,10 @@ const ProUpgrade: FC<Props> = ({const onConfirmPayment = async () => {const payload = formSubscriptionUpdatePayload(+ currentSubscription,selectedTier,selectedAddons,+ nonChangeableAddons,selectedPaymentMethodId,projectRegion)diff --git a/studio/components/to-be-cleaned/forms/SchemaFormPanel.js b/studio/components/to-be-cleaned/forms/SchemaFormPanel.jsindex 6f86522c66a..c92731055e1 100644--- a/studio/components/to-be-cleaned/forms/SchemaFormPanel.js+++ b/studio/components/to-be-cleaned/forms/SchemaFormPanel.js@@ -32,7 +32,7 @@ export default function SchemaFormPanel({setSubmitButtonLoading(true)}).catch((error) => {- console.log('Error on submitting', error)+ console.error('Error on submitting', error)})}diff --git a/studio/components/ui/DatePicker/TimeSplitInput.tsx b/studio/components/ui/DatePicker/TimeSplitInput.tsxindex 7c437936e9a..ea93dbbe9c4 100644--- a/studio/components/ui/DatePicker/TimeSplitInput.tsx+++ b/studio/components/ui/DatePicker/TimeSplitInput.tsx@@ -38,13 +38,10 @@ const TimeSplitInput = ({// Only run time conflicts if// startDate and endDate are the same date- // console.log(startDate)- // console.log(endDate)if (format(new Date(startDate), 'dd/mm/yyyy') == format(new Date(endDate), 'dd/mm/yyyy')) {// checks if start time is ahead of end timeif (type === 'start') {- // console.log('HH in start switch')if (_time.HH && Number(_time.HH) > Number(endTime.HH)) {endTimePayload.HH = _time.HHendTimeChanges = true@@ -79,8 +76,6 @@ const TimeSplitInput = ({}if (type === 'end') {- // console.log('HH in start switch')-if (_time.HH && Number(_time.HH) < Number(startTime.HH)) {startTimePayload.HH = _time.HHstartTimeChanges = true@@ -128,8 +123,6 @@ const TimeSplitInput = ({}function handleOnChange(value: string, valueType: TimeType) {- // console.log('handleOnChange')-const payload = {HH: time.HH,mm: time.mm,@@ -151,14 +144,8 @@ const TimeSplitInput = ({break}- // console.log('got here')-payload[valueType] = valuesetTime({ ...payload })-- // if (endTimeChanges) {- // setEndTime(endTimePayload)- // }}const handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {diff --git a/studio/lib/gotrue.ts b/studio/lib/gotrue.tsindex 4bd03f121ab..e4c6383a150 100644--- a/studio/lib/gotrue.ts+++ b/studio/lib/gotrue.ts@@ -18,7 +18,7 @@ export const getAuthUser = async (token: String): Promise<any> => {return { user, error: null }} catch (err) {- console.log(err)+ console.error(err)return { user: null, error: err }}}