From ee293bc66b050dfa71aea82059a92553287c338b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 25 Jun 2025 06:58:52 +0000 Subject: [PATCH] handle addons and project usage --- src/lib/sdk/billing.ts | 8 + .../billing/planSummary.svelte | 366 +++++++++++------- 2 files changed, 237 insertions(+), 137 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 581d10add..baaa7f440 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -207,8 +207,15 @@ export type AggregationTeam = { * Aggregation billing plan */ plan: string; + projectBreakdown: ProjectBreakdown[] }; +export type ProjectBreakdown = { + $id: string; + name: string; + amount: number; +} + export type InvoiceUsage = { resourceId: string; value: number; @@ -413,6 +420,7 @@ export type Plan = { supportsOrganizationRoles: boolean; buildSize: number; // in MB deploymentSize: number; // in MB + usagePerProject: boolean; }; export type PlanList = { diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 09ea95f4a..d2ce8405c 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -15,6 +15,7 @@ Divider, Icon, Layout, + Table, Tooltip, Typography } from '@appwrite.io/pink-svelte'; @@ -36,159 +37,250 @@ {#if $organization} - - Payment estimates - A breakdown of your estimated upcoming payment for the current billing period. Totals displayed - exclude accumulated credits and applicable taxes. - -

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

- - - - - {currentPlan.name} plan - - - {isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION - ? formatCurrency(0) - : currentPlan - ? formatCurrency(currentPlan?.price) - : ''} - - - - {#if currentPlan.budgeting && extraUsage > 0} - r.amount && r.amount > 0) - .length.toString()}> - - {formatCurrency(extraUsage >= 0 ? extraUsage : 0)} - - - {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess, i} - {#if i > 0} - - {/if} - - - - - {excess.resourceId} - - - {formatCurrency(excess.amount)} - - - - - - {formatNumberWithCommas(excess.value)} - - {abbreviateNumber(excess.value)} - - - - {/each} - - - {/if} - - {#if currentPlan.supportsCredits && availableCredit > 0} + {#if currentPlan.usagePerProject} + + + + {currentPlan.name} plan + + + Next payment of ${currentAggregation.amount} + will occur on + {toLocaleDate($organization?.billingNextInvoiceDate)} + + + + + + - - - Credits to be applied - - - -{formatCurrency( - Math.min(availableCredit, currentInvoice?.amount ?? 0) - )} + Base plan + + {isTrial || + $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION + ? formatCurrency(0) + : currentPlan + ? formatCurrency(currentPlan?.price) + : ''} - {/if} - - {#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION} + + + {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0 && Object.keys(currentPlan.addons).includes(r.resourceId) && currentPlan.addons[r.resourceId].price > 0) as excess, i} + {#if i > 0} - - - - Current total (USD) - - - - Estimates are updated daily and may differ from your - final invoice. - - + {/if} + + + + {excess.resourceId} + + {formatCurrency(excess.amount)} + + + + + {/each} + {#each currentAggregation.projectBreakdown as projectBreakdown} + + + {formatCurrency(projectBreakdown.amount)} + + + + + + {/each} + + + {:else} + + Payment estimates + A breakdown of your estimated upcoming payment for the current billing period. Totals displayed + exclude accumulated credits and applicable taxes. + +

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

+ + + + + {currentPlan.name} plan - - {formatCurrency( - Math.max( - (currentInvoice?.amount ?? 0) - - Math.min(availableCredit, currentInvoice?.amount ?? 0), - 0 - ) - )} + + {isTrial || + $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION + ? formatCurrency(0) + : currentPlan + ? formatCurrency(currentPlan?.price) + : ''} - {/if} - - -
- - {#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} -
- - -
- {:else} -
- {#if $organization?.billingPlanDowngrade !== null} - - {:else} + + {#if currentPlan.budgeting && extraUsage > 0} + r.amount && r.amount > 0) + .length.toString()}> + + {formatCurrency(extraUsage >= 0 ? extraUsage : 0)} + + + {#each currentAggregation.resources.filter((r) => r.amount && r.amount > 0) as excess, i} + {#if i > 0} + + {/if} + + + + + {excess.resourceId} + + + {formatCurrency(excess.amount)} + + + + + + {formatNumberWithCommas(excess.value)} + + {abbreviateNumber(excess.value)} + + + + {/each} + + + {/if} + + {#if currentPlan.supportsCredits && availableCredit > 0} + + + + Credits to be applied + + + -{formatCurrency( + Math.min(availableCredit, currentInvoice?.amount ?? 0) + )} + + + {/if} + + {#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION} + + + + + Current total (USD) + + + + Estimates are updated daily and may differ from your + final invoice. + + + + + + {formatCurrency( + Math.max( + (currentInvoice?.amount ?? 0) - + Math.min( + availableCredit, + currentInvoice?.amount ?? 0 + ), + 0 + ) + )} + + + {/if} + + + + + {#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} +
+ - {/if} - -
- {/if} -
- +
+ {:else} +
+ {#if $organization?.billingPlanDowngrade !== null} + + {:else} + + {/if} + +
+ {/if} +
+
+ {/if} {/if}