Merge pull request #720 from ente-io/fix-customer-portal-open

fix redirect url for customer portal sent for electron app
This commit is contained in:
Manav 2022-09-23 19:08:45 +05:30 committed by GitHub
commit 3d4382effe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View file

@ -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`;

View file

@ -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();