From 7c5eae2806ef1d6f9d872c7c256b327bacb23517 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 10 Oct 2024 14:53:54 +0200 Subject: [PATCH 1/2] feat: use console sdk with cloud services --- .gitignore | 1 + src/lib/components/backupDatabaseAlert.svelte | 4 +- src/lib/components/backupRestoreBox.svelte | 6 +- .../billing/alerts/limitReached.svelte | 4 +- .../alerts/missingPaymentMethod.svelte | 4 +- .../billing/alerts/newDevUpgradePro.svelte | 4 +- .../billing/alerts/paymentMandate.svelte | 3 +- src/lib/components/billing/couponInput.svelte | 6 +- .../components/billing/emptyCardCloud.svelte | 4 +- .../billing/estimatedTotalBox.svelte | 6 +- .../billing/planComparisonBox.svelte | 18 +-- src/lib/components/billing/planExcess.svelte | 9 +- .../components/billing/planSelection.svelte | 22 ++-- .../billing/selectPaymentMethod.svelte | 7 +- src/lib/components/billing/usageRates.svelte | 10 +- .../billing/validateCreditModal.svelte | 2 +- src/lib/components/bottomModalAlert.svelte | 6 +- src/lib/components/creditCardInfo.svelte | 4 +- src/lib/components/support.svelte | 8 +- src/lib/constants.ts | 7 -- src/lib/layout/activity.svelte | 4 +- src/lib/layout/containerButton.svelte | 4 +- src/lib/layout/containerHeader.svelte | 10 +- src/lib/layout/header.svelte | 5 +- src/lib/layout/logs.svelte | 4 +- src/lib/layout/navigation.svelte | 4 +- src/lib/sdk/billing.ts | 4 +- src/lib/stores/billing.ts | 105 +++++++++--------- src/lib/stores/campaigns.ts | 4 +- src/lib/stores/organization.ts | 26 ++--- src/lib/stores/sdk.ts | 8 +- src/lib/stores/stripe.ts | 16 +-- src/routes/(console)/+layout.svelte | 7 +- src/routes/(console)/+layout.ts | 8 +- .../account/organizations/+page.svelte | 6 +- .../(console)/account/payments/+page.ts | 4 +- .../account/payments/addressModal.svelte | 7 +- .../payments/deleteAddressModal.svelte | 2 +- .../payments/deletePaymentModal.svelte | 2 +- .../account/payments/editAddressModal.svelte | 2 +- .../account/payments/editPaymentModal.svelte | 36 +++--- .../account/payments/paymentMethods.svelte | 6 +- .../(console)/apply-credit/+page.svelte | 35 +++--- src/routes/(console)/apply-credit/+page.ts | 2 +- .../create-organization/+page.svelte | 45 ++++---- src/routes/(console)/onboarding/+page.svelte | 20 ++-- .../organization-[organization]/+layout.ts | 2 +- .../organization-[organization]/+page.svelte | 5 +- .../billing/+page.svelte | 13 +-- .../billing/+page.ts | 10 +- .../billing/addCreditModal.svelte | 2 +- .../billing/addCreditWizard.svelte | 7 +- .../billing/availableCredit.svelte | 10 +- .../billing/billingAddress.svelte | 2 +- .../billing/budgetAlert.svelte | 2 +- .../billing/budgetCap.svelte | 9 +- .../billing/deleteOrgPayment.svelte | 11 +- .../billing/paymentHistory.svelte | 9 +- .../billing/paymentMethods.svelte | 22 ++-- .../billing/planSummary.svelte | 21 ++-- .../billing/removeAddress.svelte | 2 +- .../billing/replaceAddress.svelte | 18 ++- .../billing/replaceCard.svelte | 10 +- .../billing/retryPaymentModal.svelte | 13 ++- .../billing/store.ts | 5 +- .../billing/taxId.svelte | 2 +- .../billing/wizard/addCredit.svelte | 2 +- .../billing/wizard/paymentDetails.svelte | 6 +- .../change-plan/+page.svelte | 52 ++++----- .../createMember.svelte | 5 +- .../organization-[organization]/header.svelte | 8 +- .../settings/+page.ts | 2 +- .../settings/deleteOrganizationModal.svelte | 2 +- .../usage/[[invoice]]/+page.svelte | 10 +- .../usage/[[invoice]]/+page.ts | 11 +- .../usage/[[invoice]]/totalMembers.svelte | 4 +- .../wizard/step1.svelte | 2 +- .../(console)/project-[project]/+layout.ts | 2 +- .../auth/security/updateMockNumbers.svelte | 4 +- .../auth/templates/+page.svelte | 4 +- .../project-[project]/databases/create.svelte | 4 +- .../database-[database]/backups/+page.svelte | 9 +- .../backups/containerHeader.svelte | 4 +- .../backups/createPolicy.svelte | 8 +- .../executions/+page.svelte | 5 +- .../settings/deleteProject.svelte | 6 +- .../settings/smtp/+page.svelte | 7 +- .../settings/usage/[[invoice]]/+page.svelte | 2 +- .../settings/usage/[[invoice]]/+page.ts | 13 +-- .../storage/bucket-[bucket]/+page.svelte | 3 +- .../storage/bucket-[bucket]/+page.ts | 4 +- .../bucket-[bucket]/create-file/step1.svelte | 6 +- .../settings/updateMaxFileSize.svelte | 6 +- .../project-[project]/updateVariables.svelte | 6 +- src/routes/(public)/(guest)/login/+page.ts | 2 +- src/routes/(public)/(guest)/register/+page.ts | 2 +- src/routes/+layout.svelte | 2 +- 97 files changed, 444 insertions(+), 445 deletions(-) diff --git a/.gitignore b/.gitignore index 031f4a1f91..2f74d4c156 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .envrc .vscode +.zed node_modules /build /.svelte-kit diff --git a/src/lib/components/backupDatabaseAlert.svelte b/src/lib/components/backupDatabaseAlert.svelte index dd1b30559a..4aec42b1a6 100644 --- a/src/lib/components/backupDatabaseAlert.svelte +++ b/src/lib/components/backupDatabaseAlert.svelte @@ -1,6 +1,5 @@ {#if $showPolicyAlert && isCloud && $organization?.$id && $page.url.pathname.match(/\/databases\/database-[^/]+$/)} - {@const isFreePlan = $organization?.billingPlan === BillingPlan.FREE} + {@const isFreePlan = $organization?.billingPlan === BillingPlan.Tier0} {@const subtitle = isFreePlan ? 'Upgrade your plan to ensure your data stays safe and backed up' diff --git a/src/lib/components/backupRestoreBox.svelte b/src/lib/components/backupRestoreBox.svelte index 842c15e19e..2882f5f854 100644 --- a/src/lib/components/backupRestoreBox.svelte +++ b/src/lib/components/backupRestoreBox.svelte @@ -1,10 +1,10 @@ -{#if $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)} +{#if $organization?.$id && $organization?.billingPlan === BillingPlan.Tier0 && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)} diff --git a/src/lib/components/billing/alerts/missingPaymentMethod.svelte b/src/lib/components/billing/alerts/missingPaymentMethod.svelte index 1dbfda5659..e279a3f472 100644 --- a/src/lib/components/billing/alerts/missingPaymentMethod.svelte +++ b/src/lib/components/billing/alerts/missingPaymentMethod.svelte @@ -1,14 +1,14 @@ -{#if ($orgMissingPaymentMethod.billingPlan === BillingPlan.PRO || $orgMissingPaymentMethod.billingPlan === BillingPlan.SCALE) && !$orgMissingPaymentMethod.paymentMethodId && !$orgMissingPaymentMethod.backupPaymentMethodId && !hideBillingHeaderRoutes.includes($page.url.pathname)} +{#if ($orgMissingPaymentMethod.billingPlan === BillingPlan.Tier1 || $orgMissingPaymentMethod.billingPlan === BillingPlan.Tier2) && !$orgMissingPaymentMethod.paymentMethodId && !$orgMissingPaymentMethod.backupPaymentMethodId && !hideBillingHeaderRoutes.includes($page.url.pathname)} diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index c58ad72683..ef835b2ec6 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 } from '@appwrite.io/console'; import { Button } from '$lib/elements/forms'; import { organization } from '$lib/stores/organization'; import { activeHeaderAlert } from '$routes/(console)/store'; @@ -21,7 +21,7 @@ } -{#if show && $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && !$page.url.pathname.includes('/console/account')} +{#if show && $organization?.$id && $organization?.billingPlan === BillingPlan.Tier0 && !$page.url.pathname.includes('/console/account')}
Get $50 Cloud credits for Appwrite Pro. diff --git a/src/lib/components/billing/alerts/paymentMandate.svelte b/src/lib/components/billing/alerts/paymentMandate.svelte index fa7f75a858..8a7e06b16e 100644 --- a/src/lib/components/billing/alerts/paymentMandate.svelte +++ b/src/lib/components/billing/alerts/paymentMandate.svelte @@ -8,8 +8,7 @@ import { confirmSetup } from '$lib/stores/stripe'; async function verifyPaymentMethod() { - const method = await sdk.forConsole.billing.setupPaymentMandate( - $organization.$id, + const method = await sdk.forConsole.account.updatePaymentMethodMandateOptions( $paymentMissingMandate.$id ); await confirmSetup(method.clientSecret, method.$id); diff --git a/src/lib/components/billing/couponInput.svelte b/src/lib/components/billing/couponInput.svelte index 369619afed..0f610046b7 100644 --- a/src/lib/components/billing/couponInput.svelte +++ b/src/lib/components/billing/couponInput.svelte @@ -1,15 +1,15 @@

- Your payment method will be charged this amount plus usage fees every 30 days {!currentPlan.trialDays + Your payment method will be charged this amount plus usage fees every 30 days {!currentPlan.trial ? `starting ${toLocaleDate(billingPayDate.toString())}` : ` after your trial period ends on ${toLocaleDate(trialEndDate.toString())}`}.

diff --git a/src/lib/components/billing/planComparisonBox.svelte b/src/lib/components/billing/planComparisonBox.svelte index c48dabfc38..1ab5d8fad2 100644 --- a/src/lib/components/billing/planComparisonBox.svelte +++ b/src/lib/components/billing/planComparisonBox.svelte @@ -1,10 +1,10 @@ {#if billingPlan} @@ -24,7 +24,7 @@ name="plan" bind:group={billingPlan} disabled={anyOrgFree || !selfService} - value={BillingPlan.FREE} + value={BillingPlan.Tier0} tooltipShow={anyOrgFree} tooltipText="You are limited to 1 Free organization per account." padding={1.5}> @@ -34,7 +34,7 @@ class:u-opacity-50={disabled}>

{tierFree.name} - {#if $organization?.billingPlan === BillingPlan.FREE && !isNewOrg} + {#if $organization?.billingPlan === BillingPlan.Tier0 && !isNewOrg} Current plan {/if}

@@ -54,7 +54,7 @@ name="plan" disabled={!selfService} bind:group={billingPlan} - value={BillingPlan.PRO} + value={BillingPlan.Tier1} padding={1.5}>

{tierPro.name} - {#if $organization?.billingPlan === BillingPlan.PRO && !isNewOrg} + {#if $organization?.billingPlan === BillingPlan.Tier1 && !isNewOrg} Current plan {/if}

@@ -76,18 +76,18 @@ - {#if $organization?.billingPlan === BillingPlan.SCALE} + {#if $organization?.billingPlan === BillingPlan.Tier2}
  • {tierScale.name} - {#if $organization?.billingPlan === BillingPlan.SCALE && !isNewOrg} + {#if $organization?.billingPlan === BillingPlan.Tier2 && !isNewOrg} Current plan {/if}

    diff --git a/src/lib/components/billing/selectPaymentMethod.svelte b/src/lib/components/billing/selectPaymentMethod.svelte index 937d6bc67c..1f57582caf 100644 --- a/src/lib/components/billing/selectPaymentMethod.svelte +++ b/src/lib/components/billing/selectPaymentMethod.svelte @@ -1,14 +1,15 @@ {#if isFree} - Usage on the {$plansInfo?.get(BillingPlan.FREE).name} plan is limited for the following resources. + Usage on the {$plansInfo?.get(BillingPlan.Tier0).name} plan is limited for the following resources. Next billing period: {toLocaleDate(nextDate)}. - {:else if org.billingPlan === BillingPlan.PRO} + {:else if org.billingPlan === BillingPlan.Tier1}

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

    - {:else if org.billingPlan === BillingPlan.SCALE} + {:else if org.billingPlan === BillingPlan.Tier2}

    Usage on the Scale plan will be charged at the end of each billing period at the following rates. Next billing period: {toLocaleDate(nextDate)}. diff --git a/src/lib/components/billing/validateCreditModal.svelte b/src/lib/components/billing/validateCreditModal.svelte index 961e041442..f444e247ec 100644 --- a/src/lib/components/billing/validateCreditModal.svelte +++ b/src/lib/components/billing/validateCreditModal.svelte @@ -18,7 +18,7 @@ async function addCoupon() { try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.console.getCopon(coupon); couponData = response; dispatch('validation', couponData); coupon = null; diff --git a/src/lib/components/bottomModalAlert.svelte b/src/lib/components/bottomModalAlert.svelte index 03ace8873f..f4392cb9a6 100644 --- a/src/lib/components/bottomModalAlert.svelte +++ b/src/lib/components/bottomModalAlert.svelte @@ -10,7 +10,7 @@ } from '$lib/stores/bottom-alerts'; import { onMount } from 'svelte'; import { organization } from '$lib/stores/organization'; - import { BillingPlan } from '$lib/constants'; + import { BillingPlan } from '@appwrite.io/console'; import { upgradeURL } from '$lib/stores/billing'; import { addBottomModalAlerts } from '$routes/(console)/bottomAlerts'; import { project } from '$routes/(console)/project-[project]/store'; @@ -74,10 +74,10 @@ case 'free': return false; case 'pro': - return organizationPlan === BillingPlan.FREE; + return organizationPlan === BillingPlan.Tier0; case 'scale': return ( - organizationPlan === BillingPlan.FREE || organizationPlan === BillingPlan.PRO + organizationPlan === BillingPlan.Tier0 || organizationPlan === BillingPlan.Tier1 ); } } diff --git a/src/lib/components/creditCardInfo.svelte b/src/lib/components/creditCardInfo.svelte index f187431340..27301a97e9 100644 --- a/src/lib/components/creditCardInfo.svelte +++ b/src/lib/components/creditCardInfo.svelte @@ -1,10 +1,10 @@

    diff --git a/src/lib/components/support.svelte b/src/lib/components/support.svelte index 66d922d410..7e2ec964e9 100644 --- a/src/lib/components/support.svelte +++ b/src/lib/components/support.svelte @@ -6,7 +6,7 @@ import { showSupportModal } from '$routes/(console)/wizard/support/store'; import { isCloud } from '$lib/system'; import { organization } from '$lib/stores/organization'; - import { BillingPlan } from '$lib/constants'; + import { BillingPlan } from '@appwrite.io/console'; import { trackEvent } from '$lib/actions/analytics'; import { localeTimezoneName, utcHourToLocaleHour } from '$lib/helpers/date'; import { upgradeURL } from '$lib/stores/billing'; @@ -14,8 +14,8 @@ export let show = false; $: isPaid = - $organization?.billingPlan === BillingPlan.PRO || - $organization?.billingPlan === BillingPlan.SCALE; + $organization?.billingPlan === BillingPlan.Tier1 || + $organization?.billingPlan === BillingPlan.Tier2; $: supportTimings = `${utcHourToLocaleHour('16:00')} - ${utcHourToLocaleHour('00:00')} ${localeTimezoneName()}`; @@ -30,7 +30,7 @@

    {/if}
    - {#if $organization?.billingPlan === BillingPlan.FREE} + {#if $organization?.billingPlan === BillingPlan.Tier0} to increase your log retention for a longer period. {/if} diff --git a/src/lib/layout/containerButton.svelte b/src/lib/layout/containerButton.svelte index e0b0512d35..f1fc32b7bd 100644 --- a/src/lib/layout/containerButton.svelte +++ b/src/lib/layout/containerButton.svelte @@ -1,13 +1,13 @@ diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index a621bff958..a200112251 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -8,7 +8,7 @@ EstimatedTotalBox, SelectPaymentMethod } from '$lib/components/billing'; - import { BillingPlan, Dependencies } from '$lib/constants'; + import { Dependencies } from '$lib/constants'; import { Button, Form, FormList, InputSelect, InputTags, InputText } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; import { @@ -16,13 +16,12 @@ WizardSecondaryContent, WizardSecondaryFooter } from '$lib/layout'; - import { type PaymentList } from '$lib/sdk/billing'; import { app } from '$lib/stores/app'; import { campaigns } from '$lib/stores/campaigns'; import { addNotification } from '$lib/stores/notifications'; import { organizationList, type Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; - import { ID } from '@appwrite.io/console'; + import { ID, BillingPlan, type Models } from '@appwrite.io/console'; import { onMount } from 'svelte'; import { writable } from 'svelte/store'; @@ -49,7 +48,7 @@ let formComponent: Form; let couponForm: Form; let isSubmitting = writable(false); - let methods: PaymentList; + let methods: Models.PaymentMethodList; let paymentMethodId: string; let collaborators: string[]; let taxId: string; @@ -69,7 +68,7 @@ let coupon: string; let couponData = data?.couponData; let campaign = campaigns.get(data?.couponData?.campaign ?? data?.campaign); - let billingPlan = BillingPlan.PRO; + let billingPlan = BillingPlan.Tier1; onMount(async () => { await loadPaymentMethods(); @@ -86,7 +85,7 @@ }); async function loadPaymentMethods() { - const methodList = await sdk.forConsole.billing.listPaymentMethods(); + const methodList = await sdk.forConsole.account.listPaymentMethods(); const filteredMethods = methodList.paymentMethods.filter((method) => !!method?.last4); methods = { paymentMethods: filteredMethods, total: filteredMethods.length }; paymentMethodId = @@ -101,21 +100,21 @@ let org: Organization; // Create new org if (selectedOrgId === newOrgId) { - org = await sdk.forConsole.billing.createOrganization( + org = (await sdk.forConsole.organizations.create( newOrgId, name, billingPlan, paymentMethodId - ); + )) as unknown as Organization; } // Upgrade existing org - else if (selectedOrg?.billingPlan === BillingPlan.FREE) { - org = await sdk.forConsole.billing.updatePlan( + else if (selectedOrg?.billingPlan === BillingPlan.Tier0) { + org = (await sdk.forConsole.organizations.updatePlan( selectedOrg.$id, billingPlan, paymentMethodId, null - ); + )) as unknown as Organization; } // Existing pro org else { @@ -124,12 +123,12 @@ // Add coupon if (couponData?.code) { - await sdk.forConsole.billing.addCredit(org.$id, couponData.code); + await sdk.forConsole.organizations.addCredit(org.$id, couponData.code); } // Add budget if (billingBudget) { - await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); + await sdk.forConsole.organizations.updateBudget(org.$id, billingBudget, [75]); } // Add collaborators @@ -148,7 +147,7 @@ // Add tax ID if (taxId) { - await sdk.forConsole.billing.updateTaxId(org.$id, taxId); + await sdk.forConsole.organizations.setBillingTaxId(org.$id, taxId); } trackEvent(Submit.CreditRedeem, { coupon: couponData.code, @@ -172,7 +171,7 @@ async function addCoupon() { try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.console.getCopon(coupon); couponData = response; coupon = null; addNotification({ @@ -212,7 +211,7 @@ placeholder="Select organization" id="organization" /> {/if} - {#if selectedOrgId && (selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId)} + {#if selectedOrgId && (selectedOrg?.billingPlan !== BillingPlan.Tier1 || !selectedOrg?.paymentMethodId)} {#if selectedOrgId === newOrgId}
    {/if} - {#if selectedOrg?.$id && selectedOrg?.billingPlan !== BillingPlan.FREE} + {#if selectedOrg?.$id && selectedOrg?.billingPlan !== BillingPlan.Tier0}
    diff --git a/src/routes/(console)/apply-credit/+page.ts b/src/routes/(console)/apply-credit/+page.ts index 96b06dd30d..ed3b9a903b 100644 --- a/src/routes/(console)/apply-credit/+page.ts +++ b/src/routes/(console)/apply-credit/+page.ts @@ -11,7 +11,7 @@ export const load: PageLoad = async ({ url }) => { let couponData: Coupon; const code = url.searchParams.get('code'); try { - couponData = await sdk.forConsole.billing.getCoupon(code); + couponData = await sdk.forConsole.console.getCopon(code); } catch (e) { redirect(303, base); } diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 137ede330a..1f965a2c43 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -11,24 +11,24 @@ } from '$lib/components/billing'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import Default from '$lib/components/roles/default.svelte'; - import { BillingPlan, Dependencies } from '$lib/constants'; + import { Dependencies } from '$lib/constants'; import { Button, Form, FormList, InputTags, InputText, Label } from '$lib/elements/forms'; import { WizardSecondaryContainer, WizardSecondaryContent, WizardSecondaryFooter } from '$lib/layout'; - import type { Coupon, PaymentList } from '$lib/sdk/billing'; + import type { Coupon } from '$lib/sdk/billing'; import { tierToPlan } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { organizationList, type Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; - import { ID } from '@appwrite.io/console'; + import { ID, BillingPlan, type Models } from '@appwrite.io/console'; import { onMount } from 'svelte'; import { writable } from 'svelte/store'; $: anyOrgFree = $organizationList.teams?.some( - (org) => (org as Organization)?.billingPlan === BillingPlan.FREE + (org) => (org as Organization)?.billingPlan === BillingPlan.Tier0 ); const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/i; let previousPage: string = base; @@ -41,9 +41,9 @@ let formComponent: Form; let isSubmitting = writable(false); - let methods: PaymentList; + let methods: Models.PaymentMethodList; let name: string; - let billingPlan: BillingPlan = BillingPlan.FREE; + let billingPlan: BillingPlan = BillingPlan.Tier0; let paymentMethodId: string; let collaborators: string[] = []; let couponData: Partial = { @@ -60,7 +60,7 @@ if ($page.url.searchParams.has('coupon')) { const coupon = $page.url.searchParams.get('coupon'); try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.console.getCopon(coupon); couponData = response; } catch (e) { couponData = { @@ -80,12 +80,12 @@ } } if (anyOrgFree) { - billingPlan = BillingPlan.PRO; + billingPlan = BillingPlan.Tier1; } }); async function loadPaymentMethods() { - methods = await sdk.forConsole.billing.listPaymentMethods(); + methods = await sdk.forConsole.account.listPaymentMethods(); paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null; } @@ -93,31 +93,31 @@ try { let org: Organization; - if (billingPlan === BillingPlan.FREE) { - org = await sdk.forConsole.billing.createOrganization( + if (billingPlan === BillingPlan.Tier0) { + org = (await sdk.forConsole.organizations.create( ID.unique(), name, - BillingPlan.FREE, + BillingPlan.Tier0, null, null - ); + )) as unknown as Organization; } else { - org = await sdk.forConsole.billing.createOrganization( + org = (await sdk.forConsole.organizations.create( ID.unique(), name, billingPlan, paymentMethodId, null - ); + )) as unknown as Organization; //Add budget if (billingBudget) { - await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]); + await sdk.forConsole.organizations.updateBudget(org.$id, billingBudget, [75]); } //Add coupon if (couponData?.code) { - await sdk.forConsole.billing.addCredit(org.$id, couponData.code); + await sdk.forConsole.organizations.addCredit(org.$id, couponData.code); trackEvent(Submit.CreditRedeem); } @@ -137,7 +137,7 @@ // Add tax ID if (taxId) { - await sdk.forConsole.billing.updateTaxId(org.$id, taxId); + await sdk.forConsole.organizations.setBillingTaxId(org.$id, taxId); } } @@ -163,7 +163,7 @@ } } - $: if (billingPlan !== BillingPlan.FREE) { + $: if (billingPlan !== BillingPlan.Tier0) { loadPaymentMethods(); } @@ -190,7 +190,7 @@ .

    - {#if billingPlan !== BillingPlan.FREE} + {#if billingPlan !== BillingPlan.Tier0} - + {#if !couponData?.code}

    - {#if $organization?.billingPlan === BillingPlan.FREE} + {#if $organization?.billingPlan === BillingPlan.Tier0} Budget caps are a Pro plan feature @@ -92,7 +93,7 @@ - {#if $organization?.billingPlan === BillingPlan.FREE} + {#if $organization?.billingPlan === BillingPlan.Tier0}
  • - {#if $organization?.billingPlan !== BillingPlan.FREE && extraUsage > 0} + {#if $organization?.billingPlan !== BillingPlan.Tier0 && extraUsage > 0} Add-ons
    - {$organization?.billingPlan === BillingPlan.FREE + {$organization?.billingPlan === BillingPlan.Tier0 ? formatCurrency(0) : formatCurrency(currentInvoice?.amount ?? 0)}
    @@ -159,7 +158,7 @@
    - {#if $organization?.billingPlan === BillingPlan.FREE} + {#if $organization?.billingPlan === BillingPlan.Tier0}