mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
### Summary This PR adds support for Isle of Man customers to use GB VAT tax IDs. Isle of Man uses the UK VAT system, so Orb requires country: 'GB' for validation - but the billing address country is IM. - Adds an IM VAT entry to `TAX_IDS` with a new `taxCountryIso2` override field, so the UI shows "IM VAT" while sending country: 'GB' to Orb - Introduces `getEffectiveTaxCountry()` to resolve the correct country code for Orb - Introduces `resolveStoredTaxId()` to map stored Orb data back to the correct UI entry, using billing address country to disambiguate IM vs GB - Updates all three billing forms to use these utilities: Billing Settings page, Add Payment Method modal and Update Billing Address modal ### Testing #### Automated tests I've added unit tests in this PR #### Manual tests You can use the following country/city/postal code combinations to test: - Isle of Man, Douglas, IM1 2LE - United Kingdom, Crumlin, BT29 4AA **Billing Settings page** - Select Isle of Man as billing country → tax ID dropdown shows "Isle of Man - IM VAT" - Select United Kingdom as billing country → tax ID dropdown shows "United Kingdom - UK VAT" / "United Kingdom - GB VAT" (not "IM VAT") - Select IM VAT, enter a valid GB VAT number, save → check network tab, Orb receives country: 'GB' - Reload page for an IM customer with existing tax ID → "IM VAT" is pre-selected (not "UK VAT") - Reload page for a GB customer with existing tax ID → "UK VAT" is pre-selected (no regression) - Change country from IM to GB → available tax IDs update, IM VAT no longer shown **Add Payment Method modal** - Open modal for an IM customer with existing tax ID → "IM VAT" is pre-selected - Check "I'm purchasing as a business", select Isle of Man in Stripe address → tax ID dropdown shows "IM VAT" - Check "I'm purchasing as a business", select United Kingdom in Stripe address → tax ID dropdown shows "UK VAT" / "GB VAT" - Submit with IM VAT → check network tab, tax ID is saved with country: 'GB' - Open modal for a GB customer → no regression, "UK VAT" shown as before **Update Billing Address modal** Appears for paid orgs missing a billing address - Open modal for an IM customer with existing tax ID → "IM VAT" is pre-selected - Open modal for a GB customer with existing tax ID → "UK VAT" is pre-selected - Fill in IM address + IM VAT and save → saves correctly, modal closes --------- Co-authored-by: Ignacio Dobronich <ignacio@dobronich.com>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
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)
|
|
|
|
const vatIdPrefix = selectedTaxId?.vatPrefix
|
|
|
|
// if the value doesn't start with the prefix, prepend them
|
|
if (vatIdPrefix && !taxId.value.startsWith(vatIdPrefix)) {
|
|
return `${vatIdPrefix}${taxId.value}`
|
|
}
|
|
|
|
return taxId.value
|
|
}
|
|
|
|
/** Ignore id property amongst tax ids */
|
|
export const checkTaxIdEqual = (a: any, b: any) => {
|
|
return a?.type === b?.type && a?.value === b?.value
|
|
}
|