mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
refactor: remove accounts, console, regions based hardcoded methods and its usages.
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
Generated
+5
-5
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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<Models.PaymentMethodList> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.PaymentMethod> {
|
||||
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<Models.BillingAddressList> {
|
||||
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<Models.BillingAddress> {
|
||||
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<Models.BillingAddress> {
|
||||
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<Models.BillingAddress> {
|
||||
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<void> {
|
||||
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<Models.ConsoleRegionList> {
|
||||
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<Models.BillingPlanList> {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +531,11 @@ export const paymentMissingMandate = writable<Models.PaymentMethod>(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',
|
||||
|
||||
+13
-12
@@ -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,
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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()
|
||||
]);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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;
|
||||
});
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
});
|
||||
|
||||
async function loadPaymentMethods() {
|
||||
paymentMethods = await sdk.forConsole.billing.listPaymentMethods();
|
||||
paymentMethods = await sdk.forConsole.account.listPaymentMethods();
|
||||
return paymentMethods;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user