From 0bece9d2737141af8a59816be85e94b89687cd38 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 18:37:46 +0530 Subject: [PATCH 1/2] fix redirect url for customer portal sent for electron app --- src/services/billingService.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/services/billingService.ts b/src/services/billingService.ts index 5d95e345a..ccacb6d5a 100644 --- a/src/services/billingService.ts +++ b/src/services/billingService.ts @@ -170,12 +170,7 @@ class billingService { action: string ) { try { - let redirectURL; - if (isElectron()) { - redirectURL = DESKTOP_REDIRECT_URL; - } else { - redirectURL = `${window.location.origin}/gallery`; - } + const redirectURL = this.getRedirectURL(); window.location.href = `${getPaymentsURL()}?productID=${productID}&paymentToken=${paymentToken}&action=${action}&redirectURL=${redirectURL}`; } catch (e) { logError(e, 'unable to get payments url'); @@ -185,9 +180,10 @@ class billingService { public async redirectToCustomerPortal() { try { + const redirectURL = this.getRedirectURL(); const response = await HTTPService.get( `${ENDPOINT}/billing/stripe/customer-portal`, - { redirectURL: `${window.location.origin}/gallery` }, + { redirectURL }, { 'X-Auth-Token': getToken(), } @@ -198,6 +194,14 @@ class billingService { throw e; } } + + public getRedirectURL() { + if (isElectron()) { + return DESKTOP_REDIRECT_URL; + } else { + return `${window.location.origin}/gallery`; + } + } } export default new billingService(); From b206f66a8e91de451059eeef55bc536567370b12 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 18:53:32 +0530 Subject: [PATCH 2/2] use payment url to decide desktop redirect url root --- src/constants/billing/index.ts | 5 ++++- src/services/billingService.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/constants/billing/index.ts b/src/constants/billing/index.ts index b445cbd96..66883392a 100644 --- a/src/constants/billing/index.ts +++ b/src/constants/billing/index.ts @@ -1 +1,4 @@ -export const DESKTOP_REDIRECT_URL = 'https://payments.ente.io/desktop-redirect'; +import { getPaymentsURL } from 'utils/common/apiUtil'; + +export const getDesktopRedirectURL = () => + `${getPaymentsURL()}/desktop-redirect`; diff --git a/src/services/billingService.ts b/src/services/billingService.ts index ccacb6d5a..19807bd16 100644 --- a/src/services/billingService.ts +++ b/src/services/billingService.ts @@ -6,7 +6,7 @@ import { logError } from 'utils/sentry'; import { getPaymentToken } from './userService'; import { Plan, Subscription } from 'types/billing'; import isElectron from 'is-electron'; -import { DESKTOP_REDIRECT_URL } from 'constants/billing'; +import { getDesktopRedirectURL } from 'constants/billing'; const ENDPOINT = getEndpoint(); @@ -197,7 +197,7 @@ class billingService { public getRedirectURL() { if (isElectron()) { - return DESKTOP_REDIRECT_URL; + return getDesktopRedirectURL(); } else { return `${window.location.origin}/gallery`; }