Skip to content

Commit

Permalink
Merge pull request #1453 from appwrite/fix-applying-credit-in-billing…
Browse files Browse the repository at this point in the history
…-estimate

Show credit in billing estimates
  • Loading branch information
ernstmul authored Oct 25, 2024
2 parents 8b94623 + 11ab071 commit 1d9df55
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
let currentInvoice: Invoice;
let extraMembers = 0;
let currentPlan;
let availableCredit = 0;
const today = new Date();
onMount(async () => {
Expand All @@ -30,6 +31,11 @@
extraMembers = members.total > 1 ? members.total - 1 : 0;
currentPlan = await sdk.forConsole.billing.getPlan($organization?.$id);
const creditList = await sdk.forConsole.billing.listCredits($organization.$id, [
Query.offset(0)
]);
availableCredit = creditList.available;
});
$: extraUsage = (currentInvoice?.amount ?? 0) - (currentPlan?.price ?? 0);
Expand Down Expand Up @@ -139,6 +145,33 @@
</CollapsibleItem>
{/if}

{#if $organization?.billingPlan !== BillingPlan.FREE && availableCredit > 0}
<CollapsibleItem noContent gap={4}>
<span class="body-text-2 u-flex u-cross-center u-gap-2"
><svg
width="16"
height="17"
viewBox="0 0 16 17"
fill="none"
xmlns="http://www.w3.org/2000/svg">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M14.166 7.93434C14.4784 8.24676 14.4784 8.75329 14.166 9.06571L8.56603 14.6657C8.25361 14.9781 7.74708 14.9781 7.43466 14.6657L1.83466 9.06571C1.67842 8.90947 1.60032 8.70469 1.60034 8.49992V4.50002C1.60034 3.17454 2.67486 2.10002 4.00034 2.10002H8.00056C8.20523 2.10008 8.40987 2.17818 8.56603 2.33434L14.166 7.93434ZM4.00034 5.30002C4.44217 5.30002 4.80034 4.94185 4.80034 4.50002C4.80034 4.05819 4.44217 3.70002 4.00034 3.70002C3.55851 3.70002 3.20034 4.05819 3.20034 4.50002C3.20034 4.94185 3.55851 5.30002 4.00034 5.30002Z"
fill="#00BC5D" />
</svg>
Credits to be applied</span>

<div
class="body-text-2 u-margin-inline-start-auto"
style="color: var(--web-green-500, #10B981)">
-{formatCurrency(
Math.min(availableCredit, currentInvoice?.amount ?? 0)
)}
</div>
</CollapsibleItem>
{/if}

<CollapsibleItem noContent gap={4}>
<span class="body-text-2">Current total (USD)</span>
<span class="tooltip u-cross-center" aria-label="total info">
Expand All @@ -153,7 +186,13 @@
<div class="body-text-2 u-margin-inline-start-auto">
{$organization?.billingPlan === BillingPlan.FREE
? formatCurrency(0)
: formatCurrency(currentInvoice?.amount ?? 0)}
: formatCurrency(
Math.max(
(currentInvoice?.amount ?? 0) -
Math.min(availableCredit, currentInvoice?.amount ?? 0),
0
)
)}
</div>
</CollapsibleItem>
</Collapsible>
Expand Down

0 comments on commit 1d9df55

Please sign in to comment.