From 3f2bb5ba03a309db1960a8cbb3b1278ca55e4db2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 19 Feb 2025 08:45:35 +0000 Subject: [PATCH] Fix: coupon fetch endpoint separate coupon fetch based on whether or not the user is logged in --- src/lib/components/billing/couponInput.svelte | 2 +- .../billing/validateCreditModal.svelte | 2 +- src/lib/sdk/billing.ts | 18 +++++++++++++++++- src/lib/stores/billing.ts | 2 +- src/routes/(console)/apply-credit/+page.ts | 2 +- .../(console)/create-organization/+page.svelte | 2 +- .../billing/wizard/addCredit.svelte | 2 +- .../change-plan/+page.svelte | 2 +- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/lib/components/billing/couponInput.svelte b/src/lib/components/billing/couponInput.svelte index 369619afe..a6c1658ec 100644 --- a/src/lib/components/billing/couponInput.svelte +++ b/src/lib/components/billing/couponInput.svelte @@ -17,7 +17,7 @@ async function addCoupon() { try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.billing.getCouponAccount(coupon); couponData = response; dispatch('validation', couponData); coupon = null; diff --git a/src/lib/components/billing/validateCreditModal.svelte b/src/lib/components/billing/validateCreditModal.svelte index 961e04144..deefc106f 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.billing.getCouponAccount(coupon); couponData = response; dispatch('validation', couponData); coupon = null; diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 5f2a549c2..d5d158b0b 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -891,7 +891,7 @@ export class Billing { } } - async getCoupon(couponId: string): Promise { + async getCouponAccount(couponId: string): Promise { const path = `/account/coupons/${couponId}`; const params = { couponId @@ -907,6 +907,22 @@ export class Billing { ); } + async getCoupon(couponId: string): Promise { + const path = `/console/coupons/${couponId}`; + const params = { + couponId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'GET', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async setBillingAddress( organizationId: string, billingAddressId: string diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 636853952..83cb2d1d6 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -465,7 +465,7 @@ export async function checkForNewDevUpgradePro(org: Organization) { if (isDismissed) return; // check if coupon already applied try { - await sdk.forConsole.billing.getCoupon(NEW_DEV_PRO_UPGRADE_COUPON); + await sdk.forConsole.billing.getCouponAccount(NEW_DEV_PRO_UPGRADE_COUPON); } catch (e) { return; } diff --git a/src/routes/(console)/apply-credit/+page.ts b/src/routes/(console)/apply-credit/+page.ts index 138e59ee3..865dc3a97 100644 --- a/src/routes/(console)/apply-credit/+page.ts +++ b/src/routes/(console)/apply-credit/+page.ts @@ -12,7 +12,7 @@ export const load: PageLoad = async ({ url }) => { let campaign: Campaign; const code = url.searchParams.get('code'); try { - couponData = await sdk.forConsole.billing.getCoupon(code); + couponData = await sdk.forConsole.billing.getCouponAccount(code); if (couponData.campaign) { campaign = await sdk.forConsole.billing.getCampaign(couponData.campaign); } diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index 56c9a9335..2c689296b 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -61,7 +61,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.billing.getCouponAccount(coupon); couponData = response; } catch (e) { couponData = { diff --git a/src/routes/(console)/organization-[organization]/billing/wizard/addCredit.svelte b/src/routes/(console)/organization-[organization]/billing/wizard/addCredit.svelte index d62ffc7ab..d8933fa6b 100644 --- a/src/routes/(console)/organization-[organization]/billing/wizard/addCredit.svelte +++ b/src/routes/(console)/organization-[organization]/billing/wizard/addCredit.svelte @@ -17,7 +17,7 @@ async function validateCoupon() { if (couponData?.status === 'active') return; try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.billing.getCouponAccount(coupon); couponData = response; $addCreditWizardStore.coupon = coupon; coupon = null; diff --git a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte index 839d3031d..88021270f 100644 --- a/src/routes/(console)/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/(console)/organization-[organization]/change-plan/+page.svelte @@ -83,7 +83,7 @@ if ($page.url.searchParams.has('code')) { const coupon = $page.url.searchParams.get('code'); try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.billing.getCouponAccount(coupon); couponData = response; } catch (e) { couponData = {