From 23a52fdf214e8356055e7d18f73dac9be8a3f370 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 28 May 2025 16:05:24 -0700 Subject: [PATCH 1/4] fix: remove duplicate success notification --- src/lib/components/billing/validateCreditModal.svelte | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lib/components/billing/validateCreditModal.svelte b/src/lib/components/billing/validateCreditModal.svelte index 130532a7b..b2c3f6190 100644 --- a/src/lib/components/billing/validateCreditModal.svelte +++ b/src/lib/components/billing/validateCreditModal.svelte @@ -38,14 +38,6 @@ message: 'Credits applied successfully' }); } - couponData = response; - dispatch('validation', couponData); - coupon = null; - show = false; - addNotification({ - type: 'success', - message: 'Credits applied successfully' - }); } catch (e) { error = e.message; } From 3e99216a3303bff77612500d005a9e493ee140fd Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 28 May 2025 17:03:09 -0700 Subject: [PATCH 2/4] fix: ensure coupon is in request when changing plan --- .../(console)/create-organization/+page.svelte | 17 ++++++----------- .../change-plan/+page.svelte | 7 +++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 77049390e..7411b7a08 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -6,12 +6,12 @@ import { PlanComparisonBox, PlanSelection, SelectPaymentMethod } from '$lib/components/billing'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import { BillingPlan, Dependencies } from '$lib/constants'; - import { Button, Form, InputTags, InputText } from '$lib/elements/forms'; + import { Button, type Form, InputTags, InputText } from '$lib/elements/forms'; import { Wizard } from '$lib/layout'; import type { Coupon } from '$lib/sdk/billing'; import { isOrganization, tierToPlan } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; - import { type OrganizationError, type Organization } from '$lib/stores/organization'; + import type { OrganizationError, Organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { confirmPayment } from '$lib/stores/stripe'; import { ID } from '@appwrite.io/console'; @@ -35,11 +35,6 @@ let billingPlan: BillingPlan = BillingPlan.FREE; let paymentMethodId: string; let collaborators: string[] = []; - let couponData: Partial = { - code: null, - status: null, - credits: null - }; let taxId: string; let billingBudget: number; @@ -54,9 +49,9 @@ const coupon = page.url.searchParams.get('coupon'); try { const response = await sdk.forConsole.billing.getCouponAccount(coupon); - couponData = response; + selectedCoupon = response; } catch (e) { - couponData = { + selectedCoupon = { code: null, status: null, credits: null @@ -127,7 +122,7 @@ selectedPlan, paymentMethodId, null, - couponData.code ? couponData.code : null, + selectedCoupon.code ? selectedCoupon.code : null, collaborators, billingBudget, taxId @@ -148,7 +143,7 @@ '', clientSecret, paymentMethodId, - '/console/create-organization?' + params.toString() + `/console/create-organization?${params}` ); await validate(org.teamId, collaborators); } diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index ae83f8c26..84b4d093f 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -54,7 +54,6 @@ let showCreditModal = false; let feedbackDowngradeReason: string; let feedbackMessage: string; - let couponData: Partial = data.coupon; afterNavigate(({ from }) => { previousPage = from?.url?.pathname || previousPage; @@ -63,9 +62,9 @@ if (page.url.searchParams.has('code')) { const coupon = page.url.searchParams.get('code'); try { - couponData = await sdk.forConsole.billing.getCouponAccount(coupon); + selectedCoupon = await sdk.forConsole.billing.getCouponAccount(coupon); } catch (e) { - couponData = { + selectedCoupon = { code: null, status: null, credits: null @@ -191,7 +190,7 @@ selectedPlan, paymentMethodId, null, - couponData?.code, + selectedCoupon?.code, newCollaborators, billingBudget, taxId ? taxId : null From d098dbc6d01a605688b77b7998c24c405d3779cf Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 29 May 2025 13:00:12 -0700 Subject: [PATCH 3/4] feat: use getCouponAccount() instead of getCoupon() for coupon retrieval getCouponAccount() better validates coupons for authenticated users because it will return an error if the user has already used the coupon. --- src/routes/(console)/apply-credit/+page.svelte | 10 +++++----- src/routes/(console)/create-organization/+page.ts | 2 +- .../organization-[organization]/change-plan/+page.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 0c743dcad..276b5be13 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -5,10 +5,10 @@ import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { CreditsApplied, SelectPaymentMethod } from '$lib/components/billing'; import { BillingPlan, Dependencies } from '$lib/constants'; - import { Button, Form, InputSelect, InputTags, InputText } from '$lib/elements/forms'; + import { Button, type Form, InputSelect, InputTags, InputText } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; import { Wizard } from '$lib/layout'; - import { type PaymentList, type Plan } from '$lib/sdk/billing'; + import type { PaymentList, Plan } from '$lib/sdk/billing'; import { addNotification } from '$lib/stores/notifications'; import { organizationList, @@ -72,7 +72,7 @@ let tempOrgId = null; let currentPlan: Plan; - $: onlyNewOrgs = (campaign && campaign.onlyNewOrgs) || (couponData && couponData.onlyNewOrgs); + $: onlyNewOrgs = campaign?.onlyNewOrgs || couponData?.onlyNewOrgs; $: selectedOrgId = tempOrgId; @@ -174,7 +174,7 @@ '', clientSecret, paymentMethodId, - '/console/apply-credit?' + params.toString() + `/console/apply-credit?${params}` ); org = await sdk.forConsole.billing.validateOrganization(org.teamId, collaborators); } @@ -205,7 +205,7 @@ async function addCoupon() { try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.billing.getCouponAccount(coupon); couponData = response; coupon = null; addNotification({ diff --git a/src/routes/(console)/create-organization/+page.ts b/src/routes/(console)/create-organization/+page.ts index c3eff35d6..150cd76f3 100644 --- a/src/routes/(console)/create-organization/+page.ts +++ b/src/routes/(console)/create-organization/+page.ts @@ -42,7 +42,7 @@ async function getCoupon(url: URL): Promise { if (url.searchParams.has('code')) { const coupon = url.searchParams.get('code'); try { - return sdk.forConsole.billing.getCoupon(coupon); + return sdk.forConsole.billing.getCouponAccount(coupon); } catch (e) { return null; } diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.ts b/src/routes/(console)/organization-[organization]/change-plan/+page.ts index e3d79c69e..b698d60dc 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.ts +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.ts @@ -49,7 +49,7 @@ async function getCoupon(url: URL): Promise { if (url.searchParams.has('code')) { const coupon = url.searchParams.get('code'); try { - return sdk.forConsole.billing.getCoupon(coupon); + return sdk.forConsole.billing.getCouponAccount(coupon); } catch (e) { return null; } From a782590f85d4de0d646b2a6269fe83d9fb4afdf9 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 30 May 2025 16:28:57 +0200 Subject: [PATCH 4/4] fix: import --- src/routes/(console)/apply-credit/+page.svelte | 2 +- src/routes/(console)/create-organization/+page.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 276b5be13..dbb3add04 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -5,7 +5,7 @@ import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { CreditsApplied, SelectPaymentMethod } from '$lib/components/billing'; import { BillingPlan, Dependencies } from '$lib/constants'; - import { Button, type Form, InputSelect, InputTags, InputText } from '$lib/elements/forms'; + import { Button, Form, InputSelect, InputTags, InputText } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; import { Wizard } from '$lib/layout'; import type { PaymentList, Plan } from '$lib/sdk/billing'; diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 7411b7a08..d6aa47b66 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -6,7 +6,7 @@ import { PlanComparisonBox, PlanSelection, SelectPaymentMethod } from '$lib/components/billing'; import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte'; import { BillingPlan, Dependencies } from '$lib/constants'; - import { Button, type Form, InputTags, InputText } from '$lib/elements/forms'; + import { Button, Form, InputTags, InputText } from '$lib/elements/forms'; import { Wizard } from '$lib/layout'; import type { Coupon } from '$lib/sdk/billing'; import { isOrganization, tierToPlan } from '$lib/stores/billing';