From 343858ba9af80586ad71002b8b265f44c19c3e95 Mon Sep 17 00:00:00 2001 From: ChiragAgg5k Date: Thu, 6 Mar 2025 17:11:25 +0530 Subject: [PATCH] refactor: account billing endpoints --- src/lib/sdk/billing.ts | 152 +----------------- src/lib/stores/organization.ts | 5 - .../(console)/account/payments/+page.ts | 2 +- .../account/payments/addressModal.svelte | 4 +- .../payments/deleteAddressModal.svelte | 4 +- .../account/payments/editAddressModal.svelte | 4 +- .../organization-[organization]/+page.svelte | 34 ++-- .../billing/+page.ts | 2 +- .../billing/replaceAddress.svelte | 26 +-- .../settings/deleteOrganizationModal.svelte | 26 +-- .../wizard/step1.svelte | 6 +- .../settings/deleteProject.svelte | 2 +- 12 files changed, 56 insertions(+), 211 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 131fa12c6..6ba951aa5 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -2,7 +2,7 @@ import type { Tier } from '$lib/stores/billing'; import type { Campaign } from '$lib/stores/campaigns'; import type { Client, Models } from '@appwrite.io/console'; import type { PaymentMethod } from '@stripe/stripe-js'; -import type { Organization, OrganizationError, OrganizationList } from '../stores/organization'; +import type { Organization, OrganizationError } from '../stores/organization'; export type Invoice = { $id: string; @@ -158,22 +158,6 @@ export class Billing { this.client = client; } - async listOrganization(queries: string[] = []): Promise { - const path = `/organizations`; - const params = { - queries - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async validateOrganization(organizationId: string, invites: string[]): Promise { const path = `/organizations/${organizationId}/validate`; const params = { @@ -247,22 +231,6 @@ export class Billing { ); } - async deleteOrganization(organizationId: string): Promise { - const path = `/organizations/${organizationId}`; - const params = { - organizationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'DELETE', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async estimationDeleteOrganization( organizationId: string ): Promise { @@ -954,124 +922,6 @@ export class Billing { ); } - async listAddresses(queries: string[] = []): Promise { - const path = `/account/billing-addresses`; - const params = { - queries - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getAddress(billingAddressId: string): Promise
{ - const path = `/account/billing-addresses/${billingAddressId}`; - const params = { - billingAddressId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async createAddress( - country: string, - streetAddress: string, - city: string, - state: string, - postalCode: string, - addressLine2?: string - ): Promise
{ - const path = `/account/billing-addresses`; - const params = { - country, - streetAddress, - city, - state, - postalCode, - addressLine2 - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'POST', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async updateAddress( - billingAddressId: string, - country: string, - streetAddress: string, - city: string, - state: string, - postalCode: string, - addressLine2?: string - ): Promise
{ - const path = `/account/billing-addresses/${billingAddressId}`; - const params = { - billingAddressId, - country, - streetAddress, - city, - state, - postalCode, - addressLine2 - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'PUT', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async deleteAddress(billingAddressId: string): Promise { - const path = `/account/billing-addresses/${billingAddressId}`; - const params = { - billingAddressId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'delete', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async listRegions(): Promise { - const path = `/console/regions`; - const params = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async getPlansInfo(): Promise { const path = `/console/plans`; const params = {}; diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 92f6650c8..37599058d 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -34,11 +34,6 @@ export type Organization = Models.Team> & { billingInvoiceId: string; }; -export type OrganizationList = { - teams: Organization[]; - total: number; -}; - export type BillingLimits = { bandwidth: number; documents: number; diff --git a/src/routes/(console)/account/payments/+page.ts b/src/routes/(console)/account/payments/+page.ts index 983d611cb..2892a28ba 100644 --- a/src/routes/(console)/account/payments/+page.ts +++ b/src/routes/(console)/account/payments/+page.ts @@ -8,7 +8,7 @@ export const load: PageLoad = async ({ depends }) => { const [paymentMethods, addressList] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), - sdk.forConsole.billing.listAddresses() + sdk.forConsole.account.listBillingAddresses() ]); return { paymentMethods, diff --git a/src/routes/(console)/account/payments/addressModal.svelte b/src/routes/(console)/account/payments/addressModal.svelte index fbeb783af..41f5f2753 100644 --- a/src/routes/(console)/account/payments/addressModal.svelte +++ b/src/routes/(console)/account/payments/addressModal.svelte @@ -1,6 +1,6 @@ diff --git a/src/routes/(console)/project-[project]/settings/deleteProject.svelte b/src/routes/(console)/project-[project]/settings/deleteProject.svelte index 34ae0206c..4a130f4de 100644 --- a/src/routes/(console)/project-[project]/settings/deleteProject.svelte +++ b/src/routes/(console)/project-[project]/settings/deleteProject.svelte @@ -18,7 +18,7 @@ let regions: Models.ConsoleRegionList; onMount(async () => { if (isCloud) { - regions = await sdk.forConsole.billing.listRegions(); + regions = await sdk.forConsole.console.regions(); } });