diff --git a/src/lib/components/billing/discountsApplied.svelte b/src/lib/components/billing/discountsApplied.svelte new file mode 100644 index 000000000..3ff2d7add --- /dev/null +++ b/src/lib/components/billing/discountsApplied.svelte @@ -0,0 +1,37 @@ + + +{#if adjustedValue > 0} + + + + {label} + + {#if value >= 100} + + {:else} + -{formatCurrency(adjustedValue)} + {/if} + +{/if} diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index 438120824..dd7878890 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -7,6 +7,7 @@ import { CreditsApplied } from '.'; import { sdk } from '$lib/stores/sdk'; import { AppwriteException } from '@appwrite.io/console'; + import DiscountsApplied from './discountsApplied.svelte'; export let billingPlan: Tier; export let collaborators: string[]; @@ -35,7 +36,8 @@ if ( e.type === 'billing_coupon_not_found' || e.type === 'billing_coupon_already_used' || - e.type === 'billing_credit_unsupported' + e.type === 'billing_credit_unsupported' || + e.type === 'billing_coupon_not_eligible' ) { couponData = { code: null, @@ -65,7 +67,8 @@ if ( e.type === 'billing_coupon_not_found' || e.type === 'billing_coupon_already_used' || - e.type === 'billing_credit_unsupported' + e.type === 'billing_credit_unsupported' || + e.type === 'billing_coupon_not_eligible' ) { couponData = { code: null, @@ -80,13 +83,6 @@ $: organizationId ? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponData?.code) : getEstimate(billingPlan, collaborators, couponData?.code); - - $: estimatedTotal = - couponData?.status === 'active' - ? estimation?.grossAmount - couponData.credits >= 0 - ? estimation?.grossAmount - couponData.credits - : 0 - : estimation?.grossAmount; {#if estimation} @@ -102,6 +98,9 @@ >{formatCurrency(item.value)} {/each} + {#each estimation.discounts ?? [] as item} + + {/each} {#if couponData?.status === 'active'} @@ -110,15 +109,15 @@ Total due - {formatCurrency(estimatedTotal)} + {formatCurrency(estimation.grossAmount)} - You'll pay {formatCurrency(estimatedTotal)} + You'll pay {formatCurrency(estimation.grossAmount)} now. {#if couponData?.code}Once your credits run out,{:else}Then{/if} you'll be charged - {formatCurrency(estimation.grossAmount)} every 30 days. + {formatCurrency(estimation.amount)} every 30 days. - - {#if selectedPlan !== BillingPlan.FREE && data.organization.billingPlan === BillingPlan.FREE} + {#if isUpgrade}