The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Detach tax ids from stripe web portal
Joshen Limdd776a5be9c4
diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingAddress.constants.ts b/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.constants.tssimilarity index 100%rename from studio/components/interfaces/Organization/BillingSettings/BillingAddress.constants.tsrename to studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.constants.tsdiff --git a/studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingAddress/index.tsxsimilarity index 100%rename from studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsxrename to studio/components/interfaces/Organization/BillingSettings/BillingAddress/index.tsxdiff --git a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsxindex bea67bae846..77ce2a0a94c 100644--- a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx@@ -1,10 +1,8 @@-import { useRouter } from 'next/router'import { FC, useState, useEffect } from 'react'import { useStore } from 'hooks'import { API_URL } from 'lib/constants'-import { getURL } from 'lib/helpers'-import { get, post } from 'lib/common/fetch'+import { get } from 'lib/common/fetch'import AWSMarketplaceSubscription from './AWSMarketplaceSubscription'import ProjectsSummary from './ProjectsSummary'@@ -19,8 +17,8 @@ interface Props {}const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {- const router = useRouter()const { ui } = useStore()+ const { slug } = organizationconst [customer, setCustomer] = useState<any>(null)const [isLoadingCustomer, setIsLoadingCustomer] = useState(false)@@ -31,10 +29,6 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {const [taxIds, setTaxIds] = useState<any>(null)const [isLoadingTaxIds, setIsLoadingTaxIds] = useState(false)- const [loading, setLoading] = useState<boolean>(false)-- const { slug, stripe_customer_id } = organization-const defaultPaymentMethod = customer?.invoice_settings?.default_payment_method ?? ''const customerBalance = customer && customer.balance ? customer.balance / 100 : 0const isCredit = customerBalance < 0@@ -50,18 +44,6 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {getTaxIds()}, [slug])- useEffect(() => {- if (stripe_customer_id) getStripeAccount()- }, [stripe_customer_id])-- const getStripeAccount = async () => {- const { customer, error: customerError } = await post(`${API_URL}/stripe/customer`, {- stripe_customer_id: stripe_customer_id,- })- if (customerError) throw customerError- console.log('getStripeAccount', customer)- }-const getCustomerProfile = async () => {try {setIsLoadingCustomer(true)@@ -110,22 +92,6 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {}}- /**- * Get a link and then redirect them- * path is used to determine what path inside billing portal to redirect to- */- const redirectToPortal = async (path: any) => {- try {- let { billingPortal } = await post(`${API_URL}/stripe/billing`, {- stripe_customer_id,- returnTo: `${getURL()}${router.asPath}`,- })- window.location.replace(billingPortal + (path ? path : null))- } catch (error: any) {- ui.setNotification({ category: 'error', message: `Failed to redirect: ${error.message}` })- }- }-return (<article className="my-4 container max-w-4xl space-y-8">{organization.aws_marketplace ? (@@ -150,7 +116,7 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {<TaxIDloading={isLoadingTaxIds}taxIds={taxIds || []}- redirectToPortal={redirectToPortal}+ onTaxIdsUpdated={(ids: any) => setTaxIds(ids)}/></div></>diff --git a/studio/components/interfaces/Organization/BillingSettings/TaxID.tsx b/studio/components/interfaces/Organization/BillingSettings/TaxID.tsxdeleted file mode 100644index ecd4fbe3a5c..00000000000--- a/studio/components/interfaces/Organization/BillingSettings/TaxID.tsx+++ /dev/null@@ -1,59 +0,0 @@-import { FC } from 'react'-import { Input, Button, IconLoader } from '@supabase/ui'-import Panel from 'components/to-be-cleaned/Panel'--interface Props {- loading: boolean- taxIds: any[]- redirectToPortal: (url: string) => void-}--const TaxID: FC<Props> = ({ loading, taxIds, redirectToPortal }) => {- return (- <div className="space-y-2">- <div>- <h4>Tax ID</h4>- <p className="text-sm opacity-50">- If you would like to include specific tax ID(s) to your invoices- </p>- </div>- <Panel- loading={loading}- footer={- <div>- <Button type="default" onClick={() => redirectToPortal('/customer/update')}>- Edit Tax IDs- </Button>- </div>- }- >- <Panel.Content className="w-3/5">- {loading && taxIds.length === 0 ? (- <div className="flex items-center space-x-4">- <IconLoader className="animate-spin" size={14} />- <p className="text-sm">Retrieving tax information</p>- </div>- ) : taxIds.length >= 1 ? (- <div className="w-full space-y-2">- {taxIds.map((taxId: any) => {- const taxIdType = taxId.type.replace('_', ' ').toUpperCase()- return (- <div key={taxId.id} className="flex items-center space-x-6">- <p>{taxIdType}</p>- <Input readOnly value={taxId.value} />- </div>- )- })}- </div>- ) : (- <div>- <p className="flex items-center space-x-2 text-sm text-scale-900">No tax IDs</p>- </div>- )}- </Panel.Content>- </Panel>- </div>- )-}--export default TaxIDdiff --git a/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.ts b/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.tsnew file mode 100644index 00000000000..7b650eebcca--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.ts@@ -0,0 +1,279 @@+// https://stripe.com/docs/api/customer_tax_ids/create+export const TAX_IDS = {+ ae_trn: {+ country: 'United Arab Emirates',+ placeholder: '123456789012345',+ },+ at_vat: {+ country: 'Austria',+ placeholder: 'ATU12345678',+ },+ au_abn: {+ country: 'Australia',+ placeholder: '12345678912',+ },+ au_arn: {+ country: 'Australia',+ placeholder: '123456789123',+ },+ be_vat: {+ country: 'Belgium',+ placeholder: 'BE0123456789',+ },+ bg_vat: {+ country: 'Bulgaria',+ placeholder: 'BG0123456789',+ },+ br_cnpj: {+ country: 'Brazil',+ placeholder: '01.234.456/5432-10',+ },+ br_cpf: {+ country: 'Brazil',+ placeholder: '123.456.789-87',+ },+ ca_bn: {+ country: 'Canada',+ placeholder: '123456789',+ },+ ca_gst_hst: {+ country: 'Canada',+ placeholder: '123456789RT0002',+ },+ ca_pst_bc: {+ country: 'Canada',+ placeholder: 'PST-1234-5678',+ },+ ca_pst_mb: {+ country: 'Canada',+ placeholder: '123456-7',+ },+ ca_pst_sk: {+ country: 'Canada',+ placeholder: '1234567',+ },+ ca_qst: {+ country: 'Canada',+ placeholder: '1234567890TQ1234',+ },+ ch_vat: {+ country: 'Switzerland',+ placeholder: 'CHE-123.456.789 MWST',+ },+ cl_tin: {+ country: 'Chile',+ placeholder: '12.345.678-K',+ },+ cy_vat: {+ country: 'Cyprus',+ placeholder: 'CY12345678Z',+ },+ cz_vat: {+ country: 'Czech Republic',+ placeholder: 'CZ1234567890',+ },+ de_vat: {+ country: 'Germany',+ placeholder: 'DE123456789',+ },+ dk_vat: {+ country: 'Denmark',+ placeholder: 'DK12345678',+ },+ ee_vat: {+ country: 'Estonia',+ placeholder: 'EE123456789',+ },+ es_cif: {+ country: 'Spain',+ placeholder: 'A12345678',+ },+ es_vat: {+ country: 'Spain',+ placeholder: 'ESA1234567Z',+ },+ fi_vat: {+ country: 'Finland',+ placeholder: 'FI12345678',+ },+ fr_vat: {+ country: 'France',+ placeholder: 'FRAB123456789',+ },+ gb_vat: {+ country: 'United Kingdom',+ placeholder: 'GB123456789',+ },+ ge_vat: {+ country: 'Georgia',+ placeholder: '123456789',+ },+ gr_vat: {+ country: 'Greece',+ placeholder: 'EL123456789',+ },+ hk_br: {+ country: 'Hong Kong SAR China',+ placeholder: '12345678',+ },+ hr_vat: {+ country: 'Croatia',+ placeholder: 'HR12345678912',+ },+ hu_vat: {+ country: 'Hungary',+ placeholder: 'HU12345678912',+ },+ id_npwp: {+ country: 'Indonesia',+ placeholder: '12.345.678.9-012.345',+ },+ ie_vat: {+ country: 'Ireland',+ placeholder: 'IE12345678AB',+ },+ il_vat: {+ country: 'Israel',+ placeholder: '000012345',+ },+ in_gst: {+ country: 'India',+ placeholder: '12ABCDE3456FGZH',+ },+ is_vat: {+ country: 'Iceland',+ placeholder: '123456',+ },+ it_vat: {+ country: 'Italy',+ placeholder: 'IT12345678912',+ },+ jp_cn: {+ country: 'Japan',+ placeholder: '1234567891234',+ },+ jp_rn: {+ country: 'Japan',+ placeholder: '12345',+ },+ kr_brn: {+ country: 'Korea',+ placeholder: '123-45-67890',+ },+ li_uid: {+ country: 'Liechtenstein',+ placeholder: 'CHE123456789',+ },+ lt_vat: {+ country: 'Lithuania',+ placeholder: 'LT123456789123',+ },+ lu_vat: {+ country: 'Luxembourg',+ placeholder: 'LU12345678',+ },+ lv_vat: {+ country: 'Latvia',+ placeholder: 'LV12345678912',+ },+ mt_vat: {+ country: 'Malta',+ placeholder: 'MT12345678',+ },+ mx_rfc: {+ country: 'Mexico',+ placeholder: 'ABC010203AB9',+ },+ my_frp: {+ country: 'Malaysia',+ placeholder: '12345678',+ },+ my_itn: {+ country: 'Malaysia',+ placeholder: 'C 1234567890',+ },+ my_sst: {+ country: 'Malaysia',+ placeholder: 'A12-3456-78912345',+ },+ nl_vat: {+ country: 'Netherlands',+ placeholder: 'NL123456789B12',+ },+ no_vat: {+ country: 'Norway',+ placeholder: '123456789MVA',+ },+ nz_gst: {+ country: 'New Zealand',+ placeholder: '123456789',+ },+ pl_vat: {+ country: 'Poland',+ placeholder: 'PL1234567890',+ },+ pt_vat: {+ country: 'Portugal',+ placeholder: 'PT123456789',+ },+ ro_vat: {+ country: 'Romania',+ placeholder: 'RO1234567891',+ },+ ru_inn: {+ country: 'Russia',+ placeholder: '1234567891',+ },+ ru_kpp: {+ country: 'Russia',+ placeholder: '123456789',+ },+ sa_vat: {+ country: 'Saudi Arabia',+ placeholder: '123456789012345',+ },+ se_vat: {+ country: 'Sweden',+ placeholder: 'SE123456789123',+ },+ sg_gst: {+ country: 'Singapore',+ placeholder: 'M12345678X',+ },+ sg_uen: {+ country: 'Singapore',+ placeholder: '123456789F',+ },+ si_vat: {+ country: 'Slovenia',+ placeholder: 'SI12345678',+ },+ sk_vat: {+ country: 'Slovakia',+ placeholder: 'SK1234567891',+ },+ th_vat: {+ country: 'Thailand',+ placeholder: '1234567891234',+ },+ tw_vat: {+ country: 'Taiwan',+ placeholder: '12345678',+ },+ ua_vat: {+ country: 'Ukraine',+ placeholder: '123456789',+ },+ us_ein: {+ country: 'United States',+ placeholder: '12-3456789',+ },+ xi_vat: {+ country: 'United Kingdom',+ placeholder: 'XI123456789',+ },+ za_vat: {+ country: 'South Africa',+ placeholder: '4123456789',+ },+}diff --git a/studio/components/interfaces/Organization/BillingSettings/TaxID/index.tsx b/studio/components/interfaces/Organization/BillingSettings/TaxID/index.tsxnew file mode 100644index 00000000000..880b637f70e--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettings/TaxID/index.tsx@@ -0,0 +1,199 @@+import { FC, useEffect, useState } from 'react'+import { isEqual } from 'lodash'+import { Input, Button, IconLoader, IconPlus, Select, IconX } from '@supabase/ui'++import { useStore } from 'hooks'+import { uuidv4 } from 'lib/helpers'+import { post, delete_ } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import Panel from 'components/to-be-cleaned/Panel'+import { TAX_IDS } from './TaxID.constants'++interface Props {+ loading: boolean+ taxIds: any[]+ onTaxIdsUpdated: (taxIds: any) => void+}++// Stripe recommends to delete tax ids and create new ones to update+// https://stripe.com/docs/billing/customer/tax-ids++const TaxID: FC<Props> = ({ loading, taxIds, onTaxIdsUpdated }) => {+ const { ui } = useStore()+ const slug = ui.selectedOrganization?.slug ?? ''++ const [isSaving, setIsSaving] = useState(false)+ const [errors, setErrors] = useState<string[]>([])+ const [taxIdValues, setTaxIdValues] = useState(taxIds)+ const formattedTaxIds = taxIds.map((taxId: any) => {+ return { id: taxId.id, type: taxId.type, value: taxId.value }+ })++ useEffect(() => {+ if (taxIdValues.length === 0) {+ setTaxIdValues(formattedTaxIds)+ } else {+ const erroredTaxIds = taxIdValues.filter((taxId: any) => errors.includes(taxId.id))+ setTaxIdValues(formattedTaxIds.concat(erroredTaxIds))+ }+ }, [taxIds])++ const hasChanges = !isEqual(taxIdValues, formattedTaxIds)++ const onUpdateTaxId = (id: string, key: string, value: string) => {+ const updatedTaxIds = taxIdValues.map((taxId: any) => {+ if (taxId.id === id) {+ return { ...taxId, [key]: value }+ }+ return taxId+ })+ setTaxIdValues(updatedTaxIds)+ }++ const onAddNewTaxId = () => {+ const newTaxId = { id: uuidv4(), type: 'ae_trn', value: '' }+ const updatedTaxIds = taxIdValues.concat([newTaxId])+ setTaxIdValues(updatedTaxIds)+ }++ const onRemoveTaxId = (id: string) => {+ const updatedTaxIds = taxIdValues.filter((taxId: any) => {+ return taxId.id !== id+ })+ setTaxIdValues(updatedTaxIds)+ }++ const onResetTaxIds = () => {+ setTaxIdValues(formattedTaxIds)+ }++ const onSaveTaxIds = async () => {+ // To make things simple we delete all existing ones and create new ones from this session+ setIsSaving(true)+ try {+ const deletedIds = await Promise.all(+ taxIds.map(async (taxId: any) => {+ return await delete_(`${API_URL}/organizations/${slug}/tax-ids`, { id: taxId.id })+ })+ )++ const newIds = await Promise.all(+ taxIdValues.map(async (taxId: any) => {+ const result = await post(`${API_URL}/organizations/${slug}/tax-ids`, {+ type: taxId.type,+ value: taxId.value,+ })+ return { id: taxId.id, result }+ })+ )++ const taxIdsWithErrors = newIds.filter((taxId: any) => {+ if (taxId.result.error) return taxId+ })+ setErrors(taxIdsWithErrors.map((taxId: any) => taxId.id))++ if (taxIdsWithErrors.length > 0) {+ taxIdsWithErrors.forEach((taxId: any) => {+ ui.setNotification({ category: 'error', message: taxId.result.error.message })+ })+ } else {+ ui.setNotification({ category: 'success', message: 'Successfully updated tax IDs' })+ }+ const idsCreated = newIds+ .filter((taxId: any) => !taxId.result.error)+ .map((taxId: any) => taxId.result)++ onTaxIdsUpdated(idsCreated)+ } catch (error: any) {+ ui.setNotification({ category: 'error', message: 'Failed to save tax IDs' })+ } finally {+ setIsSaving(false)+ }+ }++ return (+ <div className="space-y-2">+ <div>+ <h4>Tax ID</h4>+ <p className="text-sm opacity-50">+ If you would like to include specific tax ID(s) to your invoices+ </p>+ </div>+ <Panel+ loading={loading}+ footer={+ <div className="flex items-center space-x-4">+ <Button+ type="default"+ htmlType="reset"+ disabled={!hasChanges || isSaving}+ onClick={() => onResetTaxIds()}+ >+ Cancel+ </Button>+ <Button+ type="primary"+ htmlType="submit"+ loading={isSaving}+ disabled={!hasChanges || isSaving}+ onClick={() => onSaveTaxIds()}+ >+ Save changes+ </Button>+ </div>+ }+ >+ <Panel.Content className="w-3/5 space-y-4">+ {loading && taxIdValues.length === 0 ? (+ <div className="flex items-center space-x-4">+ <IconLoader className="animate-spin" size={14} />+ <p className="text-sm">Retrieving tax information</p>+ </div>+ ) : taxIdValues.length >= 1 ? (+ <div className="w-full space-y-2">+ {taxIdValues.map((taxId: any, idx: number) => {+ return (+ <div key={`tax-id-${idx}`} className="flex items-center space-x-2">+ <Select+ value={taxId.type}+ onChange={(e: any) => onUpdateTaxId(taxId.id, 'type', e.target.value)}+ >+ {Object.keys(TAX_IDS).map((taxId: string) => (+ <Select.Option key={taxId} value={taxId}>+ {taxId.replace('_', ' ').toUpperCase()}+ </Select.Option>+ ))}+ </Select>+ <Input+ value={taxId.value}+ placeholder={(TAX_IDS as any)[taxId.type].placeholder}+ onChange={(e: any) => onUpdateTaxId(taxId.id, 'value', e.target.value)}+ />+ <Button+ type="text"+ icon={<IconX />}+ onClick={() => onRemoveTaxId(taxId.id)}+ ></Button>+ </div>+ )+ })}+ </div>+ ) : (+ <div>+ <p className="flex items-center space-x-2 text-sm text-scale-900">No tax IDs</p>+ </div>+ )}+ <div+ className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition cursor-pointer"+ onClick={() => onAddNewTaxId()}+ >+ <IconPlus size={14} />+ <p className="text-sm">Add another ID</p>+ </div>+ </Panel.Content>+ </Panel>+ </div>+ )+}++export default TaxID