The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
refactor(billing): allow GB VAT tax IDs for Isle of Man customers (#43640)
Kanishk Dudeja5d942e2a46b4
diff --git a/apps/studio/components/interfaces/App/UpdateBillingAddressModal.tsx b/apps/studio/components/interfaces/App/UpdateBillingAddressModal.tsxindex ac0177f63ca..d82405c6a77 100644--- a/apps/studio/components/interfaces/App/UpdateBillingAddressModal.tsx+++ b/apps/studio/components/interfaces/App/UpdateBillingAddressModal.tsx@@ -5,7 +5,7 @@ import {BillingCustomerDataForm,type BillingCustomerDataFormValues,} from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerDataForm'-import { TAX_IDS } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants'+import { resolveStoredTaxId } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils'import { useBillingCustomerDataForm } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm'import { useOrganizationCustomerProfileQuery } from 'data/organizations/organization-customer-profile-query'import { useOrganizationCustomerProfileUpdateMutation } from 'data/organizations/organization-customer-profile-update-mutation'@@ -82,9 +82,8 @@ export function UpdateBillingAddressModal() {tax_id_type: taxId?.type,tax_id_value: taxId?.value,tax_id_name: taxId- ? TAX_IDS.find(- (option) => option.type === taxId.type && option.countryIso2 === taxId.country- )?.name || ''+ ? (resolveStoredTaxId(taxId.type, taxId.country, customerProfile?.address?.country)?.name ??+ ''): '',}),[customerProfile, taxId]diff --git a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsxindex 01dc8921287..c8905ea93bf 100644--- a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx+++ b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx@@ -13,6 +13,10 @@ import {} from '@stripe/stripe-js'import { Form } from '@ui/components/shadcn/ui/form'import { TAX_IDS } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants'+import {+ resolveStoredTaxId,+ getEffectiveTaxCountry,+} from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils'import type { CustomerAddress, CustomerTaxId } from 'data/organizations/types'import { getURL } from 'lib/helpers'import { Check, ChevronsUpDown } from 'lucide-react'@@ -96,10 +100,8 @@ export const NewPaymentMethodElement = forwardRef(resolver: zodResolver(BillingCustomerDataSchema),defaultValues: {tax_id_name: currentTaxId- ? TAX_IDS.find(- (option) =>- option.type === currentTaxId.type && option.countryIso2 === currentTaxId.country- )?.name || ''+ ? (resolveStoredTaxId(currentTaxId.type, currentTaxId.country, currentAddress?.country)+ ?.name ?? ''): '',tax_id_type: currentTaxId ? currentTaxId.type : '',tax_id_value: currentTaxId ? currentTaxId.value : '',@@ -172,7 +174,7 @@ export const NewPaymentMethodElement = forwardRef(function getConfiguredTaxId(): CustomerTaxId | null {return purchasingAsBusiness && selectedTaxId? {- country: selectedTaxId.countryIso2,+ country: getEffectiveTaxCountry(selectedTaxId),type: selectedTaxId.type,value: form.getValues('tax_id_value'),}diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerData.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerData.tsxindex cef3bddd6d3..3a138e9da1c 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerData.tsx+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerData.tsx@@ -25,7 +25,7 @@ import {BillingCustomerDataForm,type BillingCustomerDataFormValues,} from './BillingCustomerDataForm'-import { TAX_IDS } from './TaxID.constants'+import { resolveStoredTaxId } from './TaxID.utils'import { useBillingCustomerDataForm } from './useBillingCustomerDataForm'export const BillingCustomerData = () => {@@ -66,9 +66,8 @@ export const BillingCustomerData = () => {tax_id_type: taxId?.type,tax_id_value: taxId?.value,tax_id_name: taxId- ? TAX_IDS.find(- (option) => option.type === taxId.type && option.countryIso2 === taxId.country- )?.name || ''+ ? (resolveStoredTaxId(taxId.type, taxId.country, customerProfile?.address?.country)?.name ??+ ''): '',}),[customerProfile, taxId]diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants.ts b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants.tsindex de562f4824a..d468bea117c 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants.ts+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants.ts@@ -5,6 +5,8 @@ export interface TaxId {countryIso2: stringplaceholder: stringvatPrefix?: string+ /** Override the country code sent to Orb when it differs from countryIso2 */+ taxCountryIso2?: string}// Commented out countries are not currently supported by Orb API@@ -430,6 +432,16 @@ export const TAX_IDS: TaxId[] = [vatPrefix: 'GB',countryIso2: 'GB',},+ {+ // Isle of Man uses GB VAT numbers, taxCountryIso2 must be GB for Orb validation+ name: 'IM VAT',+ type: 'gb_vat',+ country: 'Isle of Man',+ placeholder: 'GB123456789',+ vatPrefix: 'GB',+ countryIso2: 'IM',+ taxCountryIso2: 'GB',+ },{name: 'GE VAT',type: 'ge_vat',diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils.ts b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils.tsindex b96a035b24a..ab98914e21a 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils.ts+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils.ts@@ -1,4 +1,35 @@-import { TAX_IDS } from './TaxID.constants'+import { TAX_IDS, TaxId } from './TaxID.constants'++/**+ * Returns the country code to send to Orb for tax validation.+ *+ * Most tax IDs use their display country (countryIso2), but some territories+ * share another country's tax system — e.g., Isle of Man uses GB VAT.+ * In these cases, taxCountryIso2 overrides the country sent to Orb.+ */+export const getEffectiveTaxCountry = (taxId: TaxId): string =>+ taxId.taxCountryIso2 ?? taxId.countryIso2++/**+ * Resolves a stored tax ID (from Orb) back to its TAX_IDS UI entry.+ *+ * Uses billingCountry (from the customer's address) to disambiguate when+ * multiple entries share the same Orb type+country — e.g., both "UK VAT"+ * and "IM VAT" map to {type: 'gb_vat', country: 'GB'} in Orb, but differ+ * by billing address country (GB vs IM).+ *+ * When billingCountry is unavailable, falls back to the stored country.+ */+export const resolveStoredTaxId = (+ type: string,+ taxCountry: string,+ billingCountry?: string+): TaxId | undefined => {+ const candidates = TAX_IDS.filter((option) => option.type === type)+ const preferredCountry = billingCountry ?? taxCountry++ return candidates.find((o) => o.countryIso2 === preferredCountry)+}export const sanitizeTaxIdValue = (taxId: { name: string; value: string }) => {const selectedTaxId = TAX_IDS.find((option) => option.name === taxId.name)diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.tsindex 176a3e4f19d..5624f6d2a6f 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form'import { BillingCustomerDataFormValues, BillingCustomerDataSchema } from './BillingCustomerDataForm'import { TAX_IDS } from './TaxID.constants'-import { sanitizeTaxIdValue } from './TaxID.utils'+import { getEffectiveTaxCountry, sanitizeTaxIdValue } from './TaxID.utils'import { components } from 'api-types'import type { CustomerAddress } from 'data/organizations/types'@@ -88,7 +88,7 @@ export function useBillingCustomerDataForm({value: values.tax_id_value,name: form.getValues().tax_id_name,}),- country: selectedTaxId?.countryIso2,+ country: getEffectiveTaxCountry(selectedTaxId),}: null,})diff --git a/apps/studio/tests/components/Billing/TaxID.utils.test.ts b/apps/studio/tests/components/Billing/TaxID.utils.test.tsindex 40d2960b0b8..bfaaca2fcab 100644--- a/apps/studio/tests/components/Billing/TaxID.utils.test.ts+++ b/apps/studio/tests/components/Billing/TaxID.utils.test.ts@@ -1,4 +1,9 @@-import { sanitizeTaxIdValue } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils'+import { TAX_IDS } from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.constants'+import {+ getEffectiveTaxCountry,+ resolveStoredTaxId,+ sanitizeTaxIdValue,+} from 'components/interfaces/Organization/BillingSettings/BillingCustomerData/TaxID.utils'import { describe, test, expect } from 'vitest'/**@@ -48,3 +53,37 @@ describe('TaxID utils: sanitizeTaxID', () => {expect(sanitizedID).toBe('12-3456789')})})++describe('TaxID utils: getEffectiveTaxCountry', () => {+ test('returns countryIso2 when no override is set', () => {+ const ukVat = TAX_IDS.find((t) => t.name === 'UK VAT')!+ expect(getEffectiveTaxCountry(ukVat)).toBe('GB')+ })++ test('returns taxCountryIso2 when override is set', () => {+ const imVat = TAX_IDS.find((t) => t.name === 'IM VAT')!+ expect(getEffectiveTaxCountry(imVat)).toBe('GB')+ })+})++describe('TaxID utils: resolveStoredTaxId', () => {+ test('resolves GB customer to UK VAT with billingCountry', () => {+ const ukVat = TAX_IDS.find((t) => t.name === 'UK VAT')!+ expect(resolveStoredTaxId('gb_vat', 'GB', 'GB')).toBe(ukVat)+ })++ test('resolves IM customer to IM VAT with billingCountry', () => {+ const imVat = TAX_IDS.find((t) => t.name === 'IM VAT')!+ expect(resolveStoredTaxId('gb_vat', 'GB', 'IM')).toBe(imVat)+ })++ test('resolves GB customer to UK VAT without billingCountry', () => {+ // Without billingCountry, falls back to countryIso2 match — UK VAT has countryIso2 'GB'+ const ukVat = TAX_IDS.find((t) => t.name === 'UK VAT')!+ expect(resolveStoredTaxId('gb_vat', 'GB')).toBe(ukVat)+ })++ test('returns undefined for unknown type', () => {+ expect(resolveStoredTaxId('unknown_type', 'XX')).toBeUndefined()+ })+})