Fix: coupon fetch endpoint

separate coupon fetch based on whether or not the user is logged in
This commit is contained in:
Damodar Lohani
2025-02-19 08:45:35 +00:00
parent 009a93d550
commit 3f2bb5ba03
8 changed files with 24 additions and 8 deletions
@@ -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;
@@ -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;
+17 -1
View File
@@ -891,7 +891,7 @@ export class Billing {
}
}
async getCoupon(couponId: string): Promise<Coupon> {
async getCouponAccount(couponId: string): Promise<Coupon> {
const path = `/account/coupons/${couponId}`;
const params = {
couponId
@@ -907,6 +907,22 @@ export class Billing {
);
}
async getCoupon(couponId: string): Promise<Coupon> {
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
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}
@@ -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 = {
@@ -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;
@@ -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 = {