The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Detach billing address from stripe web portal
Joshen Lim88c61f9d4507
diff --git a/studio/components/interfaces/Billing/EnterpriseRequest.tsx b/studio/components/interfaces/Billing/EnterpriseRequest.tsxindex 023a43df165..204ca3c424f 100644--- a/studio/components/interfaces/Billing/EnterpriseRequest.tsx+++ b/studio/components/interfaces/Billing/EnterpriseRequest.tsx@@ -1,7 +1,7 @@import { FC, useState } from 'react'import { useRouter } from 'next/router'import { Transition } from '@headlessui/react'-import { Button, Form, Input, IconArrowLeft, IconCheckCircle } from '@supabase/ui'+import { Button, Form, Input, IconArrowLeft } from '@supabase/ui'import { post } from 'lib/common/fetch'import { useStore } from 'hooks'diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingAddress.constants.ts b/studio/components/interfaces/Organization/BillingSettings/BillingAddress.constants.tsnew file mode 100644index 00000000000..dfb167f8e63--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettings/BillingAddress.constants.ts@@ -0,0 +1,248 @@+export const COUNTRIES = {+ AD: 'Andorra',+ AE: 'United Arab Emirates',+ AF: 'Afghanistan',+ AG: 'Antigua and Barbuda',+ AI: 'Anguilla',+ AL: 'Albania',+ AM: 'Armenia',+ AO: 'Angola',+ AQ: 'Antarctica',+ AR: 'Argentina',+ AS: 'American Samoa',+ AT: 'Austria',+ AU: 'Australia',+ AW: 'Aruba',+ AX: 'Åland Islands',+ AZ: 'Azerbaijan',+ BA: 'Bosnia and Herzegovina',+ BB: 'Barbados',+ BD: 'Bangladesh',+ BE: 'Belgium',+ BF: 'Burkina Faso',+ BG: 'Bulgaria',+ BH: 'Bahrain',+ BI: 'Burundi',+ BJ: 'Benin',+ BL: 'Saint Barthélemy',+ BM: 'Bermuda',+ BN: 'Brunei Darussalam',+ BO: 'Bolivia',+ BR: 'Brazil',+ BS: 'Bahamas',+ BT: 'Bhutan',+ BV: 'Bouvet Island',+ BW: 'Botswana',+ BY: 'Belarus',+ BZ: 'Belize',+ CA: 'Canada',+ CC: 'Cocos (Keeling) Islands',+ CF: 'Central African Republic',+ CG: 'Congo',+ CH: 'Switzerland',+ CI: "Côte d'Ivoire",+ CK: 'Cook Islands',+ CL: 'Chile',+ CM: 'Cameroon',+ CN: 'China',+ CO: 'Colombia',+ CR: 'Costa Rica',+ CU: 'Cuba',+ CV: 'Cape Verde',+ CW: 'Curaçao',+ CX: 'Christmas Island',+ CY: 'Cyprus',+ CZ: 'Czech Republic',+ DE: 'Germany',+ DJ: 'Djibouti',+ DK: 'Denmark',+ DM: 'Dominica',+ DO: 'Dominican Republic',+ DZ: 'Algeria',+ EC: 'Ecuador',+ EE: 'Estonia',+ EG: 'Egypt',+ EH: 'Western Sahara',+ ER: 'Eritrea',+ ES: 'Spain',+ ET: 'Ethiopia',+ FI: 'Finland',+ FJ: 'Fiji',+ FK: 'Falkland Islands',+ FM: 'Micronesia',+ FO: 'Faroe Islands',+ FR: 'France',+ GA: 'Gabon',+ GB: 'United Kingdom',+ GD: 'Grenada',+ GE: 'Georgia',+ GF: 'French Guiana',+ GG: 'Guernsey',+ GH: 'Ghana',+ GI: 'Gibraltar',+ GL: 'Greenland',+ GM: 'Gambia',+ GN: 'Guinea',+ GP: 'Guadeloupe',+ GQ: 'Equatorial Guinea',+ GR: 'Greece',+ GS: 'South Georgia and the South Sandwich Islands',+ GT: 'Guatemala',+ GU: 'Guam',+ GW: 'Guinea-Bissau',+ GY: 'Guyana',+ HK: 'Hong Kong',+ HM: 'Heard & McDonald Islands',+ HN: 'Honduras',+ HR: 'Croatia',+ HT: 'Haiti',+ HU: 'Hungary',+ ID: 'Indonesia',+ IE: 'Ireland',+ IL: 'Israel',+ IM: 'Isle of Man',+ IN: 'India',+ IO: 'British Indian Ocean Territory',+ IQ: 'Iraq',+ IR: 'Iran',+ IS: 'Iceland',+ IT: 'Italy',+ JE: 'Jersey',+ JM: 'Jamaica',+ JO: 'Jordan',+ JP: 'Japan',+ KE: 'Kenya',+ KG: 'Kyrgyzstan',+ KH: 'Cambodia',+ KI: 'Kiribati',+ KM: 'Comoros',+ KN: 'St Kitts and Nevis',+ KP: 'North Korea',+ KR: 'South Korea',+ KW: 'Kuwait',+ KY: 'Cayman Islands',+ KZ: 'Kazakhstan',+ LA: 'Laos',+ LB: 'Lebanon',+ LC: 'St Lucia',+ LI: 'Liechtenstein',+ LK: 'Sri Lanka',+ LR: 'Liberia',+ LS: 'Lesotho',+ LT: 'Lithuania',+ LU: 'Luxembourg',+ LV: 'Latvia',+ LY: 'Libya',+ MA: 'Morocco',+ MC: 'Monaco',+ MD: 'Moldova',+ ME: 'Montenegro',+ MF: 'St Martin',+ MG: 'Madagascar',+ MH: 'Marshall Islands',+ MK: 'North Macedonia',+ ML: 'Mali',+ MM: 'Myanmar',+ MN: 'Mongolia',+ MO: 'Macao',+ MP: 'Northern Mariana Islands',+ MQ: 'Martinique',+ MR: 'Mauritania',+ MS: 'Montserrat',+ MT: 'Malta',+ MU: 'Mauritius',+ MV: 'Maldives',+ MW: 'Malawi',+ MX: 'Mexico',+ MY: 'Malaysia',+ MZ: 'Mozambique',+ NA: 'Namibia',+ NC: 'New Caledonia',+ NE: 'Niger',+ NF: 'Norfolk Island',+ NG: 'Nigeria',+ NI: 'Nicaragua',+ NL: 'Netherlands',+ NO: 'Norway',+ NP: 'Nepal',+ NR: 'Nauru',+ NU: 'Niue',+ NZ: 'New Zealand',+ OM: 'Oman',+ PA: 'Panama',+ PE: 'Peru',+ PF: 'French Polynesia',+ PG: 'Papua New Guinea',+ PH: 'Philippines',+ PK: 'Pakistan',+ PL: 'Poland',+ PM: 'St Pierre and Miquelon',+ PN: 'Pitcairn Islands',+ PR: 'Puerto Rico',+ PS: 'Palestinian Territories',+ PT: 'Portugal',+ PW: 'Palau',+ PY: 'Paraguay',+ QA: 'Qatar',+ RE: 'Réunion',+ RO: 'Romania',+ RS: 'Serbia',+ RU: 'Russia',+ RW: 'Rwanda',+ SA: 'Saudi Arabia',+ SB: 'Solomon Islands',+ SC: 'Seychelles',+ SD: 'Sudan',+ SE: 'Sweden',+ SG: 'Singapore',+ SH: 'St Helena',+ SI: 'Slovenia',+ SJ: 'Svalbard & Jan Mayen',+ SK: 'Slovakia',+ SL: 'Sierra Leone',+ SM: 'San Marino',+ SN: 'Senegal',+ SO: 'Somalia',+ SR: 'Suriname',+ SS: 'South Sudan',+ ST: 'Sao Tome and Principe',+ SV: 'El Salvador',+ SX: 'Sint Maarten',+ SY: 'Syria',+ SZ: 'Eswatini',+ TC: 'Turks & Caicos Islands',+ TD: 'Chad',+ TF: 'French Southern Territories',+ TG: 'Togo',+ TH: 'Thailand',+ TJ: 'Tajikistan',+ TK: 'Tokelau',+ TL: 'Timor-Leste',+ TM: 'Turkmenistan',+ TN: 'Tunisia',+ TO: 'Tonga',+ TR: 'Turkey',+ TT: 'Trinidad & Tobago',+ TV: 'Tuvalu',+ TW: 'Taiwan',+ TZ: 'Tanzania',+ UA: 'Ukraine',+ UG: 'Uganda',+ US: 'United States of America',+ UY: 'Uruguay',+ UZ: 'Uzbekistan',+ VA: 'Vatican City',+ VC: 'St Vincent and the Grenadines',+ VE: 'Venezuela',+ VG: 'British Virgin Islands',+ VI: 'US Virgin Islands',+ VN: 'Vietnam',+ VU: 'Vanuatu',+ WF: 'Wallis & Futuna',+ WS: 'Samoa',+ YE: 'Yemen',+ YT: 'Mayotte',+ ZA: 'South Africa',+ ZM: 'Zambia',+ ZW: 'Zimbabwe',+}diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsxindex f8f5df52373..9f8fc38d28b 100644--- a/studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingAddress.tsx@@ -1,46 +1,143 @@-import { FC } from 'react'+import { FC, useState } from 'react'+import { isEqual } from 'lodash'import { Dictionary } from '@supabase/grid'-import { Input, Button } from '@supabase/ui'+import { Form, Input, Button, Select } from '@supabase/ui'++import { useStore } from 'hooks'+import { patch } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { COUNTRIES } from './BillingAddress.constants'import Panel from 'components/to-be-cleaned/Panel'interface Props {loading: booleanaddress: Dictionary<any>- redirectToPortal: (url: string) => void+ onAddressUpdated: (address: any) => void}-const BillingAddress: FC<Props> = ({ loading, address, redirectToPortal }) => {+const BillingAddress: FC<Props> = ({ loading, address, onAddressUpdated }) => {+ const { ui } = useStore()+ const orgSlug = ui.selectedOrganization?.slug ?? ''const { city, country, line1, line2, postal_code, state } = address++ const [isDirty, setIsDirty] = useState(false)+ const initialValues = {+ city,+ country,+ line1,+ line2,+ postal_code,+ state,+ }++ const onValidate = (values: any) => {+ const errors = {} as any+ if (isEqual(values, initialValues)) {+ setIsDirty(false)+ } else {+ setIsDirty(true)+ }+ return errors+ }++ const onSubmit = async (values: any, { setSubmitting }: any) => {+ try {+ setSubmitting(true)+ const updatedCustomer = await patch(`${API_URL}/organizations/${orgSlug}/customer`, {+ address: values,+ })+ if (updatedCustomer.error) throw updatedCustomer.error+ ui.setNotification({+ category: 'success',+ message: 'Successfully updated billing address',+ })+ onAddressUpdated(updatedCustomer.address)+ } catch (error: any) {+ ui.setNotification({+ category: 'success',+ message: `Failed to update billing address: ${error.message}`,+ })+ } finally {+ setSubmitting(false)+ setIsDirty(false)+ }+ }+return (<div className="space-y-2"><div><h4>Billing address</h4><p className="text-sm opacity-50">This will be reflected in every invoice</p></div>- <Panel- loading={loading}- footer={- <div>- <Button type="default" onClick={() => redirectToPortal('/customer/update')}>- Edit billing address- </Button>- </div>- }- >- <Panel.Content className="w-3/5 space-y-2">- <Input readOnly placeholder="Address line 1" value={line1 || ''} />- <Input readOnly placeholder="Address line 2" value={line2 || ''} />- <div className="flex items-center space-x-2">- <Input className="w-full" placeholder="Country" readOnly value={country || ''} />- <Input- className="w-full"- placeholder="Postal code"- readOnly- value={postal_code || ''}- />+ <Panel loading={loading}>+ {loading ? (+ <div className="flex flex-col justify-between space-y-2 py-4 px-4">+ <div className="shimmering-loader rounded py-3 mx-1 w-2/3" />+ <div className="shimmering-loader rounded py-3 mx-1 w-1/2" />+ <div className="shimmering-loader rounded py-3 mx-1 w-1/3" /></div>- {city && <Input readOnly placeholder="City" value={city} />}- </Panel.Content>+ ) : (+ <Form+ validateOnBlur+ initialValues={initialValues}+ validate={onValidate}+ onSubmit={onSubmit}+ >+ {({ isSubmitting, handleReset }: any) => {+ return (+ <>+ <Panel.Content className="w-3/5 space-y-2">+ <Input id="line1" name="line1" placeholder="Address line 1" />+ <Input id="line2" name="line2" placeholder="Address line 2" />+ <div className="flex items-center space-x-2">+ <Select className="w-full" id="country" name="country" placeholder="Country">+ {Object.keys(COUNTRIES).map((code: string) => (+ <Select.Option key={code} value={code}>+ {(COUNTRIES as any)[code]}+ </Select.Option>+ ))}+ </Select>+ <Input+ className="w-full"+ id="postal_code"+ name="postal_code"+ placeholder="Postal code"+ />+ </div>+ <div className="flex items-center space-x-2">+ <Input className="w-full" id="city" name="city" placeholder="City" />+ <Input className="w-full" id="state" name="state" placeholder="State" />+ </div>+ </Panel.Content>+ <div className="border-t border-scale-400" />+ <Panel.Content>+ <div className="flex items-center space-x-4">+ <Button+ type="default"+ htmlType="reset"+ disabled={!isDirty || isSubmitting}+ onClick={() => {+ handleReset()+ setIsDirty(false)+ }}+ >+ Cancel+ </Button>+ <Button+ type="primary"+ htmlType="submit"+ loading={isSubmitting}+ disabled={!isDirty || isSubmitting}+ >+ Save changes+ </Button>+ </div>+ </Panel.Content>+ </>+ )+ }}+ </Form>+ )}</Panel></div>)diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsxindex 68e16f4c8e4..bea67bae846 100644--- a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx@@ -22,15 +22,18 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {const router = useRouter()const { ui } = useStore()+ const [customer, setCustomer] = useState<any>(null)+ const [isLoadingCustomer, setIsLoadingCustomer] = useState(false)++ const [paymentMethods, setPaymentMethods] = useState<any>(null)const [isLoadingPaymentMethods, setIsLoadingPaymentMethods] = useState(false)- const [loading, setLoading] = useState<boolean>(false)- const [error, setError] = useState<any>(undefined)- const [customer, setCustomer] = useState<any>(null)const [taxIds, setTaxIds] = useState<any>(null)- const [paymentMethods, setPaymentMethods] = useState<any>(null)+ const [isLoadingTaxIds, setIsLoadingTaxIds] = useState(false)++ const [loading, setLoading] = useState<boolean>(false)- const { slug, stripe_customer_id, stripe_customer_object } = organization+ const { slug, stripe_customer_id } = organizationconst defaultPaymentMethod = customer?.invoice_settings?.default_payment_method ?? ''const customerBalance = customer && customer.balance ? customer.balance / 100 : 0@@ -42,41 +45,36 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {: customerBalanceuseEffect(() => {+ getCustomerProfile()getPaymentMethods()+ getTaxIds()}, [slug])useEffect(() => {- if (stripe_customer_id) {- getStripeAccount()- }+ if (stripe_customer_id) getStripeAccount()}, [stripe_customer_id])- /**- * Get stripe account to populate page- */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 {- setLoading(true)- setError(null)- const { customer, error: customerError } = await post(`${API_URL}/stripe/customer`, {- stripe_customer_id: stripe_customer_id,- })- if (customerError) throw customerError+ setIsLoadingCustomer(true)+ const customer = await get(`${API_URL}/organizations/${slug}/customer`)+ if (customer.error) throw customer.errorsetCustomer(customer)-- const { taxIds, error: taxIdsError } = await post(`${API_URL}/stripe/tax-ids`, {- stripe_customer_id: stripe_customer_id,- })- if (taxIdsError) throw taxIdsError- setTaxIds(taxIds)+ setIsLoadingCustomer(false)} catch (error: any) {ui.setNotification({+ error,category: 'error',- message: `Failed to get Stripe account: ${error.message}`,+ message: `Failed to get organization information: ${error.message}`,})- setError(error)- } finally {- setLoading(false)}}@@ -96,13 +94,28 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {}}+ const getTaxIds = async () => {+ try {+ setIsLoadingTaxIds(true)+ const { data: taxIds, error } = await get(`${API_URL}/organizations/${slug}/tax-ids`)+ if (error) throw error+ setTaxIds(taxIds)+ setIsLoadingTaxIds(false)+ } catch (error: any) {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to get organization tax IDs: ${error.message}`,+ })+ }+ }+/*** 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 {- setLoading(true)let { billingPortal } = await post(`${API_URL}/stripe/billing`, {stripe_customer_id,returnTo: `${getURL()}${router.asPath}`,@@ -110,8 +123,6 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {window.location.replace(billingPortal + (path ? path : null))} catch (error: any) {ui.setNotification({ category: 'error', message: `Failed to redirect: ${error.message}` })- } finally {- setLoading(false)}}@@ -125,20 +136,20 @@ const BillingSettings: FC<Props> = ({ organization, projects = [] }) => {<ProjectsSummary projects={projects} /><CreditBalance balance={balance} isCredit={isCredit} isDebt={isDebt} /><PaymentMethods- loading={loading || isLoadingPaymentMethods}+ loading={isLoadingCustomer || isLoadingPaymentMethods}defaultPaymentMethod={defaultPaymentMethod}paymentMethods={paymentMethods || []}- onDefaultMethodUpdated={() => getStripeAccount()}+ onDefaultMethodUpdated={setCustomer}onPaymentMethodsDeleted={() => getPaymentMethods()}/><BillingAddress- loading={loading}- address={stripe_customer_object?.address ?? {}}- redirectToPortal={redirectToPortal}+ loading={isLoadingCustomer}+ address={customer?.address ?? {}}+ onAddressUpdated={(address: any) => setCustomer({ ...customer, address })}/><TaxID- loading={loading}- taxIds={taxIds?.data ?? []}+ loading={isLoadingTaxIds}+ taxIds={taxIds || []}redirectToPortal={redirectToPortal}/></div>diff --git a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsxindex e129b32fa96..7188b424500 100644--- a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx@@ -25,7 +25,7 @@ interface Props {loading: booleandefaultPaymentMethod: stringpaymentMethods: any[]- onDefaultMethodUpdated: () => void+ onDefaultMethodUpdated: (updatedCustomer: any) => voidonPaymentMethodsDeleted: () => void}@@ -48,13 +48,13 @@ const PaymentMethods: FC<Props> = ({const onConfirmMakeDefaultPaymentMethod = async () => {try {setIsUpdatingPaymentMethod(true)- const { error } = await patch(`${API_URL}/organizations/${orgSlug}/customer`, {+ const updatedCustomer = await patch(`${API_URL}/organizations/${orgSlug}/customer`, {invoice_settings: {default_payment_method: selectedMethodForDefault.id,},})- if (error) throw error- onDefaultMethodUpdated()+ if (updatedCustomer.error) throw updatedCustomer.error+ onDefaultMethodUpdated(updatedCustomer)setSelectedMethodForDefault(undefined)ui.setNotification({category: 'success',diff --git a/studio/pages/org/[slug]/settings.tsx b/studio/pages/org/[slug]/settings.tsxindex aeda9c6bb48..49603d48d54 100644--- a/studio/pages/org/[slug]/settings.tsx+++ b/studio/pages/org/[slug]/settings.tsx@@ -154,7 +154,7 @@ const TabsView = observer(() => {<><div className="space-y-3"><section className="mt-4">- <h3 className="text-xl">{organization?.name || 'Organization'} settings</h3>+ <h1 className="text-3xl">{organization?.name || 'Organization'} settings</h1></section><nav className=""><Tabs onChange={(id: any) => setSelectedTab(id)} type="underlined">diff --git a/studio/pages/project/[ref]/settings/billing/update/index.tsx b/studio/pages/project/[ref]/settings/billing/update/index.tsxindex 75037d670a2..f654ef98708 100644--- a/studio/pages/project/[ref]/settings/billing/update/index.tsx+++ b/studio/pages/project/[ref]/settings/billing/update/index.tsx@@ -60,12 +60,9 @@ const BillingUpdate: NextPage = () => {throw new Error('Unable to get subscription ID of project')}- const { data: subscription, error }: { data: StripeSubscription; error: any } = await post(- `${API_URL}/stripe/subscription`,- { subscription_id: ui.selectedProject.subscription_id }- )+ const subscription = await get(`${API_URL}/projects/${projectRef}/subscription`)+ if (subscription.error) throw subscription.error- if (error) throw errorsetSubscription(subscription)} catch (error: any) {ui.setNotification({diff --git a/studio/pages/project/[ref]/settings/billing/update/pro.tsx b/studio/pages/project/[ref]/settings/billing/update/pro.tsxindex 1c8b6307ecf..d36898cfbd7 100644--- a/studio/pages/project/[ref]/settings/billing/update/pro.tsx+++ b/studio/pages/project/[ref]/settings/billing/update/pro.tsx@@ -80,12 +80,8 @@ const BillingUpdatePro: NextPage = () => {throw new Error('Unable to get subscription ID of project')}- const { data: subscription, error }: { data: StripeSubscription; error: any } = await post(- `${API_URL}/stripe/subscription`,- { subscription_id: ui.selectedProject.subscription_id }- )-- if (error) throw error+ const subscription = await get(`${API_URL}/projects/${projectRef}/subscription`)+ if (subscription.error) throw subscription.errorsetSubscription(subscription)} catch (error: any) {ui.setNotification({