Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/lib/components/billing/alerts/missingPaymentMethod.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { toLocaleDate } from '$lib/helpers/date';
import { HeaderAlert } from '$lib/layout';
import { orgMissingPaymentMethod } from '$routes/console/store';
</script>
Expand All @@ -12,9 +11,8 @@
type="error"
title={`Payment method required for ${$orgMissingPaymentMethod.name}`}>
<svelte:fragment>
Add a payment method to {$orgMissingPaymentMethod.name} before {toLocaleDate(
$orgMissingPaymentMethod.billingCurrentInvoiceDate
)} to avoid service interruptions to your projects.
Add a payment method to {$orgMissingPaymentMethod.name} to avoid service interruptions to
your projects.
</svelte:fragment>
<svelte:fragment slot="buttons">
<Button
Expand Down
18 changes: 17 additions & 1 deletion src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, Models, Query } from '@appwrite.io/console';
import type { Organization } from '../stores/organization';
import type { Organization, OrganizationList } from '../stores/organization';
import type { PaymentMethod } from '@stripe/stripe-js';
import type { Tier } from '$lib/stores/billing';

Expand Down Expand Up @@ -274,6 +274,22 @@ export class Billing {
this.client = client;
}

async listOrganization(queries: Query[] = []): Promise<OrganizationList> {
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 createOrganization(
organizationId: string,
name: string,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ export function checkForMarkedForDeletion(org: Organization) {
}

export async function checkForMissingPaymentMethod() {
const orgs = await sdk.forConsole.teams.list([
const orgs = await sdk.forConsole.billing.listOrganization([
Query.notEqual('billingPlan', BillingPlan.STARTER),
Query.isNull('paymentMethodId'),
Query.isNull('backupPaymentMethodId')
]);
if (orgs?.total) {
orgMissingPaymentMethod.set(orgs.teams[0] as Organization);
orgMissingPaymentMethod.set(orgs.teams[0]);
headerAlert.add({
id: 'missingPaymentMethod',
component: MissingPaymentMethod,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/stores/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export type Organization = Models.Team<Record<string, unknown>> & {
billingPlanDowngrade?: string;
};

export type OrganizationList = {
teams: Organization[];
total: number;
};

export type BillingLimits = {
bandwidth: number;
documents: number;
Expand Down