From b3e040bec8be4759dc4561c20949fd2a32f0806b Mon Sep 17 00:00:00 2001 From: Darshan Date: Fri, 19 Dec 2025 15:33:25 +0530 Subject: [PATCH] refactor: remove `accounts`, `console`, `regions` based hardcoded methods and its usages. --- package.json | 2 +- pnpm-lock.yaml | 10 +- .../billing/alerts/paymentMandate.svelte | 7 +- src/lib/sdk/billing.ts | 283 ------------------ src/lib/stores/billing.ts | 6 +- src/lib/stores/stripe.ts | 25 +- src/routes/(console)/+layout.ts | 8 +- .../(console)/account/payments/+page.ts | 4 +- .../account/payments/addressModal.svelte | 10 +- .../payments/deleteAddressModal.svelte | 5 +- .../payments/deletePaymentModal.svelte | 4 +- .../account/payments/editAddressModal.svelte | 20 +- .../account/payments/editPaymentModal.svelte | 15 +- .../(console)/apply-credit/+page.svelte | 2 +- .../(console)/create-organization/+page.ts | 2 +- .../billing/+page.ts | 4 +- .../billing/replaceAddress.svelte | 10 +- .../billing/retryPaymentModal.svelte | 16 +- .../billing/wizard/paymentDetails.svelte | 2 +- .../change-plan/+page.svelte | 2 +- src/routes/(console)/regions.ts | 7 +- 21 files changed, 95 insertions(+), 349 deletions(-) diff --git a/package.json b/package.json index a82b6d54d..50b4029dc 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@ai-sdk/svelte": "^1.1.24", - "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d", + "@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9", "@appwrite.io/pink-icons": "0.25.0", "@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@865e2fc", "@appwrite.io/pink-legacy": "^1.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 241ef357a..ce01083e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^1.1.24 version: 1.1.24(svelte@5.25.3)(zod@3.24.3) '@appwrite.io/console': - specifier: https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d - version: https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d + specifier: https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9 + version: https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9 '@appwrite.io/pink-icons': specifier: 0.25.0 version: 0.25.0 @@ -272,8 +272,8 @@ packages: '@analytics/type-utils@0.6.2': resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==} - '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d': - resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d} + '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9': + resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9} version: 1.10.0 '@appwrite.io/pink-icons-svelte@2.0.0-RC.1': @@ -3823,7 +3823,7 @@ snapshots: '@analytics/type-utils@0.6.2': {} - '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@18b170d': {} + '@appwrite.io/console@https://pkg.vc/-/@appwrite/@appwrite.io/console@7a147b9': {} '@appwrite.io/pink-icons-svelte@2.0.0-RC.1(svelte@5.25.3)': dependencies: diff --git a/src/lib/components/billing/alerts/paymentMandate.svelte b/src/lib/components/billing/alerts/paymentMandate.svelte index 08d9207d7..0126f2f9a 100644 --- a/src/lib/components/billing/alerts/paymentMandate.svelte +++ b/src/lib/components/billing/alerts/paymentMandate.svelte @@ -8,10 +8,9 @@ import { confirmSetup } from '$lib/stores/stripe'; async function verifyPaymentMethod() { - const method = await sdk.forConsole.billing.setupPaymentMandate( - $organization.$id, - $paymentMissingMandate.$id - ); + const method = await sdk.forConsole.account.updatePaymentMethodMandateOptions({ + paymentMethodId: $paymentMissingMandate.$id + }); await confirmSetup(method.clientSecret, method.providerMethodId); } diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 69c69f12f..aa2422bc9 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,6 +1,5 @@ import type { Client, Models } from '@appwrite.io/console'; import type { OrganizationError } from '../stores/organization'; -import type { PaymentMethod as StripePaymentMethod } from '@stripe/stripe-js'; export type AllowedRegions = | 'fra' @@ -99,286 +98,4 @@ export class Billing { 'content-type': 'application/json' }); } - - //ACCOUNT - - async listPaymentMethods(queries: [] = []): Promise { - const path = `/account/payment-methods`; - 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 getPaymentMethod(paymentMethodId: string): Promise { - const path = `/account/payment-methods/${paymentMethodId}`; - const params = { - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async createPaymentMethod(): Promise { - const path = `/account/payment-methods`; - const params = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'POST', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async setPaymentMethod( - paymentMethodId: string, - providerMethodId: string | StripePaymentMethod, - name: string, - state: string | undefined = undefined - ): Promise { - const path = `/account/payment-methods/${paymentMethodId}/provider`; - const params = { - paymentMethodId, - providerMethodId, - name - }; - - if (state !== undefined) { - params['state'] = state; - } - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async updatePaymentMethod( - paymentMethodId: string, - expiryMonth: string, - expiryYear: string - ): Promise { - const path = `/account/payment-methods/${paymentMethodId}`; - const params = { - paymentMethodId, - expiryMonth, - expiryYear - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async deletePaymentMethod(paymentMethodId: string): Promise { - const path = `/account/payment-methods/${paymentMethodId}`; - const params = { - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'delete', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async setDefaultPaymentMethod(paymentMethodId: string): Promise { - const path = `/account/payment-methods/${paymentMethodId}/default`; - const params = { - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async setupPaymentMandate( - organizationId: string, - paymentMethodId: string - ): Promise { - const path = `/account/payment-methods/${paymentMethodId}/setup`; - const params = { - organizationId, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - 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(teamId: string): Promise { - const path = `/console/regions`; - const params = { - teamId - }; - 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 = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } } diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index e3f373699..06c4d13fd 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -531,7 +531,11 @@ export const paymentMissingMandate = writable(null); export async function checkForMandate(org: Models.Organization) { const paymentId = org.paymentMethodId ?? org.backupPaymentMethodId; if (!paymentId) return; - const paymentMethod = await sdk.forConsole.billing.getPaymentMethod(paymentId); + + const paymentMethod = await sdk.forConsole.account.getPaymentMethod({ + paymentMethodId: paymentId + }); + if (paymentMethod?.mandateId === null && paymentMethod?.country.toLowerCase() === 'in') { headerAlert.add({ id: 'paymentMandate', diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index cda0bf776..11797553b 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -32,7 +32,7 @@ export async function initializeStripe(node: HTMLElement) { isStripeInitialized.set(true); - const methods = await sdk.forConsole.billing.listPaymentMethods(); + const methods = await sdk.forConsole.account.listPaymentMethods(); // Get the client secret from empty payment method if available clientSecret = methods.paymentMethods?.filter( @@ -41,7 +41,7 @@ export async function initializeStripe(node: HTMLElement) { // If there is no payment method, create an empty one and get the client secret if (!clientSecret) { - paymentMethod = await sdk.forConsole.billing.createPaymentMethod(); + paymentMethod = await sdk.forConsole.account.createPaymentMethod(); clientSecret = paymentMethod.clientSecret; } @@ -78,7 +78,7 @@ export async function submitStripeCard(name: string, organizationId?: string) { try { // If a payment method was created during initialization, use it, otherwise create a new one if (!paymentMethod) { - paymentMethod = await sdk.forConsole.billing.createPaymentMethod(); + paymentMethod = await sdk.forConsole.account.createPaymentMethod(); clientSecret = paymentMethod.clientSecret; } @@ -139,11 +139,12 @@ export async function submitStripeCard(name: string, organizationId?: string) { throw e; } - const method = await sdk.forConsole.billing.setPaymentMethod( - paymentMethod.$id, - providerId, + const method = await sdk.forConsole.account.updatePaymentMethodProvider({ + paymentMethodId: paymentMethod.$id, + providerMethodId: providerId, name - ); + }); + paymentElement.destroy(); isStripeInitialized.set(false); trackEvent(Submit.PaymentMethodCreate); @@ -169,12 +170,12 @@ export async function setPaymentMethod(providerMethodId: string, name: string, s return; } try { - const method = await sdk.forConsole.billing.setPaymentMethod( - paymentMethod.$id, - providerMethodId, + const method = await sdk.forConsole.account.updatePaymentMethodProvider({ + paymentMethodId: paymentMethod.$id, + providerMethodId: providerMethodId, name, state - ); + }); paymentElement.destroy(); isStripeInitialized.set(false); trackEvent(Submit.PaymentMethodCreate); @@ -195,7 +196,7 @@ export async function confirmPayment( const url = window.location.origin + (route ? route : `${base}/organization-${orgId}/billing`); - const paymentMethod = await sdk.forConsole.billing.getPaymentMethod(paymentMethodId); + const paymentMethod = await sdk.forConsole.account.getPaymentMethod({ paymentMethodId }); const { error } = await get(stripe).confirmPayment({ clientSecret: clientSecret, diff --git a/src/routes/(console)/+layout.ts b/src/routes/(console)/+layout.ts index 5ce52a00c..a17602f25 100644 --- a/src/routes/(console)/+layout.ts +++ b/src/routes/(console)/+layout.ts @@ -2,7 +2,7 @@ import { sdk } from '$lib/stores/sdk'; import { isCloud } from '$lib/system'; import type { LayoutLoad } from './$types'; import { Dependencies } from '$lib/constants'; -import { type Models, Query } from '@appwrite.io/console'; +import { type Models, Platform, Query } from '@appwrite.io/console'; export const load: LayoutLoad = async ({ depends, parent }) => { const { organizations } = await parent(); @@ -14,7 +14,11 @@ export const load: LayoutLoad = async ({ depends, parent }) => { const { endpoint, project } = sdk.forConsole.client.config; const [preferences, plansArray, versionData, consoleVariables] = await Promise.all([ sdk.forConsole.account.getPrefs(), - isCloud ? sdk.forConsole.billing.getPlansInfo() : null, + isCloud + ? sdk.forConsole.console.getPlans({ + platform: Platform.Appwrite + }) + : null, fetch(`${endpoint}/health/version`, { headers: { 'X-Appwrite-Project': project } }).then((response) => response.json() as { version?: string }), diff --git a/src/routes/(console)/account/payments/+page.ts b/src/routes/(console)/account/payments/+page.ts index b275a6e9b..fb0cb2d96 100644 --- a/src/routes/(console)/account/payments/+page.ts +++ b/src/routes/(console)/account/payments/+page.ts @@ -7,8 +7,8 @@ export const load: PageLoad = async ({ depends }) => { depends(Dependencies.ADDRESS); const [paymentMethods, addressList, countryList, locale] = await Promise.all([ - sdk.forConsole.billing.listPaymentMethods(), - sdk.forConsole.billing.listAddresses(), + sdk.forConsole.account.listPaymentMethods(), + sdk.forConsole.account.listBillingAddresses(), sdk.forConsole.locale.listCountries(), sdk.forConsole.locale.get() ]); diff --git a/src/routes/(console)/account/payments/addressModal.svelte b/src/routes/(console)/account/payments/addressModal.svelte index eea85847c..57ea22c10 100644 --- a/src/routes/(console)/account/payments/addressModal.svelte +++ b/src/routes/(console)/account/payments/addressModal.svelte @@ -42,14 +42,14 @@ async function handleSubmit() { try { - const response = await sdk.forConsole.billing.createAddress( + const response = await sdk.forConsole.account.createBillingAddress({ country, - address, + streetAddress: address, city, state, - zip ? zip : undefined, - address2 ? address2 : undefined - ); + postalCode: zip ? zip : undefined, + addressLine2: address2 ? address2 : undefined + }); trackEvent(Submit.BillingAddressCreate); let org: Models.Organization = null; diff --git a/src/routes/(console)/account/payments/deleteAddressModal.svelte b/src/routes/(console)/account/payments/deleteAddressModal.svelte index e90c24060..9f267daab 100644 --- a/src/routes/(console)/account/payments/deleteAddressModal.svelte +++ b/src/routes/(console)/account/payments/deleteAddressModal.svelte @@ -17,7 +17,10 @@ async function handleDelete() { try { - await sdk.forConsole.billing.deleteAddress(selectedAddress.$id); + await sdk.forConsole.account.deleteBillingAddress({ + billingAddressId: selectedAddress.$id + }); + await invalidate(Dependencies.PAYMENT_METHODS); showDelete = false; addNotification({ diff --git a/src/routes/(console)/account/payments/deletePaymentModal.svelte b/src/routes/(console)/account/payments/deletePaymentModal.svelte index d5e8e01f2..613db9161 100644 --- a/src/routes/(console)/account/payments/deletePaymentModal.svelte +++ b/src/routes/(console)/account/payments/deletePaymentModal.svelte @@ -17,7 +17,9 @@ async function handleDelete() { try { - await sdk.forConsole.billing.deletePaymentMethod(method); + await sdk.forConsole.account.deletePaymentMethod({ + paymentMethodId: method + }); await invalidate(Dependencies.PAYMENT_METHODS); showDelete = false; addNotification({ diff --git a/src/routes/(console)/account/payments/editAddressModal.svelte b/src/routes/(console)/account/payments/editAddressModal.svelte index 1a12a54d6..c77d0224a 100644 --- a/src/routes/(console)/account/payments/editAddressModal.svelte +++ b/src/routes/(console)/account/payments/editAddressModal.svelte @@ -33,15 +33,17 @@ async function handleSubmit() { try { - await sdk.forConsole.billing.updateAddress( - selectedAddress.$id, - selectedAddress.country, - selectedAddress.streetAddress, - selectedAddress.city, - selectedAddress.state, - selectedAddress.postalCode ? selectedAddress.postalCode : undefined, - selectedAddress.addressLine2 ? selectedAddress.addressLine2 : undefined - ); + await sdk.forConsole.account.updateBillingAddress({ + billingAddressId: selectedAddress.$id, + country: selectedAddress.country, + streetAddress: selectedAddress.streetAddress, + city: selectedAddress.city, + state: selectedAddress.state, + postalCode: selectedAddress.postalCode ? selectedAddress.postalCode : undefined, + addressLine2: selectedAddress.addressLine2 + ? selectedAddress.addressLine2 + : undefined + }); await invalidate(Dependencies.ADDRESS); show = false; addNotification({ diff --git a/src/routes/(console)/account/payments/editPaymentModal.svelte b/src/routes/(console)/account/payments/editPaymentModal.svelte index 5b1145f68..fd63c1e1d 100644 --- a/src/routes/(console)/account/payments/editPaymentModal.svelte +++ b/src/routes/(console)/account/payments/editPaymentModal.svelte @@ -10,20 +10,23 @@ import type { Models } from '@appwrite.io/console'; export let show = false; - export let selectedPaymentMethod: Models.PaymentMethod; export let isLinked = false; + export let selectedPaymentMethod: Models.PaymentMethod; + const currentYear = new Date().getFullYear(); + let error: string; let month: string; let year: number; async function handleSubmit() { try { - await sdk.forConsole.billing.updatePaymentMethod( - selectedPaymentMethod.$id, - month, - year?.toString() - ); + await sdk.forConsole.account.updatePaymentMethod({ + paymentMethodId: selectedPaymentMethod.$id, + expiryMonth: parseInt(month), + expiryYear: year + }); + trackEvent(Submit.PaymentMethodUpdate); invalidate(Dependencies.PAYMENT_METHODS); show = false; diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index a21b28447..a033dbc44 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -113,7 +113,7 @@ }); async function loadPaymentMethods() { - const methodList = await sdk.forConsole.billing.listPaymentMethods(); + const methodList = await sdk.forConsole.account.listPaymentMethods(); const filteredMethods = methodList.paymentMethods.filter((method) => !!method?.last4); methods = { paymentMethods: filteredMethods, total: filteredMethods.length }; paymentMethodId = diff --git a/src/routes/(console)/create-organization/+page.ts b/src/routes/(console)/create-organization/+page.ts index cef662708..2f780b285 100644 --- a/src/routes/(console)/create-organization/+page.ts +++ b/src/routes/(console)/create-organization/+page.ts @@ -8,7 +8,7 @@ export const load: PageLoad = async ({ url, parent, depends }) => { depends(Dependencies.ORGANIZATIONS); const [coupon, paymentMethods, plans] = await Promise.all([ getCoupon(url), - sdk.forConsole.billing.listPaymentMethods(), + sdk.forConsole.account.listPaymentMethods(), sdk.forConsole.console.getPlans({ platform: Platform.Appwrite }) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index d343e4076..bbc531fe1 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -76,8 +76,8 @@ export const load: PageLoad = async ({ parent, depends, url, route }) => { const [paymentMethods, addressList, billingAddress, availableCredit, billingPlanDowngrade] = await Promise.all([ - sdk.forConsole.billing.listPaymentMethods(), - sdk.forConsole.billing.listAddresses(), + sdk.forConsole.account.listPaymentMethods(), + sdk.forConsole.account.listBillingAddresses(), billingAddressPromise, areCreditsSupported ? sdk.forConsole.organizations.getAvailableCredits({ diff --git a/src/routes/(console)/organization-[organization]/billing/replaceAddress.svelte b/src/routes/(console)/organization-[organization]/billing/replaceAddress.svelte index 470f2dbdf..9fd9c7ff6 100644 --- a/src/routes/(console)/organization-[organization]/billing/replaceAddress.svelte +++ b/src/routes/(console)/organization-[organization]/billing/replaceAddress.svelte @@ -35,7 +35,7 @@ onMount(async () => { loading = true; - addresses = await sdk.forConsole.billing.listAddresses(); + addresses = await sdk.forConsole.account.listBillingAddresses(); const firstNonCurrentAddress = addresses?.billingAddresses?.find( (address) => address.$id !== $organization?.billingAddressId @@ -63,14 +63,14 @@ if (selectedAddress === $organization.billingAddressId) { show = false; } else if (selectedAddress === '$new') { - const address = await sdk.forConsole.billing.createAddress( + const address = await sdk.forConsole.account.createBillingAddress({ country, streetAddress, city, state, - postalCode ? postalCode : undefined, - addressLine2 ? postalCode : undefined - ); + postalCode: postalCode ? postalCode : undefined, + addressLine2: addressLine2 ? postalCode : undefined + }); await sdk.forConsole.organizations.setBillingAddress({ organizationId: $organization.$id, diff --git a/src/routes/(console)/organization-[organization]/billing/retryPaymentModal.svelte b/src/routes/(console)/organization-[organization]/billing/retryPaymentModal.svelte index a13e7c31c..13cbf9fd0 100644 --- a/src/routes/(console)/organization-[organization]/billing/retryPaymentModal.svelte +++ b/src/routes/(console)/organization-[organization]/billing/retryPaymentModal.svelte @@ -81,7 +81,11 @@ method = card as Models.PaymentMethod; } } - const card = await sdk.forConsole.billing.getPaymentMethod(method.$id); + + const card = await sdk.forConsole.account.getPaymentMethod({ + paymentMethodId: method.$id + }); + if (card?.last4) { paymentMethodId = card.$id; } else { @@ -89,15 +93,21 @@ 'The payment method you selected is not valid. Please select a different one.' ); } - invalidate(Dependencies.PAYMENT_METHODS); + + await invalidate(Dependencies.PAYMENT_METHODS); } catch (e) { paymentMethodId = $organization.paymentMethodId; error = e.message; } } + if (setAsDefault) { - await sdk.forConsole.billing.setDefaultPaymentMethod(paymentMethodId); + await sdk.forConsole.organizations.setDefaultPaymentMethod({ + organizationId: $organization.$id, + paymentMethodId + }); } + const { clientSecret, status } = await sdk.forConsole.organizations.createInvoicePayment({ organizationId: $organization.$id, diff --git a/src/routes/(console)/organization-[organization]/billing/wizard/paymentDetails.svelte b/src/routes/(console)/organization-[organization]/billing/wizard/paymentDetails.svelte index 7ee8a49b6..b81384e00 100644 --- a/src/routes/(console)/organization-[organization]/billing/wizard/paymentDetails.svelte +++ b/src/routes/(console)/organization-[organization]/billing/wizard/paymentDetails.svelte @@ -18,7 +18,7 @@ let paymentMethod: StripePaymentMethod | null = null; onMount(async () => { - methods = await sdk.forConsole.billing.listPaymentMethods(); + methods = await sdk.forConsole.account.listPaymentMethods(); $addCreditWizardStore.paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null; }); diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index af6a48b78..6e70d3f83 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -118,7 +118,7 @@ }); async function loadPaymentMethods() { - paymentMethods = await sdk.forConsole.billing.listPaymentMethods(); + paymentMethods = await sdk.forConsole.account.listPaymentMethods(); return paymentMethods; } diff --git a/src/routes/(console)/regions.ts b/src/routes/(console)/regions.ts index 32dbd0308..404ee9209 100644 --- a/src/routes/(console)/regions.ts +++ b/src/routes/(console)/regions.ts @@ -21,10 +21,11 @@ export async function loadAvailableRegions(orgId: string, force: boolean = false return; } - // TODO: @itznotabug, @torstendittmann we need a better way for this! - const availableRegions = await sdk.forConsole.billing.listRegions(orgId); - regions.set(availableRegions); + const availableRegions = await sdk.forConsole.console.getRegions({ + organizationId: orgId + }); + regions.set(availableRegions); lastLoadedOrganization = orgId; } catch (error) { console.error(`Failed to load regions for teamId: ${orgId}`, error);