diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 31c2a07972..8773bb77b9 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -276,14 +276,16 @@ export class Billing { organizationId: string, name: string, billingPlan: string, - paymentMethodId: string + paymentMethodId: string, + billingAddressId: string ): Promise { const path = `/organizations`; const params = { organizationId, name, billingPlan, - paymentMethodId + paymentMethodId, + billingAddressId }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( @@ -331,13 +333,15 @@ export class Billing { async updatePlan( organizationId: string, billingPlan: string, - paymentMethodId: string + paymentMethodId: string, + billingAddressId: string ): Promise { const path = `/organizations/${organizationId}/plan`; const params = { organizationId, billingPlan, - paymentMethodId + paymentMethodId, + billingAddressId }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index d139f71c6d..63d6b4dfa1 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -283,6 +283,7 @@ export async function checkForFreeOrgOverflow(orgs: Models.TeamList>) { diff --git a/src/routes/console/changeOrganizationTierCloud.svelte b/src/routes/console/changeOrganizationTierCloud.svelte index a4001b887c..64afb5bc2b 100644 --- a/src/routes/console/changeOrganizationTierCloud.svelte +++ b/src/routes/console/changeOrganizationTierCloud.svelte @@ -40,7 +40,8 @@ await sdk.forConsole.billing.updatePlan( $organization.$id, $changeOrganizationTier.billingPlan, - $changeOrganizationTier.paymentMethodId + $changeOrganizationTier.paymentMethodId, + $changeOrganizationTier.billingAddressId ); feedback.submitFeedback( 'downgrade', @@ -78,35 +79,10 @@ const org = await sdk.forConsole.billing.updatePlan( $organization.$id, $changeOrganizationTier.billingPlan, - $changeOrganizationTier.paymentMethodId + $changeOrganizationTier.paymentMethodId, + $changeOrganizationTier.billingAddressId ); - //Add billing address - if ($changeOrganizationTier.billingAddressId) { - await sdk.forConsole.billing.setBillingAddress( - org.$id, - $changeOrganizationTier.billingAddressId - ); - } else if ( - $changeOrganizationTier.billingAddress && - $changeOrganizationTier.billingAddress.streetAddress - ) { - const response = await sdk.forConsole.billing.createAddress( - $changeOrganizationTier.billingAddress.country, - $changeOrganizationTier.billingAddress.streetAddress, - $changeOrganizationTier.billingAddress.city, - $changeOrganizationTier.billingAddress.state, - $changeOrganizationTier.billingAddress.postalCode - ? $changeOrganizationTier.billingAddress.postalCode - : undefined, - $changeOrganizationTier.billingAddress.addressLine2 - ? $changeOrganizationTier.billingAddress.addressLine2 - : undefined - ); - - await sdk.forConsole.billing.setBillingAddress(org.$id, response.$id); - } - //Add coupon if ($changeOrganizationTier.couponCode) { await sdk.forConsole.billing.addCredit( @@ -193,15 +169,6 @@ paymentMethodId: null, collaborators: [], billingAddressId: null, - billingAddress: { - $id: null, - streetAddress: null, - addressLine2: null, - city: null, - state: null, - postalCode: null, - country: null - }, taxId: null, feedbackMessage: null }; diff --git a/src/routes/console/createOrganizationCloud.svelte b/src/routes/console/createOrganizationCloud.svelte index 9e958a28ce..8c0fb58f74 100644 --- a/src/routes/console/createOrganizationCloud.svelte +++ b/src/routes/console/createOrganizationCloud.svelte @@ -32,33 +32,9 @@ $createOrganization.id ?? ID.unique(), $createOrganization.name, $createOrganization.billingPlan, - $createOrganization.paymentMethodId + $createOrganization.paymentMethodId, + $createOrganization.billingAddressId ); - //Add billing address - if ($createOrganization.billingAddressId) { - await sdk.forConsole.billing.setBillingAddress( - org.$id, - $createOrganization.billingAddressId - ); - } else if ( - $createOrganization.billingAddress && - $createOrganization.billingAddress.streetAddress - ) { - const response = await sdk.forConsole.billing.createAddress( - $createOrganization.billingAddress.country, - $createOrganization.billingAddress.streetAddress, - $createOrganization.billingAddress.city, - $createOrganization.billingAddress.state, - $createOrganization.billingAddress.postalCode - ? $createOrganization.billingAddress.postalCode - : undefined, - $createOrganization.billingAddress.addressLine2 - ? $createOrganization.billingAddress.addressLine2 - : undefined - ); - - await sdk.forConsole.billing.setBillingAddress(org.$id, response.$id); - } //Add budget if ($createOrganization?.billingBudget) { @@ -121,15 +97,6 @@ paymentMethodId: null, collaborators: [], billingAddressId: null, - billingAddress: { - $id: null, - streetAddress: null, - addressLine2: null, - city: null, - state: null, - postalCode: null, - country: null - }, taxId: null }; }); diff --git a/src/routes/console/onboarding/+page.svelte b/src/routes/console/onboarding/+page.svelte index 5cf93944cd..55ebefea7b 100644 --- a/src/routes/console/onboarding/+page.svelte +++ b/src/routes/console/onboarding/+page.svelte @@ -62,6 +62,7 @@ ID.unique(), 'Personal Projects', 'tier-0', + null, null ); } else return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects'); diff --git a/src/routes/console/wizard/cloudOrganization/addressDetails.svelte b/src/routes/console/wizard/cloudOrganization/addressDetails.svelte index af7cbce055..608833f9c5 100644 --- a/src/routes/console/wizard/cloudOrganization/addressDetails.svelte +++ b/src/routes/console/wizard/cloudOrganization/addressDetails.svelte @@ -14,6 +14,30 @@ } ]; let addressList: AddressesList; + let country: string; + let streetAddress: string; + let city: string; + let state: string; + let postalCode: string; + let addressLine2: string; + + async function handleAddress() { + if (!$createOrganization.billingAddressId) { + try { + const response = await sdk.forConsole.billing.createAddress( + country, + streetAddress, + city, + state, + postalCode ? postalCode : undefined, + addressLine2 ? addressLine2 : undefined + ); + $createOrganization.billingAddressId = response.$id; + } catch (error) { + throw new Error(error.message); + } + } + } onMount(async () => { addressList = await sdk.forConsole.billing.listAddresses(); @@ -21,7 +45,7 @@ const countryList = await sdk.forProject.locale.listCountries(); const locale = await sdk.forProject.locale.get(); if (locale?.countryCode) { - $createOrganization.billingAddress.country = locale.countryCode; + country = locale.countryCode; } options = countryList.countries.map((country) => { return { @@ -32,7 +56,7 @@ }); - + Billing address Add a billing address for your organization. @@ -70,25 +94,25 @@ placeholder="Enter tax ID" optionalText="(optional)" /> diff --git a/src/routes/console/wizard/cloudOrganization/store.ts b/src/routes/console/wizard/cloudOrganization/store.ts index 7c1247fe36..481924e9de 100644 --- a/src/routes/console/wizard/cloudOrganization/store.ts +++ b/src/routes/console/wizard/cloudOrganization/store.ts @@ -1,5 +1,4 @@ import type { WizardStepsType } from '$lib/layout/wizard.svelte'; -import type { Address } from '$lib/sdk/billing'; import type { Tier } from '$lib/stores/billing'; import { writable } from 'svelte/store'; @@ -12,7 +11,6 @@ export const createOrganization = writable<{ billingPlan: Tier; paymentMethodId: string; billingAddressId: string; - billingAddress?: Address; collaborators?: string[]; billingBudget?: number; taxId?: string; @@ -23,14 +21,5 @@ export const createOrganization = writable<{ paymentMethodId: null, collaborators: [], billingAddressId: null, - billingAddress: { - $id: null, - streetAddress: null, - addressLine2: null, - city: null, - state: null, - postalCode: null, - country: null - }, taxId: null }); diff --git a/src/routes/console/wizard/cloudOrganizationChangeTier/addressDetails.svelte b/src/routes/console/wizard/cloudOrganizationChangeTier/addressDetails.svelte index 03861a9c04..5bd9ebaf56 100644 --- a/src/routes/console/wizard/cloudOrganizationChangeTier/addressDetails.svelte +++ b/src/routes/console/wizard/cloudOrganizationChangeTier/addressDetails.svelte @@ -15,6 +15,30 @@ } ]; let addressList: AddressesList; + let country: string; + let streetAddress: string; + let city: string; + let state: string; + let postalCode: string; + let addressLine2: string; + + async function handleAddress() { + if (!$changeOrganizationTier.billingAddressId) { + try { + const response = await sdk.forConsole.billing.createAddress( + country, + streetAddress, + city, + state, + postalCode ? postalCode : undefined, + addressLine2 ? addressLine2 : undefined + ); + $changeOrganizationTier.billingAddressId = response.$id; + } catch (error) { + throw new Error(error.message); + } + } + } onMount(async () => { addressList = await sdk.forConsole.billing.listAddresses(); @@ -23,7 +47,7 @@ : addressList.billingAddresses?.[0]?.$id ?? null; const locale = await sdk.forProject.locale.get(); if (locale?.countryCode && !$changeOrganizationTier.billingAddressId) { - $changeOrganizationTier.billingAddress.country = locale.countryCode; + country = locale.countryCode; } const countryList = await sdk.forProject.locale.listCountries(); options = countryList.countries.map((country) => { @@ -35,7 +59,7 @@ }); - + Billing address Add a billing address for your organization. @@ -73,25 +97,25 @@ placeholder="Enter tax ID" optionalText="(optional)" /> diff --git a/src/routes/console/wizard/cloudOrganizationChangeTier/store.ts b/src/routes/console/wizard/cloudOrganizationChangeTier/store.ts index 25f69bf5d0..0721a89c36 100644 --- a/src/routes/console/wizard/cloudOrganizationChangeTier/store.ts +++ b/src/routes/console/wizard/cloudOrganizationChangeTier/store.ts @@ -1,5 +1,4 @@ import type { WizardStepsType } from '$lib/layout/wizard.svelte'; -import type { Address } from '$lib/sdk/billing'; import type { Tier } from '$lib/stores/billing'; import { writable } from 'svelte/store'; @@ -12,7 +11,6 @@ export const changeOrganizationTier = writable<{ billingPlan: Tier; paymentMethodId: string; billingAddressId: string; - billingAddress?: Address; billingBudget?: number; collaborators?: string[]; isOverLimit?: boolean; @@ -33,14 +31,5 @@ export const changeOrganizationTier = writable<{ collaborators: [], isOverLimit: false, billingAddressId: null, - billingAddress: { - $id: null, - streetAddress: null, - addressLine2: null, - city: null, - state: null, - postalCode: null, - country: null - }, taxId: null });