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 5d95e345a..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(); @@ -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 getDesktopRedirectURL(); + } else { + return `${window.location.origin}/gallery`; + } + } } export default new billingService();