From 8d24a489f6de287f416548e43d9777517afddddd Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 15 Apr 2024 10:45:45 +0530 Subject: [PATCH 1/2] [desktop] Fix payment redirect Fixes: https://github.com/ente-io/ente/issues/1440 There were two issues: - It was a backward incompatible change to change the scheme from ente:// to next://. Revert. - We also need to setup a top level redirect when the user presses back without making any changes to their subscription. **Tested by** Running payments app and desktop app locally, and verifying that after interactions with the payments endpoint we go back to the desktop app's actual contents correctly. --- desktop/src/main.ts | 4 ++-- web/apps/payments/README.md | 5 +++-- web/apps/payments/src/services/billing-service.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/desktop/src/main.ts b/desktop/src/main.ts index 5425a0b5e5..4837210c87 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -32,7 +32,7 @@ import { isDev } from "./main/util"; /** * The URL where the renderer HTML is being served from. */ -export const rendererURL = "next://app"; +export const rendererURL = "ente://app"; /** * We want to hide our window instead of closing it when the user presses the @@ -63,7 +63,7 @@ export const allowWindowClose = (): void => { * production mode and `next dev` in development mode, whilst keeping the rest * of our code the same. * - * It uses protocol handlers to serve files from the "next://app" protocol + * It uses protocol handlers to serve files from the "ente://" protocol. * * - In development this is proxied to http://localhost:3000 * - In production it serves files from the `/out` directory diff --git a/web/apps/payments/README.md b/web/apps/payments/README.md index 959bedabe8..ebf3a63901 100644 --- a/web/apps/payments/README.md +++ b/web/apps/payments/README.md @@ -73,8 +73,9 @@ stripe: key: stripe_dev_key webhook-secret: stripe_dev_webhook_secret whitelisted-redirect-urls: - - "http://localhost:3000/gallery" - - "http://192.168.1.2:3001/frameRedirect" + - http://localhost:3000/gallery + - http://localhost:3001/desktop-redirect + - http://192.168.1.2:3001/frameRedirect path: success: ?status=success&session_id={CHECKOUT_SESSION_ID} cancel: ?status=fail&reason=canceled diff --git a/web/apps/payments/src/services/billing-service.ts b/web/apps/payments/src/services/billing-service.ts index 35f67660c0..9eb4fe1d5f 100644 --- a/web/apps/payments/src/services/billing-service.ts +++ b/web/apps/payments/src/services/billing-service.ts @@ -9,6 +9,12 @@ import { loadStripe } from "@stripe/stripe-js"; * redirect to the client or to some fallback URL. */ export const parseAndHandleRequest = async () => { + // See: [Note: Intercept payments redirection to desktop app] + if (window.location.pathname == "/desktop-redirect") { + window.location.href = "ente://app"; + return; + } + try { const urlParams = new URLSearchParams(window.location.search); const productID = urlParams.get("productID"); @@ -291,6 +297,8 @@ const redirectToApp = ( status: RedirectStatus, reason?: FailureReason, ) => { + // [Note: Intercept payments redirection to desktop app] + // // The desktop app passes "/desktop-redirect" as `redirectURL`. // This is just a placeholder, we want to intercept this and instead // redirect to the ente:// scheme protocol handler that is internally being From 95c0f53d212313349b3294d5ce2ccfb0bbe465b3 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 15 Apr 2024 10:56:06 +0530 Subject: [PATCH 2/2] Preserve parameters This was needed for the purchase success to be relayed back. --- web/apps/payments/src/services/billing-service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/apps/payments/src/services/billing-service.ts b/web/apps/payments/src/services/billing-service.ts index 9eb4fe1d5f..c0ba5da1e7 100644 --- a/web/apps/payments/src/services/billing-service.ts +++ b/web/apps/payments/src/services/billing-service.ts @@ -11,7 +11,9 @@ import { loadStripe } from "@stripe/stripe-js"; export const parseAndHandleRequest = async () => { // See: [Note: Intercept payments redirection to desktop app] if (window.location.pathname == "/desktop-redirect") { - window.location.href = "ente://app"; + const desktopRedirectURL = new URL("ente://app/gallery"); + desktopRedirectURL.search = new URL(window.location.href).search; + window.location.href = desktopRedirectURL.href; return; }