mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
refactor: remaining endpoints from billing.ts
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@
|
||||
"e2e:ui": "playwright test tests/e2e --ui"
|
||||
},
|
||||
"dependencies": {
|
||||
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea",
|
||||
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e",
|
||||
"@appwrite.io/pink": "0.25.0",
|
||||
"@appwrite.io/pink-icons": "0.25.0",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
|
||||
Generated
+5
-5
@@ -9,8 +9,8 @@ importers:
|
||||
.:
|
||||
dependencies:
|
||||
'@appwrite.io/console':
|
||||
specifier: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea
|
||||
version: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea
|
||||
specifier: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e
|
||||
version: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e
|
||||
'@appwrite.io/pink':
|
||||
specifier: 0.25.0
|
||||
version: 0.25.0
|
||||
@@ -199,8 +199,8 @@ packages:
|
||||
'@analytics/type-utils@0.6.2':
|
||||
resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==}
|
||||
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea}
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e}
|
||||
version: 1.5.2
|
||||
|
||||
'@appwrite.io/pink-icons@0.25.0':
|
||||
@@ -3887,7 +3887,7 @@ snapshots:
|
||||
|
||||
'@analytics/type-utils@0.6.2': {}
|
||||
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@88c29ea': {}
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6c1a98e': {}
|
||||
|
||||
'@appwrite.io/pink-icons@0.25.0': {}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
import { confirmSetup } from '$lib/stores/stripe';
|
||||
|
||||
async function verifyPaymentMethod() {
|
||||
const method = await sdk.forConsole.billing.setupPaymentMandate(
|
||||
$organization.$id,
|
||||
const method = await sdk.forConsole.account.updatePaymentMethodMandateOptions(
|
||||
$paymentMissingMandate.$id
|
||||
);
|
||||
await confirmSetup(method.clientSecret, method.$id);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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 } from '../stores/organization';
|
||||
|
||||
export type Estimation = {
|
||||
@@ -198,20 +197,6 @@ export class Billing {
|
||||
});
|
||||
}
|
||||
|
||||
async setMembership(
|
||||
programId: string
|
||||
): Promise<{ $createdAt: string } | { error: { code: number; message: string } }> {
|
||||
const path = `/console/programs/${programId}/memberships`;
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
try {
|
||||
return await this.client.call('POST', uri, {
|
||||
'content-type': 'application/json'
|
||||
});
|
||||
} catch (e) {
|
||||
return { error: { code: e.code, message: e.message } };
|
||||
}
|
||||
}
|
||||
|
||||
async setBillingAddress(
|
||||
organizationId: string,
|
||||
billingAddressId: string
|
||||
@@ -249,48 +234,6 @@ export class Billing {
|
||||
);
|
||||
}
|
||||
|
||||
async getOrganizationPaymentMethod(
|
||||
organizationId: string,
|
||||
paymentMethodId: string
|
||||
): Promise<Models.PaymentMethod> {
|
||||
const path = `/organizations/${organizationId}/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setPaymentMethod(
|
||||
paymentMethodId: string,
|
||||
providerMethodId: string | PaymentMethod,
|
||||
name: string
|
||||
): Promise<Models.PaymentMethod> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}/provider`;
|
||||
const params = {
|
||||
paymentMethodId,
|
||||
providerMethodId,
|
||||
name
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setDefaultPaymentMethod(paymentMethodId: string): Promise<Models.PaymentMethod> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}/default`;
|
||||
const params = {
|
||||
@@ -306,24 +249,4 @@ export class Billing {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ export async function checkPaymentAuthorizationRequired(org: Organization) {
|
||||
|
||||
export async function paymentExpired(org: Organization) {
|
||||
if (!org?.paymentMethodId) return;
|
||||
const payment = await sdk.forConsole.billing.getOrganizationPaymentMethod(
|
||||
const payment = await sdk.forConsole.organizations.getPaymentMethod(
|
||||
org.$id,
|
||||
org.paymentMethodId
|
||||
);
|
||||
|
||||
@@ -93,9 +93,9 @@ export async function submitStripeCard(name: string, organizationId?: string) {
|
||||
}
|
||||
|
||||
if (setupIntent && setupIntent.status === 'succeeded') {
|
||||
const method = await sdk.forConsole.billing.setPaymentMethod(
|
||||
const method = await sdk.forConsole.account.updatePaymentMethodProvider(
|
||||
paymentMethod.$id,
|
||||
setupIntent.payment_method,
|
||||
setupIntent.payment_method as string,
|
||||
name
|
||||
);
|
||||
paymentElement.destroy();
|
||||
|
||||
@@ -77,14 +77,14 @@
|
||||
}
|
||||
|
||||
$: if ($organization?.backupPaymentMethodId) {
|
||||
sdk.forConsole.billing
|
||||
.getOrganizationPaymentMethod($organization.$id, $organization.backupPaymentMethodId)
|
||||
sdk.forConsole.organizations
|
||||
.getPaymentMethod($organization.$id, $organization.backupPaymentMethodId)
|
||||
.then((res) => (backupPaymentMethod = res));
|
||||
}
|
||||
|
||||
$: if ($organization?.paymentMethodId) {
|
||||
sdk.forConsole.billing
|
||||
.getOrganizationPaymentMethod($organization.$id, $organization.paymentMethodId)
|
||||
sdk.forConsole.organizations
|
||||
.getPaymentMethod($organization.$id, $organization.paymentMethodId)
|
||||
.then((res) => (defaultPaymentMethod = res));
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -1,20 +1,19 @@
|
||||
import { base } from '$app/paths';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { VARS } from '$lib/system';
|
||||
import type { AppwriteException } from '@appwrite.io/console';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
const handleGithubEducationMembership = async (name: string, email: string) => {
|
||||
const result = await sdk.forConsole.billing.setMembership('github-student-developer');
|
||||
const result = await sdk.forConsole.console.createProgramMembership('github-student-developer');
|
||||
if (result && 'error' in result) {
|
||||
if (result.error.code === 409) {
|
||||
const error = result.error as AppwriteException;
|
||||
if (error.code === 409) {
|
||||
redirect(303, `${base}/account/organizations`);
|
||||
} else {
|
||||
await sdk.forConsole.account.deleteSession('current');
|
||||
redirect(
|
||||
303,
|
||||
`${base}/education/error?message=${result.error.message}&code=${result.error.code}`
|
||||
);
|
||||
redirect(303, `${base}/education/error?message=${error.message}&code=${error.code}`);
|
||||
}
|
||||
} else if (result && '$createdAt' in result) {
|
||||
setToGhStudentMailingList(name, email);
|
||||
|
||||
Reference in New Issue
Block a user