mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
authorize payment
This commit is contained in:
1 parent
c67fea4982
commit
708517a0d0
6 files changed
+32
-8
No files matched your search
@@ -3,7 +3,7 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import type { Searcher } from '../commands';
|
||||
|
||||
export const orgSearcher = (async (query: string) => {
|
||||
const { teams } = await sdk.forConsole.teams.list();
|
||||
const { teams } = await sdk.forConsole.billing.listOrganization();
|
||||
return teams
|
||||
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))
|
||||
.map((organization) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Client, Models } from '@appwrite.io/console';
|
||||
import type { Organization, OrganizationList } from '../stores/organization';
|
||||
import type { CreateOrgAuth, Organization, OrganizationList } from '../stores/organization';
|
||||
import type { PaymentMethod } from '@stripe/stripe-js';
|
||||
import type { Tier } from '$lib/stores/billing';
|
||||
|
||||
@@ -310,7 +310,7 @@ export class Billing {
|
||||
billingAddressId: string = undefined,
|
||||
couponId: string = undefined,
|
||||
invites: Array<string> = []
|
||||
): Promise<Organization> {
|
||||
): Promise<Organization | CreateOrgAuth> {
|
||||
const path = `/organizations`;
|
||||
const params = {
|
||||
organizationId,
|
||||
|
||||
@@ -3,6 +3,15 @@ import { derived, writable } from 'svelte/store';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import type { Tier } from './billing';
|
||||
|
||||
export type CreateOrgAuth = {
|
||||
status: number;
|
||||
message: string;
|
||||
teamId: string;
|
||||
invoiceId: string;
|
||||
clientSecret: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type Organization = Models.Team<Record<string, unknown>> & {
|
||||
billingBudget: number;
|
||||
billingPlan: Tier;
|
||||
|
||||
@@ -22,7 +22,7 @@ export const load: LayoutLoad = async ({ depends, url }) => {
|
||||
|
||||
return {
|
||||
account,
|
||||
organizations: await sdk.forConsole.teams.list()
|
||||
organizations: await sdk.forConsole.billing.listOrganization()
|
||||
};
|
||||
} catch (error) {
|
||||
const acceptedRoutes = [
|
||||
|
||||
@@ -12,7 +12,7 @@ export const load: PageLoad = async ({ url, route }) => {
|
||||
return {
|
||||
offset,
|
||||
limit,
|
||||
organizations: await sdk.forConsole.teams.list([
|
||||
organizations: await sdk.forConsole.billing.listOrganization([
|
||||
Query.offset(offset),
|
||||
Query.limit(limit),
|
||||
Query.orderDesc('')
|
||||
|
||||
@@ -22,8 +22,13 @@
|
||||
import type { Coupon, PaymentList } from '$lib/sdk/billing';
|
||||
import { plansInfo, tierFree, tierPro, tierToPlan } from '$lib/stores/billing';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { organizationList, type Organization } from '$lib/stores/organization';
|
||||
import {
|
||||
organizationList,
|
||||
type CreateOrgAuth,
|
||||
type Organization
|
||||
} from '$lib/stores/organization';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { confirmPayment } from '$lib/stores/stripe';
|
||||
import { ID } from '@appwrite.io/console';
|
||||
import { onMount } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
@@ -90,9 +95,13 @@
|
||||
paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null;
|
||||
}
|
||||
|
||||
function isOrganization(org: Organization | CreateOrgAuth): org is Organization {
|
||||
return (org as Organization).$id !== undefined;
|
||||
}
|
||||
|
||||
async function create() {
|
||||
try {
|
||||
let org: Organization;
|
||||
let org: Organization | CreateOrgAuth;
|
||||
|
||||
if (billingPlan === BillingPlan.FREE) {
|
||||
org = await sdk.forConsole.billing.createOrganization(
|
||||
@@ -113,8 +122,14 @@
|
||||
collaborators
|
||||
);
|
||||
|
||||
if (!isOrganization(org) && org.status == 402) {
|
||||
let clientSecret = org.clientSecret;
|
||||
await confirmPayment('', clientSecret, paymentMethodId);
|
||||
// throw new Error('Payment requires authentication');
|
||||
}
|
||||
|
||||
//Add budget
|
||||
if (billingBudget) {
|
||||
if (billingBudget && isOrganization(org)) {
|
||||
await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user