From c67fea49824e3c541c46aeaf578a4b81b348f84e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 28 Aug 2024 02:57:28 +0000 Subject: [PATCH 01/87] update create --- src/lib/sdk/billing.ts | 8 ++- .../console/create-organization/+page.svelte | 51 ++++++++----------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index f0fd8ec08..ebe2a5557 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -307,7 +307,9 @@ export class Billing { name: string, billingPlan: string, paymentMethodId: string, - billingAddressId: string = undefined + billingAddressId: string = undefined, + couponId: string = undefined, + invites: Array = [] ): Promise { const path = `/organizations`; const params = { @@ -315,7 +317,9 @@ export class Billing { name, billingPlan, paymentMethodId, - billingAddressId + billingAddressId, + couponId, + invites }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index e7ac26659..1b9dd8b45 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -103,23 +103,14 @@ null ); } else { - // Create free organization if coming from onboarding - if (previousPage.includes('/console/onboarding') && !anyOrgFree) { - await sdk.forConsole.billing.createOrganization( - ID.unique(), - 'Personal Projects', - BillingPlan.FREE, - null, - null - ); - } - org = await sdk.forConsole.billing.createOrganization( ID.unique(), name, billingPlan, paymentMethodId, - null + null, + couponData?.code, + collaborators ); //Add budget @@ -127,25 +118,25 @@ await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); } - //Add coupon - if (couponData?.code) { - await sdk.forConsole.billing.addCredit(org.$id, couponData.code); - trackEvent(Submit.CreditRedeem); - } + // //Add coupon + // if (couponData?.code) { + // await sdk.forConsole.billing.addCredit(org.$id, couponData.code); + // trackEvent(Submit.CreditRedeem); + // } - //Add collaborators - if (collaborators?.length) { - collaborators.forEach(async (collaborator) => { - await sdk.forConsole.teams.createMembership( - org.$id, - ['owner'], - collaborator, - undefined, - undefined, - `${$page.url.origin}/console/organization-${org.$id}` - ); - }); - } + // //Add collaborators + // if (collaborators?.length) { + // collaborators.forEach(async (collaborator) => { + // await sdk.forConsole.teams.createMembership( + // org.$id, + // ['owner'], + // collaborator, + // undefined, + // undefined, + // `${$page.url.origin}/console/organization-${org.$id}` + // ); + // }); + // } // Add tax ID if (taxId) { From 708517a0d075ee90e7706770e388a455b5635ae5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 28 Aug 2024 11:08:18 +0545 Subject: [PATCH 02/87] authorize payment --- .../commandCenter/searchers/organizations.ts | 2 +- src/lib/sdk/billing.ts | 4 ++-- src/lib/stores/organization.ts | 9 ++++++++ src/routes/+layout.ts | 2 +- .../console/account/organizations/+page.ts | 2 +- .../console/create-organization/+page.svelte | 21 ++++++++++++++++--- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/lib/commandCenter/searchers/organizations.ts b/src/lib/commandCenter/searchers/organizations.ts index df72d77b2..e5e8d7694 100644 --- a/src/lib/commandCenter/searchers/organizations.ts +++ b/src/lib/commandCenter/searchers/organizations.ts @@ -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) => { diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index ebe2a5557..ea278c5ba 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -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 = [] - ): Promise { + ): Promise { const path = `/organizations`; const params = { organizationId, diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 2beb13b03..d41cc3f54 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -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> & { billingBudget: number; billingPlan: Tier; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 85ad4e83d..5f0472229 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -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 = [ diff --git a/src/routes/console/account/organizations/+page.ts b/src/routes/console/account/organizations/+page.ts index 0b89b1d30..3f21115b8 100644 --- a/src/routes/console/account/organizations/+page.ts +++ b/src/routes/console/account/organizations/+page.ts @@ -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('') diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 1b9dd8b45..3bcbae041 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -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]); } From eec5c6f1f34b5fb5e0d788166a3e92eae9819ef5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 29 Aug 2024 08:30:49 +0545 Subject: [PATCH 03/87] support taxid and budget while creating --- src/lib/sdk/billing.ts | 8 ++++++-- .../console/create-organization/+page.svelte | 16 +++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index ea278c5ba..936d9f3ad 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -309,7 +309,9 @@ export class Billing { paymentMethodId: string, billingAddressId: string = undefined, couponId: string = undefined, - invites: Array = [] + invites: Array = [], + budget: number = undefined, + taxId: string = undefined ): Promise { const path = `/organizations`; const params = { @@ -319,7 +321,9 @@ export class Billing { paymentMethodId, billingAddressId, couponId, - invites + invites, + budget, + taxId }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 3bcbae041..09c9e9248 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -119,7 +119,9 @@ paymentMethodId, null, couponData?.code, - collaborators + collaborators, + billingBudget, + taxId ); if (!isOrganization(org) && org.status == 402) { @@ -129,9 +131,9 @@ } //Add budget - if (billingBudget && isOrganization(org)) { - await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); - } + // if (billingBudget && isOrganization(org)) { + // await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); + // } // //Add coupon // if (couponData?.code) { @@ -154,9 +156,9 @@ // } // Add tax ID - if (taxId) { - await sdk.forConsole.billing.updateTaxId(org.$id, taxId); - } + // if (taxId) { + // await sdk.forConsole.billing.updateTaxId(org.$id, taxId); + // } } trackEvent(Submit.OrganizationCreate, { From 414bc60bc88ef93dd87c4023dde3e7e55898c0b1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 29 Aug 2024 11:26:22 +0545 Subject: [PATCH 04/87] handle validation --- src/lib/sdk/billing.ts | 26 ++++++++- src/lib/stores/stripe.ts | 10 +++- .../console/create-organization/+page.svelte | 56 ++++++++++++++++--- .../billing/paymentHistory.svelte | 1 - 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 936d9f3ad..646fdc175 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -302,16 +302,36 @@ export class Billing { ); } + async validateOrganization( + organizationId: string, + invites: string[], + ): Promise { + const path = `/organizations/${organizationId}/validate`; + const params = { + organizationId, + invites, + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'PATCH', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async createOrganization( organizationId: string, name: string, billingPlan: string, paymentMethodId: string, - billingAddressId: string = undefined, - couponId: string = undefined, + billingAddressId: string = null, + couponId: string = null, invites: Array = [], budget: number = undefined, - taxId: string = undefined + taxId: string = null ): Promise { const path = `/organizations`; const params = { diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index 93b4576ae..b1f01016b 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -116,7 +116,8 @@ export async function confirmPayment( orgId: string, clientSecret: string, paymentMethodId: string, - route?: string + route?: string, + returnError: boolean = false ) { try { const url = @@ -128,10 +129,13 @@ export async function confirmPayment( clientSecret: clientSecret, confirmParams: { return_url: url, - payment_method: paymentMethod.providerMethodId - } + payment_method: paymentMethod.providerMethodId, + }, }); if (error) { + if (returnError) { + return error; + } throw error.message; } } catch (e) { diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 09c9e9248..67d1341f1 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -88,6 +88,14 @@ if (anyOrgFree) { billingPlan = BillingPlan.PRO; } + if($page.url.searchParams.has('type')) { + const type = $page.url.searchParams.get('type'); + if(type === 'confirmed') { + const organizationId= $page.url.searchParams.get('id'); + const invites = $page.url.searchParams.getAll('invites'); + await validate(organizationId, invites); + } + } }); async function loadPaymentMethods() { @@ -99,6 +107,27 @@ return (org as Organization).$id !== undefined; } + async function validate(organizationId: string, invites: string[]) { + try { + let org = await sdk.forConsole.billing.validateOrganization(organizationId, invites); + if (isOrganization(org)) { + await preloadData(`${base}/console/organization-${org.$id}`); + await goto(`${base}/console/organization-${org.$id}`); + addNotification({ + type: 'success', + message: `${org.name ?? 'Organization'} has been created` + }); + } + } catch (e) { + addNotification({ + type: 'error', + message: e.message + }); + trackError(e, Submit.OrganizationCreate); + } + + } + async function create() { try { let org: Organization | CreateOrgAuth; @@ -126,8 +155,15 @@ if (!isOrganization(org) && org.status == 402) { let clientSecret = org.clientSecret; - await confirmPayment('', clientSecret, paymentMethodId); - // throw new Error('Payment requires authentication'); + let params = new URLSearchParams(); + params.append('type', 'confirmed'); + params.append('id', org.teamId); + for (let index = 0; index < collaborators.length; index++) { + const invite = collaborators[index]; + params.append('invites', invite); + } + await confirmPayment('', clientSecret, paymentMethodId, '/console/create-organization?'+params.toString()); + await validate(org.teamId, collaborators); } //Add budget @@ -167,13 +203,15 @@ members_invited: collaborators?.length }); - await invalidate(Dependencies.ACCOUNT); - await preloadData(`${base}/console/organization-${org.$id}`); - await goto(`${base}/console/organization-${org.$id}`); - addNotification({ - type: 'success', - message: `${name ?? 'Organization'} has been created` - }); + if(isOrganization(org)) { + await invalidate(Dependencies.ACCOUNT); + await preloadData(`${base}/console/organization-${org.$id}`); + await goto(`${base}/console/organization-${org.$id}`); + addNotification({ + type: 'success', + message: `${org.name ?? 'Organization'} has been created` + }); + } } catch (e) { addNotification({ type: 'error', diff --git a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte index 1784b0a57..0c9642dfc 100644 --- a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte @@ -49,7 +49,6 @@ invoiceList = await sdk.forConsole.billing.listInvoices($page.params.organization, [ Query.limit(limit), Query.offset(offset), - Query.notEqual('from', $organization.billingCurrentInvoiceDate), Query.orderDesc('$createdAt') ]); } From c97e372386764d6cd456e9cf776368f1c4f3fa26 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 3 Sep 2024 09:17:18 +0545 Subject: [PATCH 05/87] fix check with cloud --- src/lib/sdk/billing.ts | 4 +- src/lib/stores/organization.ts | 2 +- src/routes/+layout.ts | 3 +- .../console/account/organizations/+page.ts | 15 ++++-- .../console/create-organization/+page.svelte | 52 +++++-------------- 5 files changed, 28 insertions(+), 48 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 646fdc175..3c93d32ae 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,5 +1,5 @@ import type { Client, Models } from '@appwrite.io/console'; -import type { CreateOrgAuth, Organization, OrganizationList } from '../stores/organization'; +import type { OrganizationError, Organization, OrganizationList } from '../stores/organization'; import type { PaymentMethod } from '@stripe/stripe-js'; import type { Tier } from '$lib/stores/billing'; @@ -332,7 +332,7 @@ export class Billing { invites: Array = [], budget: number = undefined, taxId: string = null - ): Promise { + ): Promise { const path = `/organizations`; const params = { organizationId, diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index d41cc3f54..ca7269ca3 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -3,7 +3,7 @@ import { derived, writable } from 'svelte/store'; import type { Models } from '@appwrite.io/console'; import type { Tier } from './billing'; -export type CreateOrgAuth = { +export type OrganizationError = { status: number; message: string; teamId: string; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 5f0472229..8986f1a12 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -6,6 +6,7 @@ import { redirect } from '@sveltejs/kit'; import { Dependencies } from '$lib/constants'; import type { LayoutLoad } from './$types'; import { redirectTo } from './store'; +import { isCloud } from '$lib/system'; export const ssr = false; @@ -22,7 +23,7 @@ export const load: LayoutLoad = async ({ depends, url }) => { return { account, - organizations: await sdk.forConsole.billing.listOrganization() + organizations: isCloud ? await sdk.forConsole.billing.listOrganization() : await sdk.forConsole.teams.list() }; } catch (error) { const acceptedRoutes = [ diff --git a/src/routes/console/account/organizations/+page.ts b/src/routes/console/account/organizations/+page.ts index 3f21115b8..803497c6a 100644 --- a/src/routes/console/account/organizations/+page.ts +++ b/src/routes/console/account/organizations/+page.ts @@ -3,19 +3,24 @@ import { sdk } from '$lib/stores/sdk'; import { getLimit, getPage, pageToOffset } from '$lib/helpers/load'; import { CARD_LIMIT } from '$lib/constants'; import type { PageLoad } from './$types'; +import { isCloud } from '$lib/system'; export const load: PageLoad = async ({ url, route }) => { const page = getPage(url); const limit = getLimit(url, route, CARD_LIMIT); const offset = pageToOffset(page, limit); + const queries = [ + Query.offset(offset), + Query.limit(limit), + Query.orderDesc('') + ]; + + const organizations = isCloud ? await sdk.forConsole.billing.listOrganization(queries) : sdk.forConsole.teams.list(queries); + return { offset, limit, - organizations: await sdk.forConsole.billing.listOrganization([ - Query.offset(offset), - Query.limit(limit), - Query.orderDesc('') - ]) + organizations }; }; diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 67d1341f1..323d48c61 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -24,7 +24,7 @@ import { addNotification } from '$lib/stores/notifications'; import { organizationList, - type CreateOrgAuth, + type OrganizationError, type Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; @@ -88,10 +88,10 @@ if (anyOrgFree) { billingPlan = BillingPlan.PRO; } - if($page.url.searchParams.has('type')) { + if ($page.url.searchParams.has('type')) { const type = $page.url.searchParams.get('type'); - if(type === 'confirmed') { - const organizationId= $page.url.searchParams.get('id'); + if (type === 'confirmed') { + const organizationId = $page.url.searchParams.get('id'); const invites = $page.url.searchParams.getAll('invites'); await validate(organizationId, invites); } @@ -103,7 +103,7 @@ paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null; } - function isOrganization(org: Organization | CreateOrgAuth): org is Organization { + function isOrganization(org: Organization | OrganizationError): org is Organization { return (org as Organization).$id !== undefined; } @@ -125,12 +125,11 @@ }); trackError(e, Submit.OrganizationCreate); } - } async function create() { try { - let org: Organization | CreateOrgAuth; + let org: Organization | OrganizationError; if (billingPlan === BillingPlan.FREE) { org = await sdk.forConsole.billing.createOrganization( @@ -162,39 +161,14 @@ const invite = collaborators[index]; params.append('invites', invite); } - await confirmPayment('', clientSecret, paymentMethodId, '/console/create-organization?'+params.toString()); + await confirmPayment( + '', + clientSecret, + paymentMethodId, + '/console/create-organization?' + params.toString() + ); await validate(org.teamId, collaborators); } - - //Add budget - // if (billingBudget && isOrganization(org)) { - // await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); - // } - - // //Add coupon - // if (couponData?.code) { - // await sdk.forConsole.billing.addCredit(org.$id, couponData.code); - // trackEvent(Submit.CreditRedeem); - // } - - // //Add collaborators - // if (collaborators?.length) { - // collaborators.forEach(async (collaborator) => { - // await sdk.forConsole.teams.createMembership( - // org.$id, - // ['owner'], - // collaborator, - // undefined, - // undefined, - // `${$page.url.origin}/console/organization-${org.$id}` - // ); - // }); - // } - - // Add tax ID - // if (taxId) { - // await sdk.forConsole.billing.updateTaxId(org.$id, taxId); - // } } trackEvent(Submit.OrganizationCreate, { @@ -203,7 +177,7 @@ members_invited: collaborators?.length }); - if(isOrganization(org)) { + if (isOrganization(org)) { await invalidate(Dependencies.ACCOUNT); await preloadData(`${base}/console/organization-${org.$id}`); await goto(`${base}/console/organization-${org.$id}`); From b568e8553c5eae5a308073a78815015e6e329820 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 3 Sep 2024 09:19:07 +0545 Subject: [PATCH 06/87] improve --- src/routes/console/create-organization/+page.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/console/create-organization/+page.svelte b/src/routes/console/create-organization/+page.svelte index 323d48c61..8dc928f00 100644 --- a/src/routes/console/create-organization/+page.svelte +++ b/src/routes/console/create-organization/+page.svelte @@ -90,7 +90,7 @@ } if ($page.url.searchParams.has('type')) { const type = $page.url.searchParams.get('type'); - if (type === 'confirmed') { + if (type === 'payment_confirmed') { const organizationId = $page.url.searchParams.get('id'); const invites = $page.url.searchParams.getAll('invites'); await validate(organizationId, invites); @@ -155,7 +155,7 @@ if (!isOrganization(org) && org.status == 402) { let clientSecret = org.clientSecret; let params = new URLSearchParams(); - params.append('type', 'confirmed'); + params.append('type', 'payment_confirmed'); params.append('id', org.teamId); for (let index = 0; index < collaborators.length; index++) { const invite = collaborators[index]; From 81d4ad8a6e2a5939edd15ffd5298f20e0ecdcbe1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 11 Nov 2024 08:41:25 +0000 Subject: [PATCH 07/87] remove unused --- .../organization-[organization]/billing/paymentHistory.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte index 290b76b75..e74739f53 100644 --- a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte @@ -28,7 +28,6 @@ import { onMount } from 'svelte'; import { trackEvent } from '$lib/actions/analytics'; import { selectedInvoice, showRetryModal } from './store'; - import { organization } from '$lib/stores/organization'; let showDropdown = []; let showFailedError = false; From c7a9e26de0ee343bc66e835b58533d5c7ec23ff9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 11 Nov 2024 09:05:36 +0000 Subject: [PATCH 08/87] allow scale selection --- .../components/billing/planSelection.svelte | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/lib/components/billing/planSelection.svelte b/src/lib/components/billing/planSelection.svelte index 0d484a9b4..cfcb28bba 100644 --- a/src/lib/components/billing/planSelection.svelte +++ b/src/lib/components/billing/planSelection.svelte @@ -76,31 +76,29 @@ - {#if $organization?.billingPlan === BillingPlan.SCALE} -
  • - - -
    -

    - {tierScale.name} - {#if $organization?.billingPlan === BillingPlan.SCALE && !isNewOrg} - Current plan - {/if} -

    -

    - {tierScale.description} -

    -

    - {formatCurrency(scalePlan?.price ?? 0)} per month + usage -

    -
    -
    -
    -
  • - {/if} +
  • + + +
    +

    + {tierScale.name} + {#if $organization?.billingPlan === BillingPlan.SCALE && !isNewOrg} + Current plan + {/if} +

    +

    + {tierScale.description} +

    +

    + {formatCurrency(scalePlan?.price ?? 0)} per month + usage +

    +
    +
    +
    +
  • {/if} From f29ca9a8e9776e643aad723c268bb549d1a63f34 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 14 Nov 2024 12:59:39 +0545 Subject: [PATCH 09/87] update plan upgrade --- src/lib/sdk/billing.ts | 14 +- .../change-plan/+page.svelte | 126 +++++++++++------- 2 files changed, 91 insertions(+), 49 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index f2428fd19..bee94ffc3 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -416,14 +416,22 @@ export class Billing { organizationId: string, billingPlan: string, paymentMethodId: string, - billingAddressId: string = undefined - ): Promise { + billingAddressId: string = undefined, + couponId: string = null, + invites: Array = [], + budget: number = undefined, + taxId: string = null + ): Promise { const path = `/organizations/${organizationId}/plan`; const params = { organizationId, billingPlan, paymentMethodId, - billingAddressId + billingAddressId, + couponId, + invites, + budget, + taxId }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 3682491c7..573f1e9fb 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -1,5 +1,5 @@
    - -

    {currentPlan.name} plan

    -

    {formatCurrency(currentPlan.price)}

    -
    - +
    +

    {selectedPlan.name} plan

    +

    {formatCurrency(selectedPlan.price)}

    +
    + +

    Additional seats ({collaborators?.length})

    - {formatCurrency(extraSeatsCost)} + {formatCurrency( + isScaleDowngrade + ? (collaborators?.length ?? 0) * (selectedPlan?.addons?.member?.price ?? 0) + : extraSeatsCost + )}

    - +
    + + {#if isScaleUpgrade} + {@const currentPlanName = currentOrgPlan.name} +
    +
    + Unused {currentPlanName} plan balance + + +
    +

    -{formatCurrency(unUsedBalances)}

    +
    + {:else if isScaleDowngrade} +
    + Unused {currentOrgPlan.name} plan balance +

    -{formatCurrency(currentOrgPlan.price)}

    +
    + {/if} + {#if couponData?.status === 'active'} {/if}
    - +

    Upcoming charge
    Due on {!currentPlan.trialDays + >Due on {!selectedPlan.trialDays ? toLocaleDate(billingPayDate.toString()) : toLocaleDate(trialEndDate.toString())}

    {formatCurrency(estimatedTotal)}

    - +

    - You'll pay {formatCurrency(estimatedTotal)} now, with our first - billing cycle starting on + You'll {isRefund ? 'receive a refund of' : 'pay'} + {formatCurrency(estimatedTotal)} + now, with our first billing cycle starting on {!currentPlan.trialDays + >{!selectedPlan.trialDays ? toLocaleDate(billingPayDate.toString()) : toLocaleDate(trialEndDate.toString())}. Once your credits run out, you'll be charged - {formatCurrency(currentPlan.price)} plus usage fees every 30 days. + {formatCurrency(selectedPlan.price)} plus usage fees every 30 days.

    diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index fe317b18a..46c1e8b59 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -23,7 +23,7 @@ InputTextarea, Label } from '$lib/elements/forms'; - import { formatCurrency } from '$lib/helpers/numbers.js'; + import { formatCurrency } from '$lib/helpers/numbers'; import { WizardSecondaryContainer, WizardSecondaryContent, @@ -39,7 +39,7 @@ type OrganizationError } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; - import { confirmPayment } from '$lib/stores/stripe.js'; + import { confirmPayment } from '$lib/stores/stripe'; import { user } from '$lib/stores/user'; import { VARS } from '$lib/system'; import { onMount } from 'svelte'; @@ -107,8 +107,8 @@ billingPlan = BillingPlan.PRO; } - const currentPlan = await sdk.forConsole.billing.getPlan($organization?.$id); - selfService = currentPlan.selfService; + const currentOrgPlan = await sdk.forConsole.billing.getPlan($organization?.$id); + selfService = currentOrgPlan.selfService; }); async function loadPaymentMethods() { @@ -210,7 +210,7 @@ async function upgrade() { try { //Add collaborators - var newCollaborators = []; + let newCollaborators = []; if (collaborators?.length) { newCollaborators = collaborators.filter( (collaborator) => @@ -369,11 +369,12 @@ {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM} + currentTier={$organization.billingPlan} /> {:else if $organization.billingPlan !== BillingPlan.CUSTOM} {/if} From bcbf5c75b5faa7ee1b82b3c0192949d586774809 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Dec 2024 13:25:27 +0530 Subject: [PATCH 13/87] address comments. --- .../billing/estimatedTotalBox.svelte | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index df06ef0b7..b73c87378 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -34,17 +34,14 @@ : 0; $: extraSeatsCost = (collaborators?.length ?? 0) * (selectedPlan?.addons?.member?.price ?? 0); - $: grossCost = - isScaleUpgrade || isScaleDowngrade - ? selectedPlan.price + extraSeatsCost - unUsedBalances - : selectedPlan.price + extraSeatsCost; + $: grossCost = isScaleUpgrade + ? selectedPlan.price + extraSeatsCost - unUsedBalances + : selectedPlan.price + extraSeatsCost; $: estimatedTotal = couponData?.status === 'active' ? Math.max(0, grossCost - couponData.credits) : grossCost; $: trialEndDate = new Date( billingPayDate.getTime() + selectedPlan.trialDays * 24 * 60 * 60 * 1000 ); - - $: isRefund = isScaleDowngrade && grossCost < 0;

    -{formatCurrency(unUsedBalances)}

    - {:else if isScaleDowngrade} -
    - Unused {currentOrgPlan.name} plan balance -

    -{formatCurrency(currentOrgPlan.price)}

    -
    {/if} {#if couponData?.status === 'active'} @@ -107,15 +99,28 @@

    - You'll {isRefund ? 'receive a refund of' : 'pay'} - {formatCurrency(estimatedTotal)} - now, with our first billing cycle starting on - {!selectedPlan.trialDays - ? toLocaleDate(billingPayDate.toString()) - : toLocaleDate(trialEndDate.toString())}. Once your credits run out, you'll be charged - {formatCurrency(selectedPlan.price)} plus usage fees every 30 days. + {#if isScaleDowngrade} + You'll continue using the {currentOrgPlan.name} plan until your current cycle ends on + {!selectedPlan.trialDays + ? toLocaleDate(billingPayDate.toString()) + : toLocaleDate(trialEndDate.toString())}. Starting the next cycle, your plan will switch to {selectedPlan.name}, and you'll be + charged + {formatCurrency(grossCost)} + every 30 days. + {:else} + You'll pay + {formatCurrency(estimatedTotal)} + now, with our first billing cycle starting on + {!selectedPlan.trialDays + ? toLocaleDate(billingPayDate.toString()) + : toLocaleDate(trialEndDate.toString())}. Once your credits run out, you'll be charged + {formatCurrency(selectedPlan.price)} plus usage fees every 30 + days. + {/if}

    From b6a517a8cf952c9d3ba5d982a34e7c4f23935dff Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Dec 2024 13:25:35 +0530 Subject: [PATCH 14/87] ran: formatter. --- src/lib/components/billing/planSelection.svelte | 6 +----- src/lib/sdk/billing.ts | 7 ++----- src/lib/stores/stripe.ts | 4 ++-- src/routes/(console)/account/organizations/+page.ts | 10 ++++------ src/routes/+layout.ts | 4 +++- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/lib/components/billing/planSelection.svelte b/src/lib/components/billing/planSelection.svelte index cfcb28bba..4a6e1f7ca 100644 --- a/src/lib/components/billing/planSelection.svelte +++ b/src/lib/components/billing/planSelection.svelte @@ -77,11 +77,7 @@
  • - +

    diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index bee94ffc3..57ad227be 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -318,14 +318,11 @@ export class Billing { ); } - async validateOrganization( - organizationId: string, - invites: string[], - ): Promise { + async validateOrganization(organizationId: string, invites: string[]): Promise { const path = `/organizations/${organizationId}/validate`; const params = { organizationId, - invites, + invites }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index 357974646..e62110d20 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -130,8 +130,8 @@ export async function confirmPayment( clientSecret: clientSecret, confirmParams: { return_url: url, - payment_method: paymentMethod.providerMethodId, - }, + payment_method: paymentMethod.providerMethodId + } }); if (error) { if (returnError) { diff --git a/src/routes/(console)/account/organizations/+page.ts b/src/routes/(console)/account/organizations/+page.ts index 803497c6a..237a3772d 100644 --- a/src/routes/(console)/account/organizations/+page.ts +++ b/src/routes/(console)/account/organizations/+page.ts @@ -10,13 +10,11 @@ export const load: PageLoad = async ({ url, route }) => { const limit = getLimit(url, route, CARD_LIMIT); const offset = pageToOffset(page, limit); - const queries = [ - Query.offset(offset), - Query.limit(limit), - Query.orderDesc('') - ]; + const queries = [Query.offset(offset), Query.limit(limit), Query.orderDesc('')]; - const organizations = isCloud ? await sdk.forConsole.billing.listOrganization(queries) : sdk.forConsole.teams.list(queries); + const organizations = isCloud + ? await sdk.forConsole.billing.listOrganization(queries) + : sdk.forConsole.teams.list(queries); return { offset, diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 6468cab57..4c9b760ca 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -29,7 +29,9 @@ export const load: LayoutLoad = async ({ depends, url, route }) => { if (account) { return { account, - organizations: isCloud ? await sdk.forConsole.billing.listOrganization() : await sdk.forConsole.teams.list() + organizations: isCloud + ? await sdk.forConsole.billing.listOrganization() + : await sdk.forConsole.teams.list() }; } From 867320911c202c46e618cc904818a092b0a3c141 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 22 Dec 2024 13:14:06 +0545 Subject: [PATCH 15/87] update models --- src/lib/sdk/billing.ts | 24 ++++++++++++++++++------ src/lib/stores/organization.ts | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index bee94ffc3..01e2008a5 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -174,6 +174,10 @@ export type Aggregation = { * Usage logs for the billing period. */ resources: OrganizationUsage; + /** + * Aggregation billing plan + */ + plan: string; }; export type OrganizationUsage = { @@ -388,19 +392,27 @@ export class Billing { ); } - async getPlan(organizationId: string): Promise { + async getOrganizationPlan(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 getPlan(planId: string): Promise { + const path = `/console/plans/${planId}`; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + } ); } diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 0e1912c5f..53420f4e5 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -29,6 +29,8 @@ export type Organization = Models.Team> & { amount: number; billingTaxId?: string; billingPlanDowngrade?: Tier; + billingAggregationId: string; + billingInvoiceId: string; }; export type OrganizationList = { From 8fdf7c515f5f8470f17723cc7922c5adabf05702 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 22 Dec 2024 13:15:42 +0545 Subject: [PATCH 16/87] refactor and get current plan from aggregation --- .../billing/+page.svelte | 3 ++- .../billing/+page.ts | 25 ++++++++++++++----- .../billing/planSummary.svelte | 5 ++-- .../change-plan/+page.svelte | 2 +- .../usage/[[invoice]]/+page.ts | 2 +- .../storage/bucket-[bucket]/settings/+page.ts | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index d3d6b7fd1..ad680d21a 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -123,7 +123,8 @@ diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index 0e945f906..14957a4d3 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -21,10 +21,16 @@ export const load: PageLoad = async ({ parent, depends }) => { const billingAddressId = (organization as Organization)?.billingAddressId; const billingAddressPromise: Promise
    = billingAddressId ? sdk.forConsole.billing - .getOrganizationBillingAddress(organization.$id, billingAddressId) - .catch(() => null) + .getOrganizationBillingAddress(organization.$id, billingAddressId) + .catch(() => null) : null; + const billingAggregationId = (organization as Organization)?.billingAggregationId; + const billingInvoiceId = (organization as Organization)?.billingInvoiceId; + + const billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, billingAggregationId); + console.log(billingAggregation); + const [ paymentMethods, addressList, @@ -32,18 +38,22 @@ export const load: PageLoad = async ({ parent, depends }) => { billingAddress, currentPlan, creditList, - invoices + invoices, + aggregationBillingPlan, + billingInvoice, ] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), sdk.forConsole.billing.listAddresses(), sdk.forConsole.billing.listAggregation(organization.$id), billingAddressPromise, - sdk.forConsole.billing.getPlan(organization.$id), + sdk.forConsole.billing.getOrganizationPlan(organization.$id), sdk.forConsole.billing.listCredits(organization.$id), sdk.forConsole.billing.listInvoices(organization.$id, [ Query.limit(1), Query.equal('from', organization.billingCurrentInvoiceDate) - ]) + ]), + sdk.forConsole.billing.getPlan(billingAggregation.plan), + sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId) ]); return { @@ -52,7 +62,10 @@ export const load: PageLoad = async ({ parent, depends }) => { aggregationList, billingAddress, currentPlan, + aggregationBillingPlan, creditList, - invoices + invoices, + billingAggregation, + billingInvoice }; }; diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index c84356b75..f1c6c6465 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -17,8 +17,9 @@ export let members: Models.MembershipList; export let currentPlan: Plan; export let creditList: CreditList; + export let currentInvoice: Invoice | undefined = undefined - const currentInvoice: Invoice | undefined = invoices.length > 0 ? invoices[0] : undefined; + // const currentInvoice: Invoice | undefined = invoices.length > 0 ? invoices[0] : undefined; const extraMembers = members.total > 1 ? members.total - 1 : 0; const availableCredit = creditList.available; const today = new Date(); @@ -45,7 +46,7 @@ - {tierToPlan($organization?.billingPlan)?.name} plan + {currentPlan.name} plan
    {isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION ? formatCurrency(0) diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index fe317b18a..a44ab8ff0 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -107,7 +107,7 @@ billingPlan = BillingPlan.PRO; } - const currentPlan = await sdk.forConsole.billing.getPlan($organization?.$id); + const currentPlan = await sdk.forConsole.billing.getOrganizationPlan($organization?.$id); selfService = currentPlan.selfService; }); diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts index 9ffafbac2..b3546b01d 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.ts @@ -45,7 +45,7 @@ export const load: PageLoad = async ({ params, parent }) => { sdk.forConsole.billing.listInvoices(org.$id, [Query.orderDesc('from')]), sdk.forConsole.billing.listUsage(params.organization, startDate, endDate), sdk.forConsole.teams.listMemberships(params.organization), - sdk.forConsole.billing.getPlan(org.$id) + sdk.forConsole.billing.getOrganizationPlan(org.$id) ]); const projectNames: { [key: string]: Models.Project } = {}; diff --git a/src/routes/(console)/project-[project]/storage/bucket-[bucket]/settings/+page.ts b/src/routes/(console)/project-[project]/storage/bucket-[bucket]/settings/+page.ts index 546bfa7a8..83972d5a6 100644 --- a/src/routes/(console)/project-[project]/storage/bucket-[bucket]/settings/+page.ts +++ b/src/routes/(console)/project-[project]/storage/bucket-[bucket]/settings/+page.ts @@ -3,7 +3,7 @@ import { sdk } from '$lib/stores/sdk'; export const load: PageLoad = async ({ parent }) => { const { organization } = await parent(); - const currentPlan = await sdk.forConsole.billing.getPlan(organization.$id); + const currentPlan = await sdk.forConsole.billing.getOrganizationPlan(organization.$id); return { currentPlan }; From 1ee29b20777877ed6472b1aded55122168e716f8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 22 Dec 2024 13:55:58 +0545 Subject: [PATCH 17/87] update summary --- .../organization-[organization]/billing/planSummary.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index f1c6c6465..2ef69316b 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -39,7 +39,7 @@

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

    From 16705d38aac193517c7de52b730acd12e17f040a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 23 Dec 2024 07:11:16 +0545 Subject: [PATCH 18/87] fix rename --- src/routes/(console)/organization-[organization]/+layout.ts | 2 +- src/routes/(console)/project-[project]/+layout.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/+layout.ts b/src/routes/(console)/organization-[organization]/+layout.ts index 650990e86..cd1968ea8 100644 --- a/src/routes/(console)/organization-[organization]/+layout.ts +++ b/src/routes/(console)/organization-[organization]/+layout.ts @@ -27,7 +27,7 @@ export const load: LayoutLoad = async ({ params, depends }) => { const res = await sdk.forConsole.billing.getRoles(params.organization); roles = res.roles; scopes = res.scopes; - currentPlan = await sdk.forConsole.billing.getPlan(params.organization); + currentPlan = await sdk.forConsole.billing.getOrganizationPlan(params.organization); if (scopes.includes('billing.read')) { await failedInvoice.load(params.organization); if (get(failedInvoice)) { diff --git a/src/routes/(console)/project-[project]/+layout.ts b/src/routes/(console)/project-[project]/+layout.ts index 018462d75..872585143 100644 --- a/src/routes/(console)/project-[project]/+layout.ts +++ b/src/routes/(console)/project-[project]/+layout.ts @@ -29,7 +29,7 @@ export const load: LayoutLoad = async ({ params, depends }) => { let roles = isCloud ? [] : defaultRoles; let scopes = isCloud ? [] : defaultScopes; if (isCloud) { - currentPlan = await sdk.forConsole.billing.getPlan(project.teamId); + currentPlan = await sdk.forConsole.billing.getOrganizationPlan(project.teamId); const res = await sdk.forConsole.billing.getRoles(project.teamId); roles = res.roles; scopes = res.scopes; From 14a0cacbf68c0e41ec36ef82e32c2ef90489d370 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 23 Dec 2024 08:17:14 +0545 Subject: [PATCH 19/87] refactor --- .../organization-[organization]/billing/+page.svelte | 3 +-- .../(console)/organization-[organization]/billing/+page.ts | 6 ------ .../organization-[organization]/billing/planSummary.svelte | 3 +-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index ad680d21a..bf09c5575 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -124,8 +124,7 @@ creditList={data?.creditList} members={data?.members} currentPlan={data?.aggregationBillingPlan} - currentInvoice={data?.billingInvoice} - invoices={data?.invoices.invoices} /> + currentInvoice={data?.billingInvoice} /> diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index c98183028..25c390c2a 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -36,7 +36,6 @@ export const load: PageLoad = async ({ parent, depends }) => { aggregationList, billingAddress, creditList, - invoices, aggregationBillingPlan, billingInvoice, ] = await Promise.all([ @@ -45,10 +44,6 @@ export const load: PageLoad = async ({ parent, depends }) => { sdk.forConsole.billing.listAggregation(organization.$id), billingAddressPromise, sdk.forConsole.billing.listCredits(organization.$id), - sdk.forConsole.billing.listInvoices(organization.$id, [ - Query.limit(1), - Query.equal('from', organization.billingCurrentInvoiceDate) - ]), sdk.forConsole.billing.getPlan(billingAggregation.plan), sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId) ]); @@ -60,7 +55,6 @@ export const load: PageLoad = async ({ parent, depends }) => { billingAddress, aggregationBillingPlan, creditList, - invoices, billingAggregation, billingInvoice }; diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 2ef69316b..eeaee9aba 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -3,7 +3,7 @@ import { CardGrid, Collapsible, CollapsibleItem, Heading } from '$lib/components'; import { Button } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; - import { plansInfo, tierToPlan, upgradeURL } from '$lib/stores/billing'; + import { plansInfo, upgradeURL } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; import type { CreditList, Invoice, Plan } from '$lib/sdk/billing'; import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers'; @@ -13,7 +13,6 @@ import { tooltip } from '$lib/actions/tooltip'; import { type Models } from '@appwrite.io/console'; - export let invoices: Array; export let members: Models.MembershipList; export let currentPlan: Plan; export let creditList: CreditList; From 9f517bd0681a462a6d23c3dacd7011ac8e1be843 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 23 Dec 2024 08:38:16 +0545 Subject: [PATCH 20/87] improvements on error --- .../billing/+page.ts | 23 ++++++++++++------- .../billing/planSummary.svelte | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index 25c390c2a..12db3b547 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -4,7 +4,6 @@ import type { Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; import type { PageLoad } from './$types'; -import { Query } from '@appwrite.io/console'; export const load: PageLoad = async ({ parent, depends }) => { const { organization, scopes } = await parent(); @@ -26,32 +25,40 @@ export const load: PageLoad = async ({ parent, depends }) => { : null; const billingAggregationId = (organization as Organization)?.billingAggregationId; - const billingInvoiceId = (organization as Organization)?.billingInvoiceId; - const billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, billingAggregationId); + let billingAggregation = null; + try { + billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, billingAggregationId); + } catch (e) { + // ignore error + } + + const billingInvoiceId = (organization as Organization)?.billingInvoiceId; + let billingInvoice = null; + try { + billingInvoice = await sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId) + } catch (e) { + // ignore error + } + const [ paymentMethods, addressList, - aggregationList, billingAddress, creditList, aggregationBillingPlan, - billingInvoice, ] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), sdk.forConsole.billing.listAddresses(), - sdk.forConsole.billing.listAggregation(organization.$id), billingAddressPromise, sdk.forConsole.billing.listCredits(organization.$id), sdk.forConsole.billing.getPlan(billingAggregation.plan), - sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId) ]); return { paymentMethods, addressList, - aggregationList, billingAddress, aggregationBillingPlan, creditList, diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index eeaee9aba..d642ae108 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -54,7 +54,7 @@ : ''}
    - {#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION && extraUsage > 0} + {#if currentPlan.budgeting && extraUsage > 0} Add-ons Date: Tue, 24 Dec 2024 07:09:19 +0545 Subject: [PATCH 21/87] credit support from plan --- src/lib/sdk/billing.ts | 1 + .../organization-[organization]/billing/planSummary.svelte | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index ef581a0eb..711be9bef 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -291,6 +291,7 @@ export type Plan = { backupsEnabled: boolean; backupPolicies: number; emailBranding: boolean; + supportsCredit: boolean; }; export type PlansInfo = { diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 3d05ac3a6..d71c709d8 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -132,7 +132,7 @@ {/if} - {#if $organization?.billingPlan !== BillingPlan.FREE && availableCredit > 0} + {#if currentPlan.supportsCredit && availableCredit > 0}

    - Due at: {toLocaleDate( - $organization?.billingNextInvoiceDate - )} + Due at: {toLocaleDate($organization?.billingNextInvoiceDate)}

    - - {currentPlan.name} plan + {currentPlan.name} plan
    {isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION ? formatCurrency(0) @@ -204,17 +213,21 @@
    {:else}
    - + {#if $organization?.billingPlanDowngrade !== null} + + {:else} + + {/if} diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 2158fdeb1..8e1a777c9 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -155,6 +155,8 @@ }) }); + await invalidate(Dependencies.ORGANIZATION); + await goto(previousPage); addNotification({ type: 'success', From fb926d9d6fb4e02b3506bce632ef6a5be7d12e7b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 24 Dec 2024 08:02:47 +0545 Subject: [PATCH 23/87] cancel downgrade --- .../billing/cancelDowngradeModel.svelte | 51 +++++++++++++++++++ .../billing/planSummary.svelte | 21 +++----- .../settings/deleteOrganizationModal.svelte | 2 +- 3 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte diff --git a/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte b/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte new file mode 100644 index 000000000..78785305b --- /dev/null +++ b/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte @@ -0,0 +1,51 @@ + + +
    + +

    + Your organization is set to change to + {tierToPlan($organization?.billingPlanDowngrade).name} + plan on {toLocaleDate($organization.billingNextInvoiceDate)}. +

    +

    Are you sure you want to cancel the change?

    + + + + +
    +
    diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index d9b9ddc08..09cc3754e 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -8,18 +8,19 @@ import type { CreditList, Invoice, Plan } from '$lib/sdk/billing'; import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; - import { BillingPlan, Dependencies } from '$lib/constants'; + import { BillingPlan } from '$lib/constants'; import { trackEvent } from '$lib/actions/analytics'; import { tooltip } from '$lib/actions/tooltip'; import { type Models } from '@appwrite.io/console'; - import { sdk } from '$lib/stores/sdk'; - import { invalidate } from '$app/navigation'; + import CancelDowngradeModel from './cancelDowngradeModel.svelte'; export let members: Models.MembershipList; export let currentPlan: Plan; export let creditList: CreditList; export let currentInvoice: Invoice | undefined = undefined; + let showCancel: boolean = false; + const extraMembers = members.total > 1 ? members.total - 1 : 0; const availableCredit = creditList.available; const today = new Date(); @@ -28,17 +29,6 @@ $plansInfo.get($organization.billingPlan)?.trialDays; const extraUsage = currentInvoice ? currentInvoice.amount - currentPlan?.price : 0; const extraAddons = currentInvoice ? currentInvoice.usage?.length : 0; - - const cancelDowngrade = async () => { - await sdk.forConsole.billing.cancelDowngrade( - $organization.$id - ); - await invalidate(Dependencies.ORGANIZATION); - trackEvent('click_organization_plan_update', { - from: 'button', - source: 'billing_tab' - }); - }; {#if $organization} @@ -214,7 +204,7 @@ {:else}
    {#if $organization?.billingPlanDowngrade !== null} - + {:else}
    diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 8e1a777c9..e1072e247 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -321,7 +321,7 @@ you will be charged {formatCurrency( extraMembers * - ($plansInfo?.get(billingPlan)?.addons?.member?.price ?? 0) + ($plansInfo?.get(billingPlan)?.usage?.member?.price ?? 0) )} monthly for {extraMembers} team members. This will be reflected in your next invoice. diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte index d63585b52..b92803eae 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte @@ -46,7 +46,7 @@

    From 34f0727d5fc3689fb75c19dcf45113487c41fc35 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 9 Jan 2025 11:48:59 +0530 Subject: [PATCH 25/87] ci: empty commit From 5d84c3b52c8dfcb8640565dbde614fa1256483ae Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 12 Jan 2025 07:28:45 +0000 Subject: [PATCH 26/87] fix types --- .../components/billing/estimatedTotal.svelte | 16 ++++ src/lib/sdk/billing.ts | 80 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/lib/components/billing/estimatedTotal.svelte diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte new file mode 100644 index 000000000..40cac8a00 --- /dev/null +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 85673c615..04cbbaef6 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -65,6 +65,28 @@ export type InvoiceList = { total: number; }; +export type Estimation = { + amount: number; + grossAmount: number; + credits: number; + discount: number; + items: EstimationItem[]; +} + +export type EstimationItem = { + label: string; + value: number; +} + +export type EstimationDeleteOrganization = { + amount: number; + grossAmount: number; + credits: number; + discount: number; + items: EstimationItem[], + unpaidInvoices: Invoice[]; +} + export type Coupon = { $id: string; code: string; @@ -396,6 +418,28 @@ export class Billing { ); } + async estimationCreateOrganization( + billingPlan: string, + couponId: string = null, + invites: Array = [], + ): Promise { + const path = `/organizations`; + const params = { + billingPlan, + couponId, + invites, + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'POST', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async deleteOrganization(organizationId: string): Promise { const path = `/organizations/${organizationId}`; const params = { @@ -412,6 +456,18 @@ export class Billing { ); } + async estimationDeleteOrganization(organizationId: string): Promise { + const path = `/organizations/${organizationId}/predictions/delete-organization`; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + } + ); + } + async getOrganizationPlan(organizationId: string): Promise { const path = `/organizations/${organizationId}/plan`; const uri = new URL(this.client.config.endpoint + path); @@ -475,6 +531,30 @@ export class Billing { params ); } + + async estimationUpdatePlan( + organizationId: string, + billingPlan: string, + couponId: string = null, + invites: Array = [], + ): Promise { + const path = `/organizations/${organizationId}/predictions/update-plan`; + const params = { + billingPlan, + couponId, + invites, + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async cancelDowngrade( organizationId: string ): Promise { From 31b1467a98ab23500f30063582bf1a91744fcb76 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 14 Jan 2025 08:05:18 +0000 Subject: [PATCH 27/87] use new estimation api for update plan and create organiation --- .../billing/discountsApplied.svelte | 21 +++++ .../components/billing/estimatedTotal.svelte | 93 +++++++++++++++++-- src/lib/sdk/billing.ts | 11 ++- .../create-organization/+page.svelte | 12 +++ .../change-plan/+page.svelte | 16 +++- 5 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 src/lib/components/billing/discountsApplied.svelte diff --git a/src/lib/components/billing/discountsApplied.svelte b/src/lib/components/billing/discountsApplied.svelte new file mode 100644 index 000000000..0a815a88c --- /dev/null +++ b/src/lib/components/billing/discountsApplied.svelte @@ -0,0 +1,21 @@ + + +{#if value > 0} + +
    +

    +

    +
    + -{formatCurrency(value)} +
    +{/if} diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 40cac8a00..f39f94f96 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -1,16 +1,97 @@ \ No newline at end of file + $: organizationId && organizationId.length > 0 ? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponId) : getEstimate(billingPlan, collaborators, couponId); + + + +{#if estimation} + +
    + + {#each estimation.items ?? [] as item} + +

    {item.label}

    +

    {formatCurrency(item.value)}

    +
    + {/each} + {#each estimation.discounts ?? [] as item} + + {/each} +
    + +

    + Total due
    +

    +

    + {formatCurrency(estimation.grossAmount)} +

    +
    + + + + +
    +{/if} \ No newline at end of file diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 7305e8abe..f4734d500 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -71,6 +71,9 @@ export type Estimation = { credits: number; discount: number; items: EstimationItem[]; + discounts: EstimationItem[]; + trialDays: number; + trialEndDate: string | undefined; } export type EstimationItem = { @@ -420,7 +423,7 @@ export class Billing { couponId: string = null, invites: Array = [], ): Promise { - const path = `/organizations`; + const path = `/organizations/estimations/create-organization`; const params = { billingPlan, couponId, @@ -428,7 +431,7 @@ export class Billing { }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( - 'POST', + 'patch', uri, { 'content-type': 'application/json' @@ -454,7 +457,7 @@ export class Billing { } async estimationDeleteOrganization(organizationId: string): Promise { - const path = `/organizations/${organizationId}/predictions/delete-organization`; + const path = `/organizations/${organizationId}/estimations/delete-organization`; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( 'patch', @@ -535,7 +538,7 @@ export class Billing { couponId: string = null, invites: Array = [], ): Promise { - const path = `/organizations/${organizationId}/predictions/update-plan`; + const path = `/organizations/${organizationId}/estimations/update-plan`; const params = { billingPlan, couponId, diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 05da83c37..59e84076c 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -9,6 +9,7 @@ PlanSelection, SelectPaymentMethod } from '$lib/components/billing'; + import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import Default from '$lib/components/roles/default.svelte'; import { BillingPlan, Dependencies } from '$lib/constants'; @@ -51,6 +52,7 @@ let billingPlan: BillingPlan = BillingPlan.FREE; let paymentMethodId: string; let collaborators: string[] = []; + let couponId: string | undefined; let couponData: Partial = { code: null, status: null, @@ -233,6 +235,11 @@ id="members" /> + {#if !couponData?.code}

    - -{formatCurrency(value)} + {#if value >= 100} +

    Credits applied

    + {:else} + -{formatCurrency(value)} + {/if} {/if} diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 884fd1763..74d003861 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -8,6 +8,7 @@ EstimatedTotalBox, SelectPaymentMethod } from '$lib/components/billing'; + import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import { BillingPlan, Dependencies } from '$lib/constants'; import { Button, Form, FormList, InputSelect, InputTags, InputText } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; @@ -285,12 +286,11 @@
  • {:else if selectedOrgId}
    - + couponId={couponData.code}> {#if campaign?.template === 'review' && (campaign?.cta || campaign?.claimed || campaign?.unclaimed)}

    {campaign?.cta}

    @@ -303,7 +303,7 @@

    {/if} -
    +
    {/if} From 293eac04ff0a9bfa15228560d92f5d7e88c56edd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 15 Jan 2025 06:50:01 +0000 Subject: [PATCH 29/87] refactor plan selection --- src/lib/components/billing/index.ts | 2 + src/lib/components/billing/selectPlan.svelte | 52 +++++++++++++++++++ src/lib/sdk/billing.ts | 6 ++- .../create-organization/+page.svelte | 8 +-- .../change-plan/+page.svelte | 22 +++----- 5 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 src/lib/components/billing/selectPlan.svelte diff --git a/src/lib/components/billing/index.ts b/src/lib/components/billing/index.ts index 266d217d8..0643e5922 100644 --- a/src/lib/components/billing/index.ts +++ b/src/lib/components/billing/index.ts @@ -7,3 +7,5 @@ export { default as PlanComparisonBox } from './planComparisonBox.svelte'; export { default as EmptyCardCloud } from './emptyCardCloud.svelte'; export { default as CreditsApplied } from './creditsApplied.svelte'; export { default as PlanSelection } from './planSelection.svelte'; +export { default as EstimatedTotal } from './estimatedTotal.svelte'; +export { default as SelectPlan } from './selectPlan.svelte'; \ No newline at end of file diff --git a/src/lib/components/billing/selectPlan.svelte b/src/lib/components/billing/selectPlan.svelte new file mode 100644 index 000000000..ecff50f99 --- /dev/null +++ b/src/lib/components/billing/selectPlan.svelte @@ -0,0 +1,52 @@ + + +{#if billingPlan} +
      + {#each $plansInfo.values() as plan} +
    • + + +
      +

      + {plan.name} + {#if $organization?.billingPlan === plan.$id && !isNewOrg} + Current plan + {/if} +

      +

      + {plan.desc} +

      +

      + {formatCurrency(plan?.price ?? 0)} +

      +
      +
      +
      +
    • + {/each} +
    +{/if} diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index f4734d500..2245053c6 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -296,7 +296,9 @@ export type PlanAddon = { export type Plan = { $id: string; name: string; + desc: string; price: number; + order: number; bandwidth: number; storage: number; webhooks: number; @@ -332,7 +334,7 @@ export type Plan = { supportsCredit: boolean; }; -export type PlansInfo = { +export type PlanList = { plans: Plan[]; total: number; }; @@ -1262,7 +1264,7 @@ export class Billing { ); } - async getPlansInfo(): Promise { + async getPlansInfo(): Promise { const path = `/console/plans`; const params = {}; const uri = new URL(this.client.config.endpoint + path); diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 59e84076c..3b758b0d3 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -6,8 +6,10 @@ import { EstimatedTotalBox, PlanComparisonBox, - PlanSelection, - SelectPaymentMethod + SelectPaymentMethod, + + SelectPlan + } from '$lib/components/billing'; import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; @@ -222,7 +224,7 @@ For more details on our plans, visit our .

    - + {#if billingPlan !== BillingPlan.FREE} $organization.billingPlan; - $: isDowngrade = billingPlan < $organization.billingPlan; + $: isUpgrade = $plansInfo.get(billingPlan).order > $currentPlan.order; + $: isDowngrade = $plansInfo.get(billingPlan).order < $currentPlan.order; $: if (billingPlan !== BillingPlan.FREE) { loadPaymentMethods(); } @@ -300,9 +299,8 @@ >Your contract is not eligible for manual changes. Please reach out to schedule a call or setup a dialog. {/if} - - {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM} + {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} - + {couponId} /> {:else if $organization.billingPlan !== BillingPlan.CUSTOM} {/if} From c5676817c3cfc63e2f8f001576aed2fb32bb1715 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 15 Jan 2025 07:31:04 +0000 Subject: [PATCH 30/87] fix after sync --- src/lib/components/billing/estimatedTotalBox.svelte | 10 +++++----- src/lib/components/billing/selectPlan.svelte | 1 - src/routes/(console)/apply-credit/+page.svelte | 7 +------ src/routes/+layout.ts | 1 - 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index 581e261b5..4d96f87c4 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -28,12 +28,12 @@ $: currentOrgPlan = $plansInfo.get(currentTier); $: unUsedBalances = isScaleUpgrade ? currentOrgPlan.price + - (collaborators?.length ?? 0) * (currentOrgPlan?.addons?.member?.price ?? 0) + (collaborators?.length ?? 0) * (currentOrgPlan?.addons?.seats?.price ?? 0) : isScaleDowngrade ? currentOrgPlan.price : 0; - $: extraSeatsCost = (collaborators?.length ?? 0) * (selectedPlan?.addons?.member?.price ?? 0); + $: extraSeatsCost = (collaborators?.length ?? 0) * (selectedPlan?.addons?.seats?.price ?? 0); $: grossCost = isScaleUpgrade ? selectedPlan.price + extraSeatsCost - unUsedBalances : selectedPlan.price + extraSeatsCost; @@ -59,7 +59,7 @@

    {formatCurrency( isScaleDowngrade - ? (collaborators?.length ?? 0) * (selectedPlan?.addons?.member?.price ?? 0) + ? (collaborators?.length ?? 0) * (selectedPlan?.addons?.seats?.price ?? 0) : extraSeatsCost )}

    @@ -102,11 +102,11 @@ You'll pay {formatCurrency(estimatedTotal)} now, with your first billing cycle starting on {!currentPlan.trialDays + >{!currentOrgPlan.trialDays ? toLocaleDate(billingPayDate.toString()) : toLocaleDate(trialEndDate.toString())}. Once your credits run out, you'll be charged - {formatCurrency(currentPlan.price)} plus usage fees every 30 days. + {formatCurrency(currentOrgPlan.price)} plus usage fees every 30 days.

    diff --git a/src/lib/components/billing/selectPlan.svelte b/src/lib/components/billing/selectPlan.svelte index ecff50f99..4447c17e3 100644 --- a/src/lib/components/billing/selectPlan.svelte +++ b/src/lib/components/billing/selectPlan.svelte @@ -8,7 +8,6 @@ export let billingPlan: string; export let anyOrgFree = false; export let isNewOrg = false; - export let selfService = true; let classes: string = ''; export { classes as class }; diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 502ede7ad..a33884a41 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -3,12 +3,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; - import { - CreditsApplied, - EstimatedTotalBox, - SelectPaymentMethod - } from '$lib/components/billing'; - import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; + import { CreditsApplied, EstimatedTotal, SelectPaymentMethod } from '$lib/components/billing'; import { BillingPlan, Dependencies } from '$lib/constants'; import { Button, Form, FormList, InputSelect, InputTags, InputText } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index eb96a29c2..816166273 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -6,7 +6,6 @@ import { redirect } from '@sveltejs/kit'; import { Dependencies } from '$lib/constants'; import type { LayoutLoad } from './$types'; import { redirectTo } from './store'; -import { isCloud } from '$lib/system'; import { base } from '$app/paths'; import type { Account } from '$lib/stores/user'; import type { AppwriteException } from '@appwrite.io/console'; From 8c9c413e4f0f4611c2730657adbdf490c7db8e09 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 15 Jan 2025 07:54:29 +0000 Subject: [PATCH 31/87] fix coupon --- .../create-organization/+page.svelte | 14 ---------- .../change-plan/+page.svelte | 27 +++++-------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 50ba69eff..03ffc63d7 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -247,15 +247,6 @@ placeholder="Enter coupon code" id="couponId" /> - {#if !couponData?.code} - - {/if} {/if} @@ -265,11 +256,6 @@ {collaborators} {couponId} /> - {:else} {/if} diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 7fd39a911..f300a7bd0 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -4,10 +4,7 @@ import { page } from '$app/stores'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { Alert } from '$lib/components'; - import { - PlanComparisonBox, - SelectPaymentMethod - } from '$lib/components/billing'; + import { PlanComparisonBox, SelectPaymentMethod } from '$lib/components/billing'; import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import PlanExcess from '$lib/components/billing/planExcess.svelte'; import SelectPlan from '$lib/components/billing/selectPlan.svelte'; @@ -299,10 +296,7 @@ >Your contract is not eligible for manual changes. Please reach out to schedule a call or setup a dialog. {/if} - + {#if isDowngrade} {#if billingPlan === BillingPlan.FREE} @@ -338,20 +332,13 @@ validityMessage="Invalid email address" id="members" /> +
    - {#if !couponData?.code} - - {/if} {/if} - - - {#if isDowngrade} Date: Wed, 15 Jan 2025 08:59:36 +0000 Subject: [PATCH 32/87] fix history not showing --- .../organization-[organization]/billing/paymentHistory.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte index 8a50a4efc..5ee85510c 100644 --- a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte @@ -62,8 +62,7 @@ request(); } - -{#if $organization?.billingPlan === BillingPlan.FREE && invoiceList.total > 0} +{#if $organization?.billingPlan !== BillingPlan.FREE && invoiceList.total > 0} Payment history From dee3b530debaabfebae519b517eff22894d2a7bb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 15 Jan 2025 09:33:57 +0000 Subject: [PATCH 33/87] fix summary --- src/lib/sdk/billing.ts | 4 +++- .../billing/+page.svelte | 1 + .../billing/planSummary.svelte | 18 ++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index d3078688c..0d0824561 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -171,10 +171,12 @@ export type Aggregation = { * Total amount of the invoice. */ amount: number; + additionalMembers: number; + /** * Price for additional members */ - additionalMembers: number; + additionalMemberAmount: number; /** * Total storage usage. */ diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index 25b35dc32..cc0fb72d1 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -123,6 +123,7 @@ creditList={data?.creditList} members={data?.members} currentPlan={data?.aggregationBillingPlan} + currentAggregation={data?.billingAggregation} currentInvoice={data?.billingInvoice} /> diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index a2b3f05ce..3d8a89c6d 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -5,7 +5,7 @@ import { toLocaleDate } from '$lib/helpers/date'; import { plansInfo, tierToPlan, upgradeURL } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; - import type { CreditList, Invoice, Plan } from '$lib/sdk/billing'; + import type { Aggregation, CreditList, Invoice, Plan } from '$lib/sdk/billing'; import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; import { BillingPlan } from '$lib/constants'; @@ -18,17 +18,16 @@ export let currentPlan: Plan; export let creditList: CreditList; export let currentInvoice: Invoice | undefined = undefined; + export let currentAggregation: Aggregation | undefined = undefined let showCancel: boolean = false; - const extraMembers = members.total > 1 ? members.total - 1 : 0; const availableCredit = creditList.available; const today = new Date(); const isTrial = new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 && $plansInfo.get($organization.billingPlan)?.trialDays; const extraUsage = currentInvoice ? currentInvoice.amount - currentPlan?.price : 0; - const extraAddons = currentInvoice ? currentInvoice.usage?.length : 0; {#if $organization} @@ -64,7 +63,7 @@ Add-ons{extraMembers ? extraAddons + 1 : extraAddons} + >{currentAggregation.additionalMembers > 0 ? currentInvoice.usage.length + 1 : currentInvoice.usage.length}
    @@ -78,7 +77,7 @@
      - {#if extraMembers} + {#if currentAggregation.additionalMembers}
    • @@ -86,15 +85,14 @@
      {formatCurrency( - extraMembers * - (currentPlan?.addons?.seats?.price ?? 0) + currentAggregation.additionalMemberAmount )}
      - {extraMembers} + {currentAggregation.additionalMembers}
    • @@ -102,10 +100,10 @@ {#if currentInvoice?.usage} {#each currentInvoice.usage as excess, i}
    • 0 ? 'u-padding-block-8' : 'u-padding-block-start-8'}" - class:u-sep-block-start={i > 0 || extraMembers}> + class:u-sep-block-start={i > 0 || currentAggregation.additionalMembers > 0}> {#if ['storage', 'bandwidth'].includes(excess.name)} {@const excessValue = humanFileSize( excess.value From 654718d019cd4b41ae2c73e116e9b072cbd406f3 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 19 Jan 2025 07:31:42 +0000 Subject: [PATCH 34/87] fix errors --- .../components/billing/estimatedTotal.svelte | 23 +++++++++---------- .../(console)/apply-credit/+page.svelte | 1 + .../create-organization/+page.svelte | 2 +- .../change-plan/+page.svelte | 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index f39f94f96..fa7a3b34e 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -1,4 +1,6 @@ -{#if estimation} +{#if isDowngrade} +
      + +

      + Your change will take effect once your current billing cycle ends on {toLocaleDate($organization.billingNextInvoiceDate)}. +

      +
      + +{:else if estimation}
      { if ($page.url.searchParams.has('coupon')) { - const coupon = $page.url.searchParams.get('coupon'); - try { - const response = await sdk.forConsole.billing.getCoupon(coupon); - couponData = response; - } catch (e) { - couponData = { - code: null, - status: null, - credits: null - }; - } + couponId = $page.url.searchParams.get('coupon'); } if ($page.url.searchParams.has('name')) { name = $page.url.searchParams.get('name'); @@ -152,7 +142,7 @@ billingPlan, paymentMethodId, null, - couponData?.code, + couponId, collaborators, billingBudget, taxId diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 025d73986..35c358b60 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -360,12 +360,22 @@ {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} {:else if $organization.billingPlan !== BillingPlan.CUSTOM} + {#if isDowngrade} + + {/if} {/if} From d64de9039de649249c402b370cfc2626045cffa8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 20 Jan 2025 06:41:18 +0000 Subject: [PATCH 36/87] improve estimatie total --- .../components/billing/estimatedTotal.svelte | 162 +++++++++--------- .../change-plan/+page.svelte | 30 ++-- 2 files changed, 102 insertions(+), 90 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index fef543608..1af444fd3 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -1,21 +1,17 @@ -{#if isDowngrade} -
      - -

      - Your change will take effect once your current billing cycle ends on {toLocaleDate($organization.billingNextInvoiceDate)}. -

      -
      - +{#if error.length} + + + {error} + + {:else if estimation} - -
      - - {#each estimation.items ?? [] as item} +
      + + {#each estimation.items ?? [] as item} + +

      {item.label}

      +

      {formatCurrency(item.value)}

      +
      + {/each} + {#each estimation.discounts ?? [] as item} + + {/each} +
      -

      {item.label}

      -

      {formatCurrency(item.value)}

      +

      + Total due
      +

      +

      + {formatCurrency(estimation.grossAmount)} +

      - {/each} - {#each estimation.discounts ?? [] as item} - - {/each} -
      - -

      - Total due
      -

      -

      - {formatCurrency(estimation.grossAmount)} -

      -
      -

      - You'll pay {formatCurrency(estimation.amount)} now. Once your credits run out, you'll be charged - {formatCurrency(estimation.amount)} every 30 days. -

      +

      + You'll pay {formatCurrency(estimation.amount)} now. Once + your credits run out, you'll be charged + {formatCurrency(estimation.amount)} every 30 days. +

      - - - {#if budgetEnabled} -
      - -
      - {/if} -
      -
      -
      -{/if} \ No newline at end of file + + + {#if budgetEnabled} +
      + +
      + {/if} +
      +
      +
      +{/if} diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 35c358b60..baf1f44cc 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -21,6 +21,7 @@ InputTextarea, Label } from '$lib/elements/forms'; + import { toLocaleDate } from '$lib/helpers/date.js'; import { formatCurrency } from '$lib/helpers/numbers'; import { WizardSecondaryContainer, @@ -76,6 +77,7 @@ let taxId: string; let billingBudget: number; let showCreditModal = false; + let error: string = ''; let feedbackDowngradeReason: string; let feedbackMessage: string; @@ -83,6 +85,7 @@ onMount(async () => { if ($page.url.searchParams.has('code')) { + couponId = $page.url.searchParams.get('code'); const coupon = $page.url.searchParams.get('code'); try { const response = await sdk.forConsole.billing.getCoupon(coupon); @@ -275,7 +278,7 @@ $: if (billingPlan !== BillingPlan.FREE) { loadPaymentMethods(); } - $: isButtonDisabled = $organization.billingPlan === billingPlan; + $: isButtonDisabled = $organization.billingPlan === billingPlan || error.length > 0; @@ -360,21 +363,26 @@ {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} {:else if $organization.billingPlan !== BillingPlan.CUSTOM} {#if isDowngrade} - +
      + +

      + Your change will take effect once your current billing cycle ends on {toLocaleDate($organization.billingNextInvoiceDate)}. +

      +
      {/if} {/if} @@ -386,7 +394,7 @@ From e696d0c05b667ef1478ae01819f31fffe6391315 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 20 Jan 2025 06:41:36 +0000 Subject: [PATCH 37/87] check estimation before delete flow --- .../settings/+page.svelte | 2 + .../deleteOrganizationEstimation.svelte | 31 +++ .../settings/deleteOrganizationModal.svelte | 203 +++++++++--------- .../settings/invoicesTable.svelte | 137 ++++++++++++ 4 files changed, 276 insertions(+), 97 deletions(-) create mode 100644 src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte create mode 100644 src/routes/(console)/organization-[organization]/settings/invoicesTable.svelte diff --git a/src/routes/(console)/organization-[organization]/settings/+page.svelte b/src/routes/(console)/organization-[organization]/settings/+page.svelte index 98b236e6d..361a52d73 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.svelte +++ b/src/routes/(console)/organization-[organization]/settings/+page.svelte @@ -15,10 +15,12 @@ import { isCloud } from '$lib/system'; import Baa from './BAA.svelte'; import Soc2 from './Soc2.svelte'; + import DeleteOrganizationEstimation from './deleteOrganizationEstimation.svelte'; export let data; let name: string; let showDelete = false; + let showDeleteEstimation = false; onMount(() => { name = $organization.name; diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte new file mode 100644 index 000000000..3d6a967b9 --- /dev/null +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte @@ -0,0 +1,31 @@ + + +{#if error} + + {error} + +{/if} +{#if estimation} + {#if estimation.unpaidInvoices?.length > 0} + + + You have a unpaid invoices. Please settle them first in order to delete team. + + + + + {/if} +{/if} + +{#if $selectedInvoice} + +{/if} diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index 78c9e2946..26a338491 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -1,5 +1,5 @@
      @@ -108,103 +124,96 @@ icon="exclamation" state="warning" headerDivider={false}> - {#if upcomingInvoice} - - - You have a pending {formatCurrency(upcomingInvoice.grossAmount)} invoice for your - {tierToPlan(upcomingInvoice.plan).name} plan - -

      - By proceeding, your invoice will be processed within the hour. Upon successful - payment, your organization will be deleted. -

      -
      - {/if} + {#if estimation} + + {:else} +

      + {#if $projects.total > 0} + The following projects and all data associated with {$organization.name} + will be permanently deleted. This action is irreversible. + {:else} + All data associated with {$organization.name} will be permanently + deleted. + This action is irreversible. + {/if} +

      -

      {#if $projects.total > 0} - The following projects and all data associated with {$organization.name} will - be permanently deleted. This action is irreversible. - {:else} - All data associated with {$organization.name} will be permanently deleted. - This action is irreversible. +

      + + {#each tabs as { name, label, total }} + (selectedTab = name)}> + {label.desktop} ({total}) + + {/each} + + + + + {#each tabData.headers as header} + {header} + {/each} + + + {#each tabData.rows as row} + + {#each row.cells as cell} + {cell} + {/each} + + {/each} + + +
      +
      + + {#each tabs as { name, label, total }} + (selectedTab = name)}> + {label.mobile} ({total}) + + {/each} + + + + + {#each tabData.headers as header, index} + {header} + {/each} + + + {#each tabData.rows as row} + + {#each row.cells as cell, index} + {cell} + {/each} + + {/each} + + +
      {/if} -

      - {#if $projects.total > 0} -
      - - {#each tabs as { name, label, total }} - (selectedTab = name)}> - {label.desktop} ({total}) - - {/each} - - - - - {#each tabData.headers as header} - {header} - {/each} - - - {#each tabData.rows as row} - - {#each row.cells as cell} - {cell} - {/each} - - {/each} - - -
      -
      - - {#each tabs as { name, label, total }} - (selectedTab = name)}> - {label.mobile} ({total}) - - {/each} - - - - - {#each tabData.headers as header, index} - {header} - {/each} - - - {#each tabData.rows as row} - - {#each row.cells as cell, index} - {cell} - {/each} - - {/each} - - -
      + + + {/if} - - - - + . +
    • + + + {:else} + + {status === 'requires_authentication' ? 'failed' : status} + + {/if} + + + {formatCurrency(invoice.grossAmount)} + + + + + + (showDropdown[i] = !showDropdown[i])} + event="view_invoice"> + View invoice + + { + showDropdown[i] = !showDropdown[i]; + }} + event="download_invoice"> + Download PDF + + {#if status === 'overdue' || status === 'failed'} + { + retryPayment(invoice); + showDropdown[i] = !showDropdown[i]; + trackEvent(`click_retry_payment`, { + from: 'button', + source: 'billing_invoice_menu' + }); + }}> + Retry payment + + {/if} + + + + + {/each} + + From 2f36ff286bc2d4aceec436af7ab3edefeccc2c09 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 20 Jan 2025 06:42:13 +0000 Subject: [PATCH 38/87] remove unused code --- .../(console)/organization-[organization]/settings/+page.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/settings/+page.svelte b/src/routes/(console)/organization-[organization]/settings/+page.svelte index 361a52d73..98b236e6d 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.svelte +++ b/src/routes/(console)/organization-[organization]/settings/+page.svelte @@ -15,12 +15,10 @@ import { isCloud } from '$lib/system'; import Baa from './BAA.svelte'; import Soc2 from './Soc2.svelte'; - import DeleteOrganizationEstimation from './deleteOrganizationEstimation.svelte'; export let data; let name: string; let showDelete = false; - let showDeleteEstimation = false; onMount(() => { name = $organization.name; From 09ba6186d6c3a4949fd970c4ebe94304dde43b94 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 20 Jan 2025 08:26:04 +0000 Subject: [PATCH 39/87] fix check --- .../settings/deleteOrganizationModal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index 26a338491..96073a046 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -124,7 +124,7 @@ icon="exclamation" state="warning" headerDivider={false}> - {#if estimation} + {#if estimation &&( estimation.unpaidInvoices.length > 0 || estimation.grossAmount > 0)} {:else}

      From 0cb3512f432be3737b7d785867940370c68861be Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:16:30 +0000 Subject: [PATCH 40/87] Fix review comments and errors --- .../components/billing/estimatedTotal.svelte | 36 +++++++++---------- .../(console)/apply-credit/+page.svelte | 2 +- .../create-organization/+page.svelte | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 1af444fd3..06e7cc48e 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -4,6 +4,7 @@ import type { Estimation } from '$lib/sdk/billing'; import { sdk } from '$lib/stores/sdk'; import Alert from '../alert.svelte'; + import Card from '../card.svelte'; import DiscountsApplied from './discountsApplied.svelte'; export let organizationId: string | undefined = undefined; @@ -11,29 +12,32 @@ export let collaborators: string[]; export let couponId: string; export let fixedCoupon = false; - export let error: string = ''; + export let error = ''; export let billingBudget: number; let budgetEnabled = false; - var estimation: Estimation; + let estimation: Estimation; - let getEstimate = async (billingPlan, collaborators, couponId) => { + async function getEstimate(billingPlan: string, collaborators: string[], couponId: string) { try { error = ''; estimation = await sdk.forConsole.billing.estimationCreateOrganization( billingPlan, - couponId == '' ? null : couponId, + couponId === '' ? null : couponId, collaborators ?? [] ); } catch (e) { - // error = e.message; - console.log(e); } - }; + } - let getUpdatePlanEstimate = async (organizationId, billingPlan, collaborators, couponId) => { + async function getUpdatePlanEstimate( + organizationId: string, + billingPlan: string, + collaborators: string[], + couponId: string | undefined + ) { try { error = ''; estimation = await sdk.forConsole.billing.estimationUpdatePlan( @@ -44,11 +48,10 @@ ); } catch (e) { error = e.message; - console.log(e); } - }; + } - $: organizationId && organizationId.length > 0 + $: organizationId ? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponId) : getEstimate(billingPlan, collaborators, couponId); @@ -60,10 +63,7 @@ {:else if estimation} -

      + {#each estimation.items ?? [] as item} @@ -85,9 +85,9 @@

      - You'll pay {formatCurrency(estimation.amount)} now. Once + You'll pay {formatCurrency(estimation.grossAmount)} now. Once your credits run out, you'll be charged - {formatCurrency(estimation.amount)} every 30 days. + {formatCurrency(estimation.grossAmount)} every 30 days.

      @@ -110,5 +110,5 @@ {/if} -
      + {/if} diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 588bb5697..f9cb293e3 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -288,7 +288,7 @@
      diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index b1a8f28c8..b07f1eac3 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -142,7 +142,7 @@ billingPlan, paymentMethodId, null, - couponId, + couponId && couponId.length > 0 ? couponId : null, collaborators, billingBudget, taxId From dda2fd8792402d9563d8690310df06c999694b52 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:19:49 +0000 Subject: [PATCH 41/87] update review comments --- src/lib/components/billing/estimatedTotal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 06e7cc48e..0199e0ba9 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -77,7 +77,7 @@

      - Total due
      + Total due

      {formatCurrency(estimation.grossAmount)} From 8e994cba4ed814d684e3871f30ccfafd6bcb7326 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:21:08 +0000 Subject: [PATCH 42/87] remove old component --- .../billing/estimatedTotalBox.svelte | 132 ------------------ src/lib/components/billing/index.ts | 1 - 2 files changed, 133 deletions(-) delete mode 100644 src/lib/components/billing/estimatedTotalBox.svelte diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte deleted file mode 100644 index 4d96f87c4..000000000 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ /dev/null @@ -1,132 +0,0 @@ - - -

      - -
      -

      {selectedPlan.name} plan

      -

      {formatCurrency(selectedPlan.price)}

      -
      - -
      -

      Additional seats ({collaborators?.length})

      -

      - {formatCurrency( - isScaleDowngrade - ? (collaborators?.length ?? 0) * (selectedPlan?.addons?.seats?.price ?? 0) - : extraSeatsCost - )} -

      -
      - - {#if isScaleUpgrade} - {@const currentPlanName = currentOrgPlan.name} -
      -
      - Unused {currentPlanName} plan balance - - -
      -

      -{formatCurrency(unUsedBalances)}

      -
      - {/if} - - {#if couponData?.status === 'active'} - - {/if} -
      -
      -

      - Upcoming charge
      Due on {!selectedPlan.trialDays - ? toLocaleDate(billingPayDate.toString()) - : toLocaleDate(trialEndDate.toString())} -

      -

      - {formatCurrency(estimatedTotal)} -

      -
      - -

      - You'll pay {formatCurrency(estimatedTotal)} now, with your first - billing cycle starting on - {!currentOrgPlan.trialDays - ? toLocaleDate(billingPayDate.toString()) - : toLocaleDate(trialEndDate.toString())}. Once your credits run out, you'll be charged - {formatCurrency(currentOrgPlan.price)} plus usage fees every 30 days. -

      - - - - {#if budgetEnabled} -
      - -
      - {/if} -
      -
      -
      diff --git a/src/lib/components/billing/index.ts b/src/lib/components/billing/index.ts index 0643e5922..f58efa250 100644 --- a/src/lib/components/billing/index.ts +++ b/src/lib/components/billing/index.ts @@ -2,7 +2,6 @@ export { default as PaymentBoxes } from './paymentBoxes.svelte'; export { default as CouponInput } from './couponInput.svelte'; export { default as SelectPaymentMethod } from './selectPaymentMethod.svelte'; export { default as UsageRates } from './usageRates.svelte'; -export { default as EstimatedTotalBox } from './estimatedTotalBox.svelte'; export { default as PlanComparisonBox } from './planComparisonBox.svelte'; export { default as EmptyCardCloud } from './emptyCardCloud.svelte'; export { default as CreditsApplied } from './creditsApplied.svelte'; From 6e6daca8b49b1d0ec14ef27ec132dcf867554347 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:26:09 +0000 Subject: [PATCH 43/87] removed unused change --- src/lib/stores/stripe.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index e62110d20..58edfd431 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -117,8 +117,7 @@ export async function confirmPayment( orgId: string, clientSecret: string, paymentMethodId: string, - route?: string, - returnError: boolean = false + route?: string ) { try { const url = @@ -134,9 +133,6 @@ export async function confirmPayment( } }); if (error) { - if (returnError) { - return error; - } throw error.message; } } catch (e) { From 27c545325507fb08743a812c8f5a35e10baa5c17 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:36:27 +0000 Subject: [PATCH 44/87] more review fixes --- src/routes/(console)/create-organization/+page.svelte | 2 +- .../organization-[organization]/billing/+page.ts | 8 ++------ ...lDowngradeModel.svelte => cancelDowngradeModal.svelte} | 0 .../billing/planSummary.svelte | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) rename src/routes/(console)/organization-[organization]/billing/{cancelDowngradeModel.svelte => cancelDowngradeModal.svelte} (100%) diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index b07f1eac3..914bddcb5 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -105,7 +105,7 @@ async function validate(organizationId: string, invites: string[]) { try { - let org = await sdk.forConsole.billing.validateOrganization(organizationId, invites); + const org = await sdk.forConsole.billing.validateOrganization(organizationId, invites); if (isOrganization(org)) { await preloadData(`${base}/console/organization-${org.$id}`); await goto(`${base}/console/organization-${org.$id}`); diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index 0d7f48a37..ef01264d7 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -34,12 +34,6 @@ export const load: PageLoad = async ({ parent, depends }) => { } const billingInvoiceId = (organization as Organization)?.billingInvoiceId; - let billingInvoice = null; - try { - billingInvoice = await sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId) - } catch (e) { - // ignore error - } const [ @@ -47,12 +41,14 @@ export const load: PageLoad = async ({ parent, depends }) => { addressList, billingAddress, creditList, + billingInvoice, aggregationBillingPlan, ] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), sdk.forConsole.billing.listAddresses(), billingAddressPromise, sdk.forConsole.billing.listCredits(organization.$id), + sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId), sdk.forConsole.billing.getPlan(billingAggregation?.plan ?? organization.billingPlan), ]); diff --git a/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte b/src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte similarity index 100% rename from src/routes/(console)/organization-[organization]/billing/cancelDowngradeModel.svelte rename to src/routes/(console)/organization-[organization]/billing/cancelDowngradeModal.svelte diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 3d8a89c6d..f88992b86 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -12,7 +12,7 @@ import { trackEvent } from '$lib/actions/analytics'; import { tooltip } from '$lib/actions/tooltip'; import { type Models } from '@appwrite.io/console'; - import CancelDowngradeModel from './cancelDowngradeModel.svelte'; + import CancelDowngradeModel from './cancelDowngradeModal.svelte'; export let members: Models.MembershipList; export let currentPlan: Plan; From cc0f655a56437c9565e8385183724f143f0474f4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:39:14 +0000 Subject: [PATCH 45/87] fix component --- .../change-plan/+page.svelte | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index baf1f44cc..de8a9f63e 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -9,6 +9,7 @@ import PlanExcess from '$lib/components/billing/planExcess.svelte'; import SelectPlan from '$lib/components/billing/selectPlan.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; + import Card from '$lib/components/card.svelte'; import Default from '$lib/components/roles/default.svelte'; import { BillingPlan, Dependencies, feedbackDowngradeOptions } from '$lib/constants'; import { @@ -363,26 +364,20 @@ {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} {:else if $organization.billingPlan !== BillingPlan.CUSTOM} {#if isDowngrade} -
      - -

      - Your change will take effect once your current billing cycle ends on {toLocaleDate($organization.billingNextInvoiceDate)}. -

      -
      + + Your change will take effect once your current billing cycle ends on {toLocaleDate($organization.billingNextInvoiceDate)}. + {/if} {/if} @@ -394,7 +389,7 @@ From f3a28cd6685025b95965af7a9580330bd8259815 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:42:43 +0000 Subject: [PATCH 46/87] remove duplicates --- src/lib/stores/billing.ts | 6 +++++- src/routes/(console)/create-organization/+page.svelte | 6 +----- .../organization-[organization]/change-plan/+page.svelte | 6 +----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 6604469cb..ed2854ad9 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -1,7 +1,7 @@ import { page } from '$app/stores'; import { derived, get, writable } from 'svelte/store'; import { sdk } from './sdk'; -import { organization, type Organization } from './organization'; +import { organization, type Organization, type OrganizationError } from './organization'; import type { InvoiceList, AddressesList, @@ -485,3 +485,7 @@ export function calculateResourceSurplus(total: number, limit: number, limitUnit const realLimit = (limitUnit ? sizeToBytes(limit, limitUnit) : limit) || Infinity; return total > realLimit ? total - realLimit : 0; } + +export function isOrganization(org: Organization | OrganizationError): org is Organization { + return (org as Organization).$id !== undefined; +} \ No newline at end of file diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 914bddcb5..e84f8e197 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -21,7 +21,7 @@ WizardSecondaryFooter } from '$lib/layout'; import type { Coupon, PaymentList } from '$lib/sdk/billing'; - import { tierToPlan } from '$lib/stores/billing'; + import { isOrganization, tierToPlan } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { organizationList, @@ -99,10 +99,6 @@ paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null; } - function isOrganization(org: Organization | OrganizationError): org is Organization { - return (org as Organization).$id !== undefined; - } - async function validate(organizationId: string, invites: string[]) { try { const org = await sdk.forConsole.billing.validateOrganization(organizationId, invites); diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index de8a9f63e..8adad4999 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -30,7 +30,7 @@ WizardSecondaryFooter } from '$lib/layout'; import { type Coupon, type PaymentList } from '$lib/sdk/billing'; - import { plansInfo, tierToPlan, type Tier } from '$lib/stores/billing'; + import { isOrganization, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { currentPlan, @@ -182,10 +182,6 @@ } } - function isOrganization(org: Organization | OrganizationError): org is Organization { - return (org as Organization).$id !== undefined; - } - async function validate(organizationId: string, invites: string[]) { try { let org = await sdk.forConsole.billing.validateOrganization(organizationId, invites); From acb814b5ca9f7e956c8ff01eb7d8d88a4fccf45d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:44:37 +0000 Subject: [PATCH 47/87] fix function definiation --- .../settings/deleteOrganizationModal.svelte | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index 96073a046..28e43d5aa 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -100,8 +100,8 @@ organizationName = ''; } - let getEstimate = async () => { - if(isCloud) { + async function getEstimate() { + if (isCloud) { try { error = ''; estimation = await sdk.forConsole.billing.estimationDeleteOrganization( @@ -109,10 +109,9 @@ ); } catch (e) { error = e.message; - console.log(e); } } - }; + }
      @@ -124,7 +123,7 @@ icon="exclamation" state="warning" headerDivider={false}> - {#if estimation &&( estimation.unpaidInvoices.length > 0 || estimation.grossAmount > 0)} + {#if estimation && (estimation.unpaidInvoices.length > 0 || estimation.grossAmount > 0)} {:else}

      From dccfb2885a39e024ce368bbb3b9cdf7183cd0ca6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 06:55:39 +0000 Subject: [PATCH 48/87] fix new org error --- .../billing/+page.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index ef01264d7..2bf2039c7 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -24,31 +24,36 @@ export const load: PageLoad = async ({ parent, depends }) => { .catch(() => null) : null; - const billingAggregationId = (organization as Organization)?.billingAggregationId; - + /** + * Needed to keep this out of Promise.all, as when organization is + * initially created, these might return 404 + * - can be removed later once that is fixed in back-end + */ let billingAggregation = null; try { - billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, billingAggregationId); + billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, (organization as Organization)?.billingAggregationId); } catch (e) { // ignore error } - const billingInvoiceId = (organization as Organization)?.billingInvoiceId; - + let billingInvoice = null; + try { + billingInvoice = await sdk.forConsole.billing.getInvoice(organization.$id, (organization as Organization)?.billingInvoiceId); + } catch (e) { + // ignore error + } const [ paymentMethods, addressList, billingAddress, creditList, - billingInvoice, aggregationBillingPlan, ] = await Promise.all([ sdk.forConsole.billing.listPaymentMethods(), sdk.forConsole.billing.listAddresses(), billingAddressPromise, sdk.forConsole.billing.listCredits(organization.$id), - sdk.forConsole.billing.getInvoice(organization.$id, billingInvoiceId), sdk.forConsole.billing.getPlan(billingAggregation?.plan ?? organization.billingPlan), ]); From 609cf5fe8b2475b55efa09694c6f7598b55ce5e2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 26 Jan 2025 07:10:41 +0000 Subject: [PATCH 49/87] fix button state --- src/routes/(console)/create-organization/+page.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index e84f8e197..0edd44b72 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -63,6 +63,7 @@ let billingBudget: number; let showCreditModal = false; + let error = ''; onMount(async () => { if ($page.url.searchParams.has('coupon')) { @@ -237,6 +238,7 @@ {#if billingPlan !== BillingPlan.FREE} formComponent.triggerSubmit()} - disabled={$isSubmitting}> + disabled={$isSubmitting || error.length > 0}> Create organization From 4fb76da48de44ef18a689a2d95f9702dafef2245 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 27 Jan 2025 08:57:40 +0000 Subject: [PATCH 50/87] fix alert --- .../components/billing/estimatedTotal.svelte | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 0199e0ba9..5d2ab12b7 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -21,12 +21,12 @@ async function getEstimate(billingPlan: string, collaborators: string[], couponId: string) { try { - error = ''; estimation = await sdk.forConsole.billing.estimationCreateOrganization( billingPlan, couponId === '' ? null : couponId, collaborators ?? [] ); + error = ''; } catch (e) { error = e.message; } @@ -56,15 +56,15 @@ : getEstimate(billingPlan, collaborators, couponId); -{#if error.length} - - - {error} - - -{:else if estimation} +{#if estimation || error.length} - + {#if error.length} +

      + {error} +

      + {/if} + + {#if estimation} {#each estimation.items ?? [] as item}

      {item.label}

      @@ -76,19 +76,18 @@ {/each}
      -

      - Total due -

      +

      Total due

      {formatCurrency(estimation.grossAmount)}

      - You'll pay {formatCurrency(estimation.grossAmount)} now. Once - your credits run out, you'll be charged + You'll pay {formatCurrency(estimation.grossAmount)} now. + Once your credits run out, you'll be charged {formatCurrency(estimation.grossAmount)} every 30 days.

      + {/if} Date: Tue, 28 Jan 2025 05:30:23 +0000 Subject: [PATCH 51/87] fix spacing --- src/lib/components/billing/discountsApplied.svelte | 3 +-- src/lib/components/billing/estimatedTotal.svelte | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/components/billing/discountsApplied.svelte b/src/lib/components/billing/discountsApplied.svelte index 028854d27..d35b3a168 100644 --- a/src/lib/components/billing/discountsApplied.svelte +++ b/src/lib/components/billing/discountsApplied.svelte @@ -1,5 +1,4 @@ {#if estimation || error.length} - + {#if error.length}

      {error} @@ -85,7 +85,7 @@

      You'll pay {formatCurrency(estimation.grossAmount)} now. Once your credits run out, you'll be charged - {formatCurrency(estimation.grossAmount)} every 30 days. + {formatCurrency(estimation.amount)} every 30 days.

      {/if} From 429c7da66fd8e822fbca8a6d5b75a7bf62c72dd5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 28 Jan 2025 06:06:19 +0000 Subject: [PATCH 52/87] bring back credits modal --- .../billing/discountsApplied.svelte | 23 +++++++++ .../components/billing/estimatedTotal.svelte | 49 ++++++++++--------- src/lib/sdk/billing.ts | 3 +- .../change-plan/+page.svelte | 22 +++++---- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/lib/components/billing/discountsApplied.svelte b/src/lib/components/billing/discountsApplied.svelte index d35b3a168..82ae0907e 100644 --- a/src/lib/components/billing/discountsApplied.svelte +++ b/src/lib/components/billing/discountsApplied.svelte @@ -1,8 +1,15 @@ {#if value > 0} @@ -14,6 +21,22 @@ {label}

      + {#if !fixedCoupon && label.toLowerCase() === 'credits'} + + {/if}
      {#if value >= 100}

      Credits applied

      diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 3afd78945..ce9a3558c 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -1,7 +1,7 @@ diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 0edd44b72..d3de145b8 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -3,13 +3,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; - import { - PlanComparisonBox, - SelectPaymentMethod, - - SelectPlan - - } from '$lib/components/billing'; + import { PlanComparisonBox, SelectPaymentMethod, SelectPlan } from '$lib/components/billing'; import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import Default from '$lib/components/roles/default.svelte'; @@ -227,23 +221,27 @@ id="members" /> - + {#if !couponData?.code} + + {/if} {/if} {#if billingPlan !== BillingPlan.FREE} + {couponData} /> {:else} {/if} From 269bf9f01e2ff0fa4d5ec51e8dfe4ca6d989c158 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 29 Jan 2025 04:05:33 +0000 Subject: [PATCH 56/87] fix formatting --- .../billing/discountsApplied.svelte | 2 +- .../components/billing/estimatedTotal.svelte | 24 +++++- src/lib/components/billing/index.ts | 2 +- src/lib/components/billing/selectPlan.svelte | 2 +- src/lib/sdk/billing.ts | 75 +++++++------------ src/lib/stores/billing.ts | 5 +- .../create-organization/+page.svelte | 2 - .../billing/+page.ts | 49 ++++++------ .../billing/planSummary.svelte | 15 ++-- 9 files changed, 89 insertions(+), 87 deletions(-) diff --git a/src/lib/components/billing/discountsApplied.svelte b/src/lib/components/billing/discountsApplied.svelte index 82ae0907e..433d02ecf 100644 --- a/src/lib/components/billing/discountsApplied.svelte +++ b/src/lib/components/billing/discountsApplied.svelte @@ -1,6 +1,6 @@ {#if estimation || error.length} diff --git a/src/lib/components/billing/index.ts b/src/lib/components/billing/index.ts index f58efa250..1cc70d3d9 100644 --- a/src/lib/components/billing/index.ts +++ b/src/lib/components/billing/index.ts @@ -7,4 +7,4 @@ export { default as EmptyCardCloud } from './emptyCardCloud.svelte'; export { default as CreditsApplied } from './creditsApplied.svelte'; export { default as PlanSelection } from './planSelection.svelte'; export { default as EstimatedTotal } from './estimatedTotal.svelte'; -export { default as SelectPlan } from './selectPlan.svelte'; \ No newline at end of file +export { default as SelectPlan } from './selectPlan.svelte'; diff --git a/src/lib/components/billing/selectPlan.svelte b/src/lib/components/billing/selectPlan.svelte index 4447c17e3..8aae2f0ac 100644 --- a/src/lib/components/billing/selectPlan.svelte +++ b/src/lib/components/billing/selectPlan.svelte @@ -19,7 +19,7 @@ = [], + invites: Array = [] ): Promise { const path = `/organizations/estimations/create-organization`; const params = { billingPlan, couponId, - invites, + invites }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( @@ -466,40 +465,30 @@ export class Billing { ); } - async estimationDeleteOrganization(organizationId: string): Promise { + async estimationDeleteOrganization( + organizationId: string + ): Promise { const path = `/organizations/${organizationId}/estimations/delete-organization`; const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - } - ); + return await this.client.call('patch', uri, { + 'content-type': 'application/json' + }); } async getOrganizationPlan(organizationId: string): Promise { const path = `/organizations/${organizationId}/plan`; const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - } - ); + return await this.client.call('get', uri, { + 'content-type': 'application/json' + }); } async getPlan(planId: string): Promise { const path = `/console/plans/${planId}`; const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - } - ); + return await this.client.call('get', uri, { + 'content-type': 'application/json' + }); } async getRoles(organizationId: string): Promise { @@ -546,13 +535,13 @@ export class Billing { organizationId: string, billingPlan: string, couponId: string = null, - invites: Array = [], + invites: Array = [] ): Promise { const path = `/organizations/${organizationId}/estimations/update-plan`; const params = { billingPlan, couponId, - invites, + invites }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( @@ -565,18 +554,12 @@ export class Billing { ); } - async cancelDowngrade( - organizationId: string - ): Promise { + async cancelDowngrade(organizationId: string): Promise { const path = `/organizations/${organizationId}/plan/cancel`; const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - } - ); + return await this.client.call('patch', uri, { + 'content-type': 'application/json' + }); } async updateBudget( diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 341e302bb..d4affddb6 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -275,7 +275,8 @@ export async function checkForUsageLimit(org: Organization) { const members = org.total; const plan = get(plansInfo)?.get(org.billingPlan); - const membersOverflow = (members - 1) > plan.addons.seats.limit ? members - (plan.addons.seats.limit || members) : 0; + const membersOverflow = + members - 1 > plan.addons.seats.limit ? members - (plan.addons.seats.limit || members) : 0; if (resources.some((r) => r.value >= 100) || membersOverflow > 0) { readOnly.set(true); @@ -490,4 +491,4 @@ export function calculateResourceSurplus(total: number, limit: number, limitUnit export function isOrganization(org: Organization | OrganizationError): org is Organization { return (org as Organization).$id !== undefined; -} \ No newline at end of file +} diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index d3de145b8..9137dc128 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -47,7 +47,6 @@ let billingPlan: BillingPlan = BillingPlan.FREE; let paymentMethodId: string; let collaborators: string[] = []; - let couponId: string | undefined; let couponData: Partial = { code: null, status: null, @@ -240,7 +239,6 @@ {billingBudget} {billingPlan} {collaborators} - {couponId} {couponData} /> {:else} diff --git a/src/routes/(console)/organization-[organization]/billing/+page.ts b/src/routes/(console)/organization-[organization]/billing/+page.ts index 2bf2039c7..b72e98ea0 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.ts +++ b/src/routes/(console)/organization-[organization]/billing/+page.ts @@ -20,42 +20,43 @@ export const load: PageLoad = async ({ parent, depends }) => { const billingAddressId = (organization as Organization)?.billingAddressId; const billingAddressPromise: Promise
      = billingAddressId ? sdk.forConsole.billing - .getOrganizationBillingAddress(organization.$id, billingAddressId) - .catch(() => null) + .getOrganizationBillingAddress(organization.$id, billingAddressId) + .catch(() => null) : null; /** - * Needed to keep this out of Promise.all, as when organization is + * Needed to keep this out of Promise.all, as when organization is * initially created, these might return 404 * - can be removed later once that is fixed in back-end */ let billingAggregation = null; try { - billingAggregation = await sdk.forConsole.billing.getAggregation(organization.$id, (organization as Organization)?.billingAggregationId); - } catch (e) { - // ignore error - } - - let billingInvoice = null; - try { - billingInvoice = await sdk.forConsole.billing.getInvoice(organization.$id, (organization as Organization)?.billingInvoiceId); + billingAggregation = await sdk.forConsole.billing.getAggregation( + organization.$id, + (organization as Organization)?.billingAggregationId + ); } catch (e) { // ignore error } - const [ - paymentMethods, - addressList, - billingAddress, - creditList, - aggregationBillingPlan, - ] = await Promise.all([ - sdk.forConsole.billing.listPaymentMethods(), - sdk.forConsole.billing.listAddresses(), - billingAddressPromise, - sdk.forConsole.billing.listCredits(organization.$id), - sdk.forConsole.billing.getPlan(billingAggregation?.plan ?? organization.billingPlan), - ]); + let billingInvoice = null; + try { + billingInvoice = await sdk.forConsole.billing.getInvoice( + organization.$id, + (organization as Organization)?.billingInvoiceId + ); + } catch (e) { + // ignore error + } + + const [paymentMethods, addressList, billingAddress, creditList, aggregationBillingPlan] = + await Promise.all([ + sdk.forConsole.billing.listPaymentMethods(), + sdk.forConsole.billing.listAddresses(), + billingAddressPromise, + sdk.forConsole.billing.listCredits(organization.$id), + sdk.forConsole.billing.getPlan(billingAggregation?.plan ?? organization.billingPlan) + ]); return { paymentMethods, diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index f88992b86..8cfaeee8c 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -18,7 +18,7 @@ export let currentPlan: Plan; export let creditList: CreditList; export let currentInvoice: Invoice | undefined = undefined; - export let currentAggregation: Aggregation | undefined = undefined + export let currentAggregation: Aggregation | undefined = undefined; let showCancel: boolean = false; @@ -46,8 +46,7 @@
      - - {tierToPlan($organization?.billingPlan)?.name} plan + {currentPlan.name} plan
      {isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION @@ -63,7 +62,9 @@ Add-ons{currentAggregation.additionalMembers > 0 ? currentInvoice.usage.length + 1 : currentInvoice.usage.length} + >{currentAggregation.additionalMembers > 0 + ? currentInvoice.usage.length + 1 + : currentInvoice.usage.length}
      @@ -100,10 +101,12 @@ {#if currentInvoice?.usage} {#each currentInvoice.usage as excess, i}
    • + 0 ? 'u-padding-block-8' : 'u-padding-block-start-8'}" - class:u-sep-block-start={i > 0 || currentAggregation.additionalMembers > 0}> + class:u-sep-block-start={i > 0 || + currentAggregation.additionalMembers > 0}> {#if ['storage', 'bandwidth'].includes(excess.name)} {@const excessValue = humanFileSize( excess.value From 079b7b572a568c1a2683cc4f4cf77aa444bf86a6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 29 Jan 2025 04:20:04 +0000 Subject: [PATCH 57/87] fix refactor --- .../components/billing/estimatedTotal.svelte | 11 ++------- .../(console)/apply-credit/+page.svelte | 2 +- .../create-organization/+page.svelte | 24 +++++++++++-------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index b16893a24..1884cc2e8 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -4,7 +4,6 @@ import type { Coupon, Estimation } from '$lib/sdk/billing'; import { sdk } from '$lib/stores/sdk'; import { AppwriteException } from '@appwrite.io/console'; - import Alert from '../alert.svelte'; import Card from '../card.svelte'; import DiscountsApplied from './discountsApplied.svelte'; import { addNotification } from '$lib/stores/notifications'; @@ -13,7 +12,6 @@ export let billingPlan: string; export let collaborators: string[]; export let fixedCoupon = false; - export let error = ''; export let couponData: Partial; export let billingBudget: number; @@ -94,14 +92,9 @@ : getEstimate(billingPlan, collaborators, couponData?.code); -{#if estimation || error.length} +{#if estimation} - {#if error.length} - - {error} - - {/if} - + {#if estimation} {#each estimation.items ?? [] as item} {#if item.value > 0} diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 9b1b3731e..ced29eda1 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -291,7 +291,7 @@ organizationId={selectedOrgId === newOrgId ? undefined : selectedOrgId} {billingPlan} {collaborators} - couponId={couponData.code}> + {couponData}> {#if campaign?.template === 'review' && (campaign?.cta || campaign?.claimed || campaign?.unclaimed)}

      {campaign?.cta}

      diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 9137dc128..622ea0129 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -56,11 +56,20 @@ let billingBudget: number; let showCreditModal = false; - let error = ''; onMount(async () => { if ($page.url.searchParams.has('coupon')) { - couponId = $page.url.searchParams.get('coupon'); + const coupon = $page.url.searchParams.get('coupon'); + try { + const response = await sdk.forConsole.billing.getCoupon(coupon); + couponData = response; + } catch (e) { + couponData = { + code: null, + status: null, + credits: null + }; + } } if ($page.url.searchParams.has('name')) { name = $page.url.searchParams.get('name'); @@ -132,7 +141,7 @@ billingPlan, paymentMethodId, null, - couponId && couponId.length > 0 ? couponId : null, + couponData.code ? couponData.code : null, collaborators, billingBudget, taxId @@ -234,12 +243,7 @@ {#if billingPlan !== BillingPlan.FREE} - + {:else} {/if} @@ -251,7 +255,7 @@ From 3c373367fba86f520ba8ccf1866d6a6c76510540 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 29 Jan 2025 04:27:52 +0000 Subject: [PATCH 58/87] remove unused code --- .../organization-[organization]/change-plan/+page.svelte | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 6d51e61b2..fc6a14f54 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -18,7 +18,6 @@ FormList, InputSelect, InputTags, - InputText, InputTextarea, Label } from '$lib/elements/forms'; @@ -274,7 +273,7 @@ $: if (billingPlan !== BillingPlan.FREE) { loadPaymentMethods(); } - $: isButtonDisabled = $organization.billingPlan === billingPlan || error.length > 0; + $: isButtonDisabled = $organization.billingPlan === billingPlan; @@ -389,7 +388,7 @@ From 65720b25b9c3170eff910ef7e4a3ffce956451f6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 29 Jan 2025 04:41:52 +0000 Subject: [PATCH 59/87] improve delete organization --- src/lib/stores/billing.ts | 4 + .../deleteOrganizationEstimation.svelte | 18 +--- .../settings/deleteOrganizationModal.svelte | 18 ++-- .../settings/invoicesTable.svelte | 93 ++++++++++--------- 4 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index d4affddb6..455c1e139 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -469,6 +469,10 @@ export const upgradeURL = derived( page, ($page) => `${base}/organization-${$page.data?.organization?.$id}/change-plan` ); +export const billingURL = derived( + page, + ($page) => `${base}/organization-${$page.data?.organization?.$id}/billing` +); export const hideBillingHeaderRoutes = ['/console/create-organization', '/console/account']; diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte index 3d6a967b9..df79ddae5 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte @@ -1,31 +1,19 @@ -{#if error} - - {error} - -{/if} {#if estimation} {#if estimation.unpaidInvoices?.length > 0} - You have a unpaid invoices. Please settle them first in order to delete team. + This organization has unresolved invoices that must be settled before it can be + deleted. Please review and resolve these invoices to proceed. - + {/if} {/if} - -{#if $selectedInvoice} - -{/if} diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index 28e43d5aa..b3c7c51e0 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -22,6 +22,7 @@ } from '$lib/elements/table'; import { onMount } from 'svelte'; import DeleteOrganizationEstimation from './deleteOrganizationEstimation.svelte'; + import { billingURL } from '$lib/stores/billing'; export let showDelete = false; export let invoices: InvoiceList; @@ -215,12 +216,17 @@ - + {#if estimation && estimation.unpaidInvoices.length > 0} + + {:else} + + {/if}
      diff --git a/src/routes/(console)/organization-[organization]/settings/invoicesTable.svelte b/src/routes/(console)/organization-[organization]/settings/invoicesTable.svelte index fccee4c6a..cbf881c3f 100644 --- a/src/routes/(console)/organization-[organization]/settings/invoicesTable.svelte +++ b/src/routes/(console)/organization-[organization]/settings/invoicesTable.svelte @@ -23,6 +23,7 @@ const endpoint = getApiEndpoint(); export let invoices: Invoice[]; + export let showActions = true; function retryPayment(invoice: Invoice) { $selectedInvoice = invoice; @@ -35,7 +36,9 @@ Due Date Status Amount Due - + {#if showActions} + + {/if} {#each invoices as invoice, i} @@ -84,53 +87,55 @@ {formatCurrency(invoice.grossAmount)} - - - - - (showDropdown[i] = !showDropdown[i])} - event="view_invoice"> - View invoice - - + + + + (showDropdown[i] = !showDropdown[i])} + event="view_invoice"> + View invoice + + { - retryPayment(invoice); showDropdown[i] = !showDropdown[i]; - trackEvent(`click_retry_payment`, { - from: 'button', - source: 'billing_invoice_menu' - }); - }}> - Retry payment - - {/if} - - - + }} + event="download_invoice"> + Download PDF + + {#if status === 'overdue' || status === 'failed'} + { + retryPayment(invoice); + showDropdown[i] = !showDropdown[i]; + trackEvent(`click_retry_payment`, { + from: 'button', + source: 'billing_invoice_menu' + }); + }}> + Retry payment + + {/if} + + + + {/if} {/each} From 9be7e17db32da7ab9a381a1ed4185c611c8cc3cd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 30 Jan 2025 07:21:02 +0545 Subject: [PATCH 60/87] bind data --- src/routes/(console)/create-organization/+page.svelte | 2 +- .../organization-[organization]/change-plan/+page.svelte | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 622ea0129..815d1390d 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -243,7 +243,7 @@ {#if billingPlan !== BillingPlan.FREE} - + {:else} {/if} diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index fc6a14f54..6235ff394 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -362,11 +362,9 @@ {#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade} {:else if $organization.billingPlan !== BillingPlan.CUSTOM} From 998e6ab5242386e9a8b3936a6f492151fda6776e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 30 Jan 2025 07:23:22 +0545 Subject: [PATCH 61/87] fix downgrade info --- .../organization-[organization]/billing/+page.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index cc0fb72d1..0aa3665d9 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -110,8 +110,8 @@ {/if} {#if $organization?.billingPlanDowngrade} - Your organization will change to a {tierToPlan($organization?.billingPlanDowngrade) - .name} plan once your current billing cycle ends and your invoice is paid on {toLocaleDate( + Your organization has changed to {tierToPlan($organization?.billingPlanDowngrade) + .name} plan. You will continue to have access to {tierToPlan($organization?.billingPlan)} plan features until your billing period ends on {toLocaleDate( $organization.billingNextInvoiceDate )}. From d0747b8d45c865ec9da70f93c94dff1c7fe769ca Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 30 Jan 2025 07:50:08 +0545 Subject: [PATCH 62/87] fix information on downgrade --- src/lib/components/billing/planExcess.svelte | 26 +++++++++---------- src/lib/stores/billing.ts | 15 +++++------ .../change-plan/+page.svelte | 9 +++++-- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index 352f0b29b..35303bbde 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -17,7 +17,7 @@ import { abbreviateNumber } from '$lib/helpers/numbers'; import { formatNum } from '$lib/helpers/string'; import { onMount } from 'svelte'; - import type { OrganizationUsage } from '$lib/sdk/billing'; + import type { Aggregation } from '$lib/sdk/billing'; import { sdk } from '$lib/stores/sdk'; import { BillingPlan } from '$lib/constants'; import { tooltip } from '$lib/actions/tooltip'; @@ -33,16 +33,15 @@ executions?: number; members?: number; } = null; - let usage: OrganizationUsage = null; + let aggregation: Aggregation = null; let showExcess = false; onMount(async () => { - usage = await sdk.forConsole.billing.listUsage( + aggregation = await sdk.forConsole.billing.getAggregation( $organization.$id, - $organization.billingCurrentInvoiceDate, - new Date().toISOString() + $organization.billingAggregationId ); - excess = calculateExcess(usage, plan, members); + excess = calculateExcess(aggregation, plan); showExcess = Object.values(excess).some((value) => value > 0); }); @@ -50,14 +49,12 @@ {#if showExcess} - Your {tierToPlan($organization.billingPlan).name} plan subscription will end on {toLocaleDate( - $organization.billingNextInvoiceDate - )} + Your organization will switch to {tierToPlan(BillingPlan.FREE).name} plan. You will continue + to have access to {tierToPlan($organization.billingPlan).name} plan features until your billing + period ends on {toLocaleDate($organization.billingNextInvoiceDate)} - Following payment of your final invoice, your organization will switch to the {tierToPlan( - BillingPlan.FREE - ).name} plan. {#if excess?.members > 0}All team members except the owner will be removed on - that date.{/if} Service disruptions may occur unless resource usage is reduced. + {#if excess?.members > 0}All team members except the owner will be removed on that date.{/if} + Service disruptions may occur unless resource usage is reduced. - + +
    • From bcfd428463779e87fae80870ce9f2c195535f099 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 3 Feb 2025 06:48:15 +0545 Subject: [PATCH 68/87] fix alert --- .../settings/deleteOrganizationEstimation.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte index df79ddae5..1daf3b089 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte @@ -8,10 +8,8 @@ {#if estimation} {#if estimation.unpaidInvoices?.length > 0} - This organization has unresolved invoices that must be settled before it can be deleted. Please review and resolve these invoices to proceed. - From 9486712e56db1cb80b6be2e4ff07440b8109af48 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 3 Feb 2025 06:49:22 +0545 Subject: [PATCH 69/87] format --- .../settings/deleteOrganizationEstimation.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte index 1daf3b089..e96fe0295 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationEstimation.svelte @@ -8,8 +8,8 @@ {#if estimation} {#if estimation.unpaidInvoices?.length > 0} - This organization has unresolved invoices that must be settled before it can be - deleted. Please review and resolve these invoices to proceed. + This organization has unresolved invoices that must be settled before it can be deleted. + Please review and resolve these invoices to proceed. From 91988fa48125b7ad9354d422e9fe2720c7f33892 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Feb 2025 07:43:05 +0545 Subject: [PATCH 70/87] refactor downgrade alerts --- src/lib/components/billing/planExcess.svelte | 37 ++++++++----------- .../change-plan/+page.svelte | 21 ++++++----- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index 2090172c2..f17573369 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -46,32 +46,25 @@ }); -{#if showExcess} - - - Your organization will switch to {tierToPlan(BillingPlan.FREE).name} plan on {toLocaleDate( - $organization.billingNextInvoiceDate - )}. - + + + Your organization will switch to {tierToPlan(BillingPlan.FREE).name} plan on {toLocaleDate( + $organization.billingNextInvoiceDate + )}. + + {#if !showExcess} + You will retain access to your {tierToPlan($organization.billingPlan).name} plan features until + your billing period ends. + {:else} You will retain access to {tierToPlan($organization.billingPlan).name} plan features until your billing period ends. After that, {#if excess?.members > 0}all team members except the owner will be removed - {:else} - your organization will be limited to Free plan resources{/if}, and service disruptions - may occur if usage exceeds plan limits. - - - - - - - + {/if}, and service disruptions may occur if usage exceeds Free plan limits. + {/if} + +{#if showExcess} + Resource Free limit diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 9fa048caf..0ffdc625a 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -301,19 +301,22 @@ tier={BillingPlan.FREE} class="u-margin-block-start-24" members={data?.members?.total ?? 0} /> - {:else if billingPlan === BillingPlan.PRO && $organization.billingPlan === BillingPlan.SCALE && collaborators?.length > 0} + {:else} {@const extraMembers = collaborators?.length ?? 0} - Your monthly payments will be adjusted for the Pro plan + Your organization will switch to {tierToPlan(billingPlan).name} plan on {toLocaleDate( + $organization.billingNextInvoiceDate + )}. - After switching plans, - you will be charged {formatCurrency( - extraMembers * - ($plansInfo?.get(billingPlan)?.addons?.seats?.price ?? 0) - )} monthly for {extraMembers} team members. This will be reflected in - your next invoice. + You will retain access to {tierToPlan($organization.billingPlan).name} plan features + until your billing period ends. {#if extraMembers > 0}After that, + you will be charged {formatCurrency( + extraMembers * + ($plansInfo?.get(billingPlan)?.addons?.seats?.price ?? 0) + )} per month for {extraMembers} team members.{/if} {/if} {/if} From c320009071bcae67a11e56cffe094ef1dd8905b9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Feb 2025 08:55:47 +0000 Subject: [PATCH 71/87] fix new dev pro banner --- .../billing/alerts/newDevUpgradePro.svelte | 14 +++++++------- src/lib/stores/billing.ts | 18 +++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index c58ad7268..0349414ab 100644 --- a/src/lib/components/billing/alerts/newDevUpgradePro.svelte +++ b/src/lib/components/billing/alerts/newDevUpgradePro.svelte @@ -11,13 +11,13 @@ let show = true; function handleClose() { - show = false; - const now = new Date().getTime(); - localStorage.setItem($activeHeaderAlert.id, now.toString()); - trackEvent('close_upgrade_banner', { - source: 'cloud_credits_banner', - campaign: 'WelcomeManual' - }); + // show = false; + // const now = new Date().getTime(); + // localStorage.setItem($activeHeaderAlert.id, now.toString()); + // trackEvent('close_upgrade_banner', { + // source: 'cloud_credits_banner', + // campaign: 'WelcomeManual' + // }); } diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index a8c95710d..ff10647cb 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -455,14 +455,18 @@ export async function checkForNewDevUpgradePro(org: Organization) { if (now - accountCreated < 1000 * 60 * 60 * 24 * 7) return; const isDismissed = !!localStorage.getItem('newDevUpgradePro'); if (isDismissed) return; - if (now - accountCreated < 1000 * 60 * 60 * 24 * 37) { - headerAlert.add({ - id: 'newDevUpgradePro', - component: newDevUpgradePro, - show: true, - importance: 1 - }); + // check if coupon already applied + try { + await sdk.forConsole.billing.getCoupon('appw50'); + } catch (e) { + return; } + headerAlert.add({ + id: 'newDevUpgradePro', + component: newDevUpgradePro, + show: true, + importance: 1 + }); } export const upgradeURL = derived( page, From ab14064c1828a69b56e7c0fe622b07aae29ebe71 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Feb 2025 08:57:30 +0000 Subject: [PATCH 72/87] fix comment --- .../billing/alerts/newDevUpgradePro.svelte | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index 0349414ab..c58ad7268 100644 --- a/src/lib/components/billing/alerts/newDevUpgradePro.svelte +++ b/src/lib/components/billing/alerts/newDevUpgradePro.svelte @@ -11,13 +11,13 @@ let show = true; function handleClose() { - // show = false; - // const now = new Date().getTime(); - // localStorage.setItem($activeHeaderAlert.id, now.toString()); - // trackEvent('close_upgrade_banner', { - // source: 'cloud_credits_banner', - // campaign: 'WelcomeManual' - // }); + show = false; + const now = new Date().getTime(); + localStorage.setItem($activeHeaderAlert.id, now.toString()); + trackEvent('close_upgrade_banner', { + source: 'cloud_credits_banner', + campaign: 'WelcomeManual' + }); } From 2dd1e9a028d2d3b0197eb5bc761a24481eef70ed Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 5 Feb 2025 04:31:26 +0000 Subject: [PATCH 73/87] fix alert type --- .../organization-[organization]/change-plan/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 0ffdc625a..e5d1e0f5a 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -303,7 +303,7 @@ members={data?.members?.total ?? 0} /> {:else} {@const extraMembers = collaborators?.length ?? 0} - + Your organization will switch to {tierToPlan(billingPlan).name} plan on {toLocaleDate( $organization.billingNextInvoiceDate From 856b99455fcea576bd3f300e788c8d19ff91d242 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 5 Feb 2025 04:33:12 +0000 Subject: [PATCH 74/87] fix free downgrade --- src/lib/components/billing/planExcess.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index f17573369..f524365a3 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -54,12 +54,13 @@ {#if !showExcess} You will retain access to your {tierToPlan($organization.billingPlan).name} plan features until - your billing period ends. + your billing period ends. After that, your organization will be limited to Free plan resources, + and service disruptions may occur if usage exceeds plan limits. {:else} You will retain access to {tierToPlan($organization.billingPlan).name} plan features until your billing period ends. After that, - {#if excess?.members > 0}all team members except the owner will be removed + {#if excess?.members > 0} + all team members except the owner will be removed {/if}, and service disruptions may occur if usage exceeds Free plan limits. {/if} From 9ae763d53605bd40f5ba214aea80eb042b5f9c90 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 5 Feb 2025 04:35:24 +0000 Subject: [PATCH 75/87] updates --- src/lib/components/billing/planExcess.svelte | 4 ++-- .../organization-[organization]/change-plan/+page.svelte | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index f524365a3..59cd94c07 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -60,8 +60,8 @@ You will retain access to {tierToPlan($organization.billingPlan).name} plan features until your billing period ends. After that, {#if excess?.members > 0} - all team members except the owner will be removed - {/if}, and service disruptions may occur if usage exceeds Free plan limits. + all team members except the owner will be removed, + {/if} and service disruptions may occur if usage exceeds Free plan limits. {/if} {#if showExcess} diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index e5d1e0f5a..992916f27 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -162,9 +162,7 @@ type: 'success', isHtml: true, message: ` - ${$organization.name} will change to ${ - tierToPlan(billingPlan).name - } plan at the end of the current billing cycle.` + ${$organization.name} plan has been successfully updated.` }); trackEvent(Submit.OrganizationDowngrade, { From 2caad838fd6852debf4615cd23ec06cedb0046f6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 11 Feb 2025 09:15:28 +0000 Subject: [PATCH 76/87] renaming constants --- src/lib/components/billing/estimatedTotal.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 1884cc2e8..9c4f217c2 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -33,9 +33,9 @@ } catch (e) { if (e instanceof AppwriteException) { if ( - e.type === 'coupon_not_found' || - e.type === 'coupon_already_used' || - e.type === 'billing_credits_unsupported' + e.type === 'billing_coupon_not_found' || + e.type === 'billing_coupon_already_used' || + e.type === 'billing_credit_unsupported' ) { couponData = { code: null, @@ -68,9 +68,9 @@ } catch (e) { if (e instanceof AppwriteException) { if ( - e.type === 'coupon_not_found' || - e.type === 'coupon_already_used' || - e.type === 'billing_credits_unsupported' + e.type === 'billing_coupon_not_found' || + e.type === 'billing_coupon_already_used' || + e.type === 'billing_credit_unsupported' ) { couponData = { code: null, From c234c0cb673a6822df93663d899505934c25339a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 13 Feb 2025 12:46:41 +0000 Subject: [PATCH 77/87] Fix check issues --- src/lib/components/billing/estimatedTotal.svelte | 2 +- src/lib/components/billing/planExcess.svelte | 2 -- .../billing/paymentHistory.svelte | 7 +++---- .../organization-[organization]/billing/planSummary.svelte | 2 -- .../organization-[organization]/change-plan/+page.svelte | 2 -- .../settings/deleteOrganizationModal.svelte | 3 +-- 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 9c4f217c2..3558d6fca 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -105,7 +105,7 @@ {/if} {/each} {#each estimation.discounts ?? [] as item} - + {/each}
      diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index 59cd94c07..97f56e9d8 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -12,7 +12,6 @@ import { calculateExcess, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; import { toLocaleDate } from '$lib/helpers/date'; - import { Button } from '$lib/elements/forms'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; import { abbreviateNumber } from '$lib/helpers/numbers'; import { formatNum } from '$lib/helpers/string'; @@ -23,7 +22,6 @@ import { tooltip } from '$lib/actions/tooltip'; export let tier: Tier; - export let members: number; const plan = $plansInfo?.get(tier); let excess: { diff --git a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte index 2d2401213..0e73e8bf4 100644 --- a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte @@ -28,11 +28,10 @@ import { onMount } from 'svelte'; import { trackEvent } from '$lib/actions/analytics'; import { selectedInvoice, showRetryModal } from './store'; - import { organization } from '$lib/stores/organization'; let showDropdown = []; let showFailedError = false; - // let isLoadingInvoices = true; + let isLoadingInvoices = true; let offset = 0; let invoiceList: InvoiceList = { @@ -46,13 +45,13 @@ onMount(request); async function request() { - // isLoadingInvoices = true; + isLoadingInvoices = true; invoiceList = await sdk.forConsole.billing.listInvoices($page.params.organization, [ Query.limit(limit), Query.offset(offset), Query.orderDesc('$createdAt') ]); - // isLoadingInvoices = false; + isLoadingInvoices = false; } function retryPayment(invoice: Invoice) { diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index f95976549..feffb532f 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -11,10 +11,8 @@ import { BillingPlan } from '$lib/constants'; import { trackEvent } from '$lib/actions/analytics'; import { tooltip } from '$lib/actions/tooltip'; - import { type Models } from '@appwrite.io/console'; import CancelDowngradeModel from './cancelDowngradeModal.svelte'; - export let members: Models.MembershipList; export let currentPlan: Plan; export let creditList: CreditList; export let currentInvoice: Invoice | undefined = undefined; diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 992916f27..ce8abb105 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -9,7 +9,6 @@ import PlanExcess from '$lib/components/billing/planExcess.svelte'; import SelectPlan from '$lib/components/billing/selectPlan.svelte'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; - import Card from '$lib/components/card.svelte'; import Default from '$lib/components/roles/default.svelte'; import { BillingPlan, Dependencies, feedbackDowngradeOptions } from '$lib/constants'; import { @@ -72,7 +71,6 @@ status: null, credits: null }; - let couponId: string; let taxId: string; let billingBudget: number; let showCreditModal = false; diff --git a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte index b3c7c51e0..22fba4379 100644 --- a/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/(console)/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -11,7 +11,7 @@ import { projects } from '../store'; import { toLocaleDate } from '$lib/helpers/date'; import { isCloud } from '$lib/system'; - import type { EstimationDeleteOrganization, InvoiceList } from '$lib/sdk/billing'; + import type { EstimationDeleteOrganization } from '$lib/sdk/billing'; import { TableBody, TableCell, @@ -25,7 +25,6 @@ import { billingURL } from '$lib/stores/billing'; export let showDelete = false; - export let invoices: InvoiceList; let error: string = null; let selectedTab = 'projects'; From ef6c421bb25b41886e2b9a1d28bd3e07d7d0eb4c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 13 Feb 2025 12:50:13 +0000 Subject: [PATCH 78/87] Fix analysis issues 2 --- .../(console)/organization-[organization]/billing/+page.svelte | 1 - .../organization-[organization]/billing/paymentHistory.svelte | 3 --- .../organization-[organization]/change-plan/+page.svelte | 1 - .../organization-[organization]/settings/+page.svelte | 3 +-- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index 2e2688651..c370fbf31 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -120,7 +120,6 @@
      diff --git a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte index 0e73e8bf4..65fe42cfd 100644 --- a/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte @@ -31,7 +31,6 @@ let showDropdown = []; let showFailedError = false; - let isLoadingInvoices = true; let offset = 0; let invoiceList: InvoiceList = { @@ -45,13 +44,11 @@ onMount(request); async function request() { - isLoadingInvoices = true; invoiceList = await sdk.forConsole.billing.listInvoices($page.params.organization, [ Query.limit(limit), Query.offset(offset), Query.orderDesc('$createdAt') ]); - isLoadingInvoices = false; } function retryPayment(invoice: Invoice) { diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index ce8abb105..8544b7f74 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -81,7 +81,6 @@ onMount(async () => { if ($page.url.searchParams.has('code')) { - couponId = $page.url.searchParams.get('code'); const coupon = $page.url.searchParams.get('code'); try { const response = await sdk.forConsole.billing.getCoupon(coupon); diff --git a/src/routes/(console)/organization-[organization]/settings/+page.svelte b/src/routes/(console)/organization-[organization]/settings/+page.svelte index 98b236e6d..598d3aa33 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.svelte +++ b/src/routes/(console)/organization-[organization]/settings/+page.svelte @@ -16,7 +16,6 @@ import Baa from './BAA.svelte'; import Soc2 from './Soc2.svelte'; - export let data; let name: string; let showDelete = false; @@ -106,4 +105,4 @@ {/if} - + From 5afae81dcc565d0857c728793f8fb378a843a220 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 13 Feb 2025 13:09:32 +0000 Subject: [PATCH 79/87] check success --- src/routes/(console)/onboarding/+page.svelte | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/routes/(console)/onboarding/+page.svelte b/src/routes/(console)/onboarding/+page.svelte index e4c1f1ae7..b32451e1a 100644 --- a/src/routes/(console)/onboarding/+page.svelte +++ b/src/routes/(console)/onboarding/+page.svelte @@ -12,7 +12,7 @@ import { isCloud } from '$lib/system'; import { ID } from '@appwrite.io/console'; import { onMount } from 'svelte'; - import { tierToPlan, type Tier, plansInfo } from '$lib/stores/billing'; + import { tierToPlan, type Tier, plansInfo, isOrganization } from '$lib/stores/billing'; import { formatCurrency } from '$lib/helpers/numbers'; import { base } from '$app/paths'; import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect'; @@ -59,11 +59,18 @@ plan: tierToPlan(plan)?.name }); await invalidate(Dependencies.ACCOUNT); - await goto(`${base}/organization-${org.$id}`); - addNotification({ - message: `${orgName} organization successfully created`, - type: 'success' - }); + if (isOrganization(org)) { + await goto(`${base}/organization-${org.$id}`); + addNotification({ + message: `${orgName} organization successfully created`, + type: 'success' + }); + } else { + addNotification({ + message: `${org.message}`, + type: 'error' + }); + } } catch (error) { addNotification({ message: error.message, From 4132c038a5f48a481394818a86ffbc49a7986c4d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 04:28:48 +0000 Subject: [PATCH 80/87] fix error --- .../usage/[[invoice]]/totalMembers.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte index b92803eae..27d9c041c 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/totalMembers.svelte @@ -46,7 +46,7 @@

      From c72b76842ac90704473e93d85675a0f4fe921de8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 06:36:58 +0000 Subject: [PATCH 81/87] fix missing await --- src/routes/(console)/account/organizations/+page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/account/organizations/+page.ts b/src/routes/(console)/account/organizations/+page.ts index 237a3772d..4ba4be7e4 100644 --- a/src/routes/(console)/account/organizations/+page.ts +++ b/src/routes/(console)/account/organizations/+page.ts @@ -14,7 +14,7 @@ export const load: PageLoad = async ({ url, route }) => { const organizations = isCloud ? await sdk.forConsole.billing.listOrganization(queries) - : sdk.forConsole.teams.list(queries); + : await sdk.forConsole.teams.list(queries); return { offset, From 602f1cb08ff3a44fc44685ec3d91a474a18449cc Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 06:55:54 +0000 Subject: [PATCH 82/87] format --- .../(console)/organization-[organization]/settings/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(console)/organization-[organization]/settings/+page.svelte b/src/routes/(console)/organization-[organization]/settings/+page.svelte index 598d3aa33..03f3b7c4d 100644 --- a/src/routes/(console)/organization-[organization]/settings/+page.svelte +++ b/src/routes/(console)/organization-[organization]/settings/+page.svelte @@ -105,4 +105,4 @@ {/if} - + From 80fb6ce2a3e3532f0b383f87523da7c8a81b14b0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 07:56:26 +0000 Subject: [PATCH 83/87] update endpoint for test --- playwright.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright.config.ts b/playwright.config.ts index 3f39d8761..fe964db38 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,7 +12,7 @@ const config: PlaywrightTestConfig = { webServer: { timeout: 120000, env: { - PUBLIC_APPWRITE_ENDPOINT: 'https://console-testing-2.appwrite.org/v1', + PUBLIC_APPWRITE_ENDPOINT: 'https://dlbillingic.appwrite.org/v1', PUBLIC_CONSOLE_MODE: 'cloud', PUBLIC_STRIPE_KEY: 'pk_test_51LT5nsGYD1ySxNCyd7b304wPD8Y1XKKWR6hqo6cu3GIRwgvcVNzoZv4vKt5DfYXL1gRGw4JOqE19afwkJYJq1g3K004eVfpdWn' From 1d9a1c58b0452ad5a17844e593eb34cbd81c6cfc Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 08:37:08 +0000 Subject: [PATCH 84/87] Fix info --- src/lib/components/billing/estimatedTotal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/billing/estimatedTotal.svelte b/src/lib/components/billing/estimatedTotal.svelte index 3558d6fca..c0e5c5233 100644 --- a/src/lib/components/billing/estimatedTotal.svelte +++ b/src/lib/components/billing/estimatedTotal.svelte @@ -117,7 +117,7 @@

      You'll pay {formatCurrency(estimation.grossAmount)} now. - Once your credits run out, you'll be charged + {#if couponData?.code}Once your credits run out,{:else}Then{/if} you'll be charged {formatCurrency(estimation.amount)} every 30 days.

      {/if} From 288096703bfe39b533ed2af15e0deed80bba6636 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 08:55:39 +0000 Subject: [PATCH 85/87] Use constant --- src/lib/components/billing/alerts/newDevUpgradePro.svelte | 4 ++-- src/lib/constants.ts | 1 + src/lib/stores/billing.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index c58ad7268..8e4637a65 100644 --- a/src/lib/components/billing/alerts/newDevUpgradePro.svelte +++ b/src/lib/components/billing/alerts/newDevUpgradePro.svelte @@ -2,7 +2,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { trackEvent } from '$lib/actions/analytics'; - import { BillingPlan } from '$lib/constants'; + import { BillingPlan, NEW_DEV_PRO_UPGRADE_CUPON } from '$lib/constants'; import { Button } from '$lib/elements/forms'; import { organization } from '$lib/stores/organization'; import { activeHeaderAlert } from '$routes/(console)/store'; @@ -29,7 +29,7 @@ secondary fullWidthMobile class="u-line-height-1" - href={`${base}/apply-credit?code=appw50&org=${$organization.$id}`} + href={`${base}/apply-credit?code=${NEW_DEV_PRO_UPGRADE_CUPON}&org=${$organization.$id}`} on:click={() => { trackEvent('click_credits_redeem', { from: 'button', diff --git a/src/lib/constants.ts b/src/lib/constants.ts index c77f213b5..f69f74d89 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,6 +1,7 @@ export const PAGE_LIMIT = 12; // default page limit export const CARD_LIMIT = 6; // default card limit export const INTERVAL = 5 * 60000; // default interval to check for feedback +export const NEW_DEV_PRO_UPGRADE_CUPON = 'appw50'; export enum Dependencies { FACTORS = 'dependency:factors', diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index ffe2f1e82..a619d8262 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -22,7 +22,7 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store'; import MarkedForDeletion from '$lib/components/billing/alerts/markedForDeletion.svelte'; -import { BillingPlan } from '$lib/constants'; +import { BillingPlan, NEW_DEV_PRO_UPGRADE_CUPON } from '$lib/constants'; import PaymentMandate from '$lib/components/billing/alerts/paymentMandate.svelte'; import MissingPaymentMethod from '$lib/components/billing/alerts/missingPaymentMethod.svelte'; import LimitReached from '$lib/components/billing/alerts/limitReached.svelte'; @@ -465,7 +465,7 @@ export async function checkForNewDevUpgradePro(org: Organization) { if (isDismissed) return; // check if coupon already applied try { - await sdk.forConsole.billing.getCoupon('appw50'); + await sdk.forConsole.billing.getCoupon(NEW_DEV_PRO_UPGRADE_CUPON); } catch (e) { return; } From 55dceeeac865d4c5097db36c1a53a5f969c987bd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 14:42:56 +0545 Subject: [PATCH 86/87] Update src/lib/constants.ts Co-authored-by: Darshan --- src/lib/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index f69f74d89..00ee09df3 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,7 +1,7 @@ export const PAGE_LIMIT = 12; // default page limit export const CARD_LIMIT = 6; // default card limit export const INTERVAL = 5 * 60000; // default interval to check for feedback -export const NEW_DEV_PRO_UPGRADE_CUPON = 'appw50'; +export const NEW_DEV_PRO_UPGRADE_COUPON = 'appw50'; export enum Dependencies { FACTORS = 'dependency:factors', From 178698eaf4e80e7d6f10646d7188fc0b1c7187b4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 14 Feb 2025 08:59:12 +0000 Subject: [PATCH 87/87] fix typo --- src/lib/components/billing/alerts/newDevUpgradePro.svelte | 4 ++-- src/lib/stores/billing.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index 8e4637a65..7f8c30878 100644 --- a/src/lib/components/billing/alerts/newDevUpgradePro.svelte +++ b/src/lib/components/billing/alerts/newDevUpgradePro.svelte @@ -2,7 +2,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { trackEvent } from '$lib/actions/analytics'; - import { BillingPlan, NEW_DEV_PRO_UPGRADE_CUPON } from '$lib/constants'; + import { BillingPlan, NEW_DEV_PRO_UPGRADE_COUPON } from '$lib/constants'; import { Button } from '$lib/elements/forms'; import { organization } from '$lib/stores/organization'; import { activeHeaderAlert } from '$routes/(console)/store'; @@ -29,7 +29,7 @@ secondary fullWidthMobile class="u-line-height-1" - href={`${base}/apply-credit?code=${NEW_DEV_PRO_UPGRADE_CUPON}&org=${$organization.$id}`} + href={`${base}/apply-credit?code=${NEW_DEV_PRO_UPGRADE_COUPON}&org=${$organization.$id}`} on:click={() => { trackEvent('click_credits_redeem', { from: 'button', diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index a619d8262..636853952 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -22,7 +22,7 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/(console)/store'; import MarkedForDeletion from '$lib/components/billing/alerts/markedForDeletion.svelte'; -import { BillingPlan, NEW_DEV_PRO_UPGRADE_CUPON } from '$lib/constants'; +import { BillingPlan, NEW_DEV_PRO_UPGRADE_COUPON } from '$lib/constants'; import PaymentMandate from '$lib/components/billing/alerts/paymentMandate.svelte'; import MissingPaymentMethod from '$lib/components/billing/alerts/missingPaymentMethod.svelte'; import LimitReached from '$lib/components/billing/alerts/limitReached.svelte'; @@ -465,7 +465,7 @@ export async function checkForNewDevUpgradePro(org: Organization) { if (isDismissed) return; // check if coupon already applied try { - await sdk.forConsole.billing.getCoupon(NEW_DEV_PRO_UPGRADE_CUPON); + await sdk.forConsole.billing.getCoupon(NEW_DEV_PRO_UPGRADE_COUPON); } catch (e) { return; }