diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 60d86ce19..70e47ec37 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -218,5 +218,7 @@ export enum Submit { PaymentMethodDeleted = 'submit_payment_method_deleted', BillingAddressDeleted = 'submit_billing_address_deleted', BillingAddressCreated = 'submit_billing_address_created', - BillingAddressUpdated = 'submit_billing_address_updated' + BillingAddressUpdated = 'submit_billing_address_updated', + OrganizationPaymentAdded = 'submit_organization_payment_added', + OrganizationBackupPaymentAdded = 'submit_organization_backup_payment_added' } diff --git a/src/lib/components/box.svelte b/src/lib/components/box.svelte index c16d116ea..0d9b51ca6 100644 --- a/src/lib/components/box.svelte +++ b/src/lib/components/box.svelte @@ -5,5 +5,8 @@ + {#if $$slots?.end} +
+ {/if} diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 1db317072..7aeae0472 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -3,6 +3,7 @@ export const CARD_LIMIT = 6; // default card limit export const INTERVAL = 5 * 60000; // default interval to check for feedback export enum Dependencies { + ORG_PAYMENT_METHODS = 'dependency:orgPaymentMethods', PAYMENT_METHODS = 'dependency:paymentMethods', ORGANIZATION = 'dependency:organization', PROJECT = 'dependency:project', @@ -257,7 +258,7 @@ export const eventServices: Array = [ ]; export const usageRates = { - free: [ + 'tier-0': [ { resource: 'Organization members', limit: '1', rate: 'lorem' }, { resource: 'Bandwidth', limit: '1', rate: 'lorem' }, { resource: 'Storage', limit: '1', rate: 'lorem' }, @@ -265,7 +266,7 @@ export const usageRates = { { resource: 'Active users', limit: '1', rate: 'lorem' }, { resource: 'Concurrent connections', limit: '1', rate: 'lorem' } ], - starter: [ + 'tier-1': [ { resource: 'Organization members', limit: '1', rate: 'lorem' }, { resource: 'Bandwidth', limit: '1', rate: 'lorem' }, { resource: 'Storage', limit: '1', rate: 'lorem' }, @@ -273,7 +274,7 @@ export const usageRates = { { resource: 'Active users', limit: '1', rate: 'lorem' }, { resource: 'Concurrent connections', limit: '1', rate: 'lorem' } ], - pro: [ + 'tier-2': [ { resource: 'Organization members', limit: 'Unlimited', rate: '20$/member' }, { resource: 'Bandwidth', limit: '1TB', rate: '$0.04/GB' }, { resource: 'Storage', limit: '150GB', rate: '$0.025/GB' }, diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts new file mode 100644 index 000000000..e500b630b --- /dev/null +++ b/src/lib/sdk/billing.ts @@ -0,0 +1,431 @@ +import type { Client } from '@appwrite.io/console'; +import type { Organization } from '../stores/organization'; + +export type PaymentMethodData = { + $id: string; + providerMethodId: string; + expiryMonth: number; + expiryYear: number; + last4: string; + country: string; + brand: string; + clientSecret?: string; +}; + +export type PaymentList = { + paymentMethods: PaymentMethodData[]; + total: number; +}; + +export type Invoice = { + $id: string; + amount: number; + currency: string; + date: number; + status: string; + paymentMethod: PaymentMethodData; +}; + +export type InvoiceList = { + invoices: Invoice[]; + total: number; +}; +export class Billing { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + async createOrganization( + organizationId: string, + name: string, + billingPlan: string, + paymentMethodId: string + ): Promise { + const path = `/organizations`; + const params = { + organizationId, + name, + billingPlan, + paymentMethodId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'POST', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async getPlan(organizationId: string): Promise { + const path = `/organizations/${organizationId}/plan`; + const params = { + organizationId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async updatePlan( + organizationId: string, + billingPlan: string, + paymentMethodId: string + ): Promise { + const path = `/organizations/${organizationId}/plan`; + const params = { + organizationId, + billingPlan, + paymentMethodId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async updateBudget(organizationId: string, budget: number, alert: number[]): Promise { + const path = `/organizations/${organizationId}/budget`; + const params = { + organizationId, + budget, + alert + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async setOrganizationPaymentMethod(organizationId: string, paymentMethodId: string) { + const path = `/organizations/${organizationId}/payment-method`; + 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 setOrganizationPaymentMethodBackup(organizationId: string, paymentMethodId: string) { + const path = `/organizations/${organizationId}/payment-method/backup`; + 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 listInvoices( + organizationId: string, + queries: string[] = [], + search = '' + ): Promise { + const path = `/organizations/${organizationId}/invoices`; + const params = { + organizationId, + queries, + search + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async getInvoice(organizationId: string, invoiceId: string): Promise { + const path = `/organizations/${organizationId}/invoices/${invoiceId}`; + const params = { + organizationId, + invoiceId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async getInvoiceView(organizationId: string, invoiceId: string): Promise { + const path = `/organizations/${organizationId}/invoices/${invoiceId}/view`; + const params = { + organizationId, + invoiceId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async downloadInvoice(organizationId: string, invoiceId: string): Promise { + const path = `/organizations/${organizationId}/invoices/${invoiceId}/download`; + const params = { + organizationId, + invoiceId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async listUsage( + organizationId: string, + queries: string[] = [] + ): Promise> { + const path = `/organizations/${organizationId}/aggregations`; + const params = { + organizationId, + queries + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async getUsage( + organizationId: string, + aggregationId: string + ): Promise> { + const path = `/organizations/${organizationId}/aggregations/${aggregationId}`; + const params = { + organizationId, + aggregationId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + //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 updatePaymentMethod( + paymentMethodId: string, + providerMethodId: string + ): Promise { + const path = `/account/payment-methods/${paymentMethodId}`; + const params = { + paymentMethodId, + providerMethodId + }; + 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 addCredit(organizationId: string, couponId: string): Promise { + const path = `/organizations/${organizationId}/credits`; + const params = { + couponId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'POST', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async listCredits(organizationId: string, queries = []): Promise { + const path = `/organizations/${organizationId}/credits`; + 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 getCredit(organizationId: string, creditId: string): Promise { + const path = `/organizations/${organizationId}/credits/${creditId}`; + const params = { + creditId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'GET', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + // async listPaymentMethods(teamId: string) { + // const path = `/teams/${teamId}/payment-methods`; + // const uri = new URL(this.client.config.endpoint + path); + // return await this.client.call('GET', uri); + // } + + // async createPaymentMethod(teamId: string): Promise { + // const path = `/teams/${teamId}/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 + // ); + // } +} diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index abca418c4..c0852c638 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -1,434 +1,7 @@ -import type { Client } from '@appwrite.io/console'; -import type { Organization } from './organization'; +import { page } from '$app/stores'; +import { derived } from 'svelte/store'; -export type PaymentMethodData = { - $id: string; - providerMethodId: string; - expiryMonth: number; - expiryYear: number; - last4: string; - country: string; - brand: string; - clientSecret?: string; -}; - -export type PaymentList = { - paymentMethods: PaymentMethodData[]; - total: number; -}; - -export type Invoice = { - $id: string; - amount: number; - currency: string; - date: number; - status: string; - paymentMethod: PaymentMethodData; -}; - -export type InvoiceList = { - invoices: Invoice[]; - total: number; -}; -export class Billing { - client: Client; - - constructor(client: Client) { - this.client = client; - } - - async createOrganization( - organizationId: string, - name: string, - billingPlan: string, - paymentMethodId: string - ): Promise { - const path = `/organization`; - const params = { - organizationId, - name, - billingPlan, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'POST', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getPlan(organizationId: string): Promise { - const path = `/organizations/${organizationId}/plan`; - const params = { - organizationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async updatePlan( - organizationId: string, - billingPlan: string, - paymentMethodId: string - ): Promise { - const path = `/organizations/${organizationId}/plan`; - const params = { - organizationId, - billingPlan, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async updateBudget(organizationId: string, budget: number, alert: number[]): Promise { - const path = `/organizations/${organizationId}/budget`; - const params = { - organizationId, - budget, - alert - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async setOrganizationPaymentMethod(organizationId: string, paymentMethodId: string) { - const path = `/organizations/${organizationId}/payment-method`; - 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 setOrganizationPaymentMethodBackup(organizationId: string, paymentMethodId: string) { - const path = `/organizations/${organizationId}/payment-method/backup`; - 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 listInvoices( - organizationId: string, - queries: string[] = [], - search = '' - ): Promise { - const path = `/organizations/${organizationId}/invoices`; - const params = { - organizationId, - queries, - search - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getInvoice(organizationId: string, invoiceId: string): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}`; - const params = { - organizationId, - invoiceId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getInvoiceView(organizationId: string, invoiceId: string): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}/view`; - const params = { - organizationId, - invoiceId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async downloadInvoice(organizationId: string, invoiceId: string): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}/download`; - const params = { - organizationId, - invoiceId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async listUsage( - organizationId: string, - queries: string[] = [] - ): Promise> { - const path = `/organizations/${organizationId}/aggregations`; - const params = { - organizationId, - queries - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getUsage( - organizationId: string, - aggregationId: string - ): Promise> { - const path = `/organizations/${organizationId}/aggregations/${aggregationId}`; - const params = { - organizationId, - aggregationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - //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 updatePaymentMethod( - paymentMethodId: string, - providerMethodId: string - ): Promise { - const path = `/account/payment-methods/${paymentMethodId}`; - const params = { - paymentMethodId, - providerMethodId - }; - 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 addCredit(organizationId: string, couponId: string): Promise { - const path = `/organizations/${organizationId}/credits`; - const params = { - couponId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'POST', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async listCredits(organizationId: string, queries = []): Promise { - const path = `/organizations/${organizationId}/credits`; - 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 getCredit(organizationId: string, creditId: string): Promise { - const path = `/organizations/${organizationId}/credits/${creditId}`; - const params = { - creditId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - // async listPaymentMethods(teamId: string) { - // const path = `/teams/${teamId}/payment-methods`; - // const uri = new URL(this.client.config.endpoint + path); - // return await this.client.call('GET', uri); - // } - - // async createPaymentMethod(teamId: string): Promise { - // const path = `/teams/${teamId}/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 - // ); - // } -} +export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods); export const tierFree = { price: 0, diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 025116712..092500e71 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -8,8 +8,8 @@ export type Organization = Models.Team> & { budgetAlert: number[]; paymentMethodId: string; backupPaymentMethodId: string; - billingCurrentInvoiceDate: Date; - billingNextInvoiceDate: Date; + billingCurrentInvoiceDate: string; + billingNextInvoiceDate: string; }; export const newOrgModal = writable(false); diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 6efb8c448..a8004bc26 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -14,7 +14,7 @@ import { Teams, Users } from '@appwrite.io/console'; -import { Billing } from './billing'; +import { Billing } from '../sdk/billing'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; diff --git a/src/routes/console/account/payments/paymentModal.svelte b/src/routes/console/account/payments/paymentModal.svelte index 0cceecdb8..155b8dd70 100644 --- a/src/routes/console/account/payments/paymentModal.svelte +++ b/src/routes/console/account/payments/paymentModal.svelte @@ -10,7 +10,8 @@ import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { app } from '$lib/stores/app'; - import { apperanceDark, apperanceLight, type PaymentMethodData } from '$lib/stores/billing'; + import { apperanceDark, apperanceLight } from '$lib/stores/billing'; + import type { PaymentMethodData } from '$lib/sdk/billing'; import { VARS } from '$lib/system'; export let show = false; diff --git a/src/routes/console/onboarding/+page.svelte b/src/routes/console/onboarding/+page.svelte index be55cba83..bf2c5ce3f 100644 --- a/src/routes/console/onboarding/+page.svelte +++ b/src/routes/console/onboarding/+page.svelte @@ -10,6 +10,7 @@ import { Container } from '$lib/layout'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; + import { isCloud } from '$lib/system'; import { ID } from '@appwrite.io/console'; let name: string; @@ -41,7 +42,14 @@ } async function createOrganization() { - return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects'); + if (isCloud) { + return await sdk.forConsole.billing.createOrganization( + ID.unique(), + 'Personal Projects', + 'tier-0', + null + ); + } else return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects'); } diff --git a/src/routes/console/organization-[organization]/billing/+page.svelte b/src/routes/console/organization-[organization]/billing/+page.svelte index eb802422b..47ade1713 100644 --- a/src/routes/console/organization-[organization]/billing/+page.svelte +++ b/src/routes/console/organization-[organization]/billing/+page.svelte @@ -1,31 +1,19 @@ - - {#if $organization?.billingPlan !== 'tier-2'} + {#if $organization?.billingPlan === 'tier-2'} {/if} - -{#if showPayment} - -{/if} diff --git a/src/routes/console/organization-[organization]/billing/+page.ts b/src/routes/console/organization-[organization]/billing/+page.ts index fb506bb21..4f310560d 100644 --- a/src/routes/console/organization-[organization]/billing/+page.ts +++ b/src/routes/console/organization-[organization]/billing/+page.ts @@ -5,6 +5,7 @@ import type { PageLoad } from './$types'; export const load: PageLoad = async ({ parent, depends }) => { await parent(); depends(Dependencies.PAYMENT_METHODS); + depends(Dependencies.ORG_PAYMENT_METHODS); return { paymentMethods: await sdk.forConsole.billing.listPaymentMethods() diff --git a/src/routes/console/organization-[organization]/billing/availableCredit.svelte b/src/routes/console/organization-[organization]/billing/availableCredit.svelte deleted file mode 100644 index 1b63715fb..000000000 --- a/src/routes/console/organization-[organization]/billing/availableCredit.svelte +++ /dev/null @@ -1,45 +0,0 @@ - - - - Available Credit - -

Appwrite credit will automatically be applied to your next invoice.

- -

Credit balance: {credit}

- - - - -
- - - - -
diff --git a/src/routes/console/organization-[organization]/billing/billingAddress.svelte b/src/routes/console/organization-[organization]/billing/billingAddress.svelte index 93de721d1..969dec675 100644 --- a/src/routes/console/organization-[organization]/billing/billingAddress.svelte +++ b/src/routes/console/organization-[organization]/billing/billingAddress.svelte @@ -1,5 +1,8 @@ @@ -9,8 +12,13 @@ View or update your billing address. This address will appear on your invoice.

- -

Add a billing address

-
+ + (showDropdown = true)}> +

Add a billing address

+
+ + Add new billing address + +
diff --git a/src/routes/console/organization-[organization]/billing/budgetAlert.svelte b/src/routes/console/organization-[organization]/billing/budgetAlert.svelte index ba44bfec4..49e238627 100644 --- a/src/routes/console/organization-[organization]/billing/budgetAlert.svelte +++ b/src/routes/console/organization-[organization]/billing/budgetAlert.svelte @@ -118,4 +118,4 @@ - + diff --git a/src/routes/console/organization-[organization]/billing/budgetCap.svelte b/src/routes/console/organization-[organization]/billing/budgetCap.svelte index d09af29f0..0c02b92d6 100644 --- a/src/routes/console/organization-[organization]/billing/budgetCap.svelte +++ b/src/routes/console/organization-[organization]/billing/budgetCap.svelte @@ -68,9 +68,9 @@ - + - + diff --git a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte deleted file mode 100644 index 47579a499..000000000 --- a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte +++ /dev/null @@ -1,20 +0,0 @@ - - - - Payment History - -

- Transaction history for this Organization. Download invoices for more details about your - payments. -

- - -

- You have no payment history. After you receive your first invoice, you'll see it - here. -

-
-
-
diff --git a/src/routes/console/organization-[organization]/billing/paymentMethods.svelte b/src/routes/console/organization-[organization]/billing/paymentMethods.svelte index 22b8757d0..e7cbcf5e4 100644 --- a/src/routes/console/organization-[organization]/billing/paymentMethods.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentMethods.svelte @@ -1,33 +1,136 @@ - Payment Methods + Payment methods -

View or update your organization payment methods here.

+

+ View or update your organization payment methods here. A maximum of two payment methods can + be added. +

- {#if $paymentMethods.total > 0} - {#each $paymentMethods.paymentMethods as paymentMethod} -

- {paymentMethod.brand} - {paymentMethod.last4}, expiring: {paymentMethod.expiryMonth}/{paymentMethod.expiryYear} - {#if paymentMethod.default} {/if} -

- {/each} - - {:else} - (showPayment = true)}> -

Add a payment method

-
- {/if} +

Default

+
+
+
+ + + + {#if $paymentMethods.total} + {#each $paymentMethods.paymentMethods as paymentMethod} + addPaymentMethod(paymentMethod?.$id)}> +

+ Card ending in {paymentMethod.last4} + {paymentMethod.brand} +

+
+ {/each} + {/if} + Add new billing address +
+
+
+
+ Add a payment method +
+
+
+

Backup

+
+
+
+ + + + {#if $paymentMethods.total} + {#each $paymentMethods.paymentMethods as paymentMethod} + addBackupPaymentMethod(paymentMethod?.$id)}> +

+ Card ending in {paymentMethod.last4} + {paymentMethod.brand} +

+
+ {/each} + {/if} + Add new billing address +
+
+
+
+ Add a backup payment method +
+
+
+ +{#if showPayment && isCloud && hasStripePublicKey} + +{/if} diff --git a/src/routes/console/organization-[organization]/billing/paymentSummary.svelte b/src/routes/console/organization-[organization]/billing/paymentSummary.svelte index bd60176b9..24c197706 100644 --- a/src/routes/console/organization-[organization]/billing/paymentSummary.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentSummary.svelte @@ -1,24 +1,66 @@ - Payment Summary + Plan summary -

An overview of your upcoming payments.

+

+ Your current project plan. For more information on Appwrite plans, +

-
PLACEHOLDER PLAN
+
+ {currentTier.name} +
+
+ + +

${currentTier.price}

-

X projects

- {#if VARS.CONSOLE_TIER && VARS.CONSOLE_TIER !== 'base'} -
-

Next billing data

-

XX DATE

-
- {/if} +
+

+ Billing period: {toLocaleDate($organization.billingCurrentInvoiceDate)} - {toLocaleDate( + $organization.billingNextInvoiceDate + )} +

+ +
+
+ + +
+ + diff --git a/src/routes/console/organization-[organization]/billing/store.ts b/src/routes/console/organization-[organization]/billing/store.ts deleted file mode 100644 index c9f2b970f..000000000 --- a/src/routes/console/organization-[organization]/billing/store.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { page } from '$app/stores'; -import { derived } from 'svelte/store'; - -export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods); diff --git a/src/routes/console/project-[project]/settings/usage/[[period]]/+page.svelte b/src/routes/console/project-[project]/settings/usage/[[period]]/+page.svelte index 6dcaa4c3a..95c6cc7ac 100644 --- a/src/routes/console/project-[project]/settings/usage/[[period]]/+page.svelte +++ b/src/routes/console/project-[project]/settings/usage/[[period]]/+page.svelte @@ -7,7 +7,7 @@ export let data; - $: requests = data.response.requests; + $: requests = data.requests; // $: network = data.response.network; // $: executions = data.response.executions; // $: documents = data.response.documents; diff --git a/src/routes/console/wizard/step2.svelte b/src/routes/console/wizard/step2.svelte index e156c4d09..7e77801af 100644 --- a/src/routes/console/wizard/step2.svelte +++ b/src/routes/console/wizard/step2.svelte @@ -6,7 +6,7 @@ import { onMount } from 'svelte'; import { createOrganization } from './store'; import UsageRates from './usageRates.svelte'; - import type { PaymentList, PaymentMethodData } from '$lib/stores/billing'; + import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing'; import { paymentMethods } from '../account/payments/store'; import { loadStripe, type Stripe, type StripeElements } from '@stripe/stripe-js'; import { organization } from '$lib/stores/organization'; @@ -167,4 +167,4 @@ - + diff --git a/src/routes/console/wizard/usageRates.svelte b/src/routes/console/wizard/usageRates.svelte index 7c6af3ca0..fe332dbbb 100644 --- a/src/routes/console/wizard/usageRates.svelte +++ b/src/routes/console/wizard/usageRates.svelte @@ -1,4 +1,4 @@ - Usage rates -

Usage on the Pro plan will be charged at the end of each billing period at the following - rates. Next billing period: 05 Jun, 2023. + rates. Next billing period: {toLocaleDate(nextDate)}

@@ -29,7 +36,7 @@ Rate - {#each usageRates[$createOrganization.billingPlan] as usage} + {#each usageRates[tier] as usage} {usage.resource} {usage.limit}