From bdda2d4987751e114cddb2eeab7567fab673efae Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 17 Sep 2025 10:57:40 +0500 Subject: [PATCH] web: add support for direct checkout --- apps/web/package-lock.json | 2 +- apps/web/src/navigation/index.ts | 2 +- apps/web/src/views/payments.tsx | 34 +++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/apps/web/package-lock.json b/apps/web/package-lock.json index a6cfd1dcb..bd92fa6da 100644 --- a/apps/web/package-lock.json +++ b/apps/web/package-lock.json @@ -504,7 +504,7 @@ }, "../desktop": { "name": "@notesnook/desktop", - "version": "3.2.3", + "version": "3.3.0-beta.1", "hasInstallScript": true, "license": "GPL-3.0-or-later", "dependencies": { diff --git a/apps/web/src/navigation/index.ts b/apps/web/src/navigation/index.ts index 956d34f87..db7995901 100644 --- a/apps/web/src/navigation/index.ts +++ b/apps/web/src/navigation/index.ts @@ -70,7 +70,7 @@ export function useQueryParams(parseFn = parseQuery) { return [parseFn(querystring)]; } -function parseQuery(querystring: string) { +function parseQuery(querystring: string): Partial> { return Object.fromEntries(new URLSearchParams(querystring).entries()); } diff --git a/apps/web/src/views/payments.tsx b/apps/web/src/views/payments.tsx index 2de44753e..1a0f1d9b8 100644 --- a/apps/web/src/views/payments.tsx +++ b/apps/web/src/views/payments.tsx @@ -27,23 +27,43 @@ import { Loader } from "../components/loader"; import { IS_DEV } from "../dialogs/buy-dialog/helpers"; function Payments() { - const [{ _ptxn }] = useQueryParams(); + const [{ _ptxn, priceId, email, quantity }] = useQueryParams(); const [isLoading, setIsLoading] = useState(true); useEffect(() => { - if (!_ptxn) return hardNavigate("/notes"); + if (!_ptxn && !priceId) return hardNavigate("/notes"); (async function () { const paddle = await initializePaddle({ token: CLIENT_PADDLE_TOKEN, environment: IS_DEV ? "sandbox" : "production" }); + if (!paddle) return hardNavigate("/notes"); + setIsLoading(false); - paddle?.Checkout.open({ - transactionId: _ptxn, - settings: { displayMode: "overlay" } - }); + if (_ptxn) { + paddle.Checkout.open({ + transactionId: _ptxn, + settings: { displayMode: "overlay" } + }); + } else if (priceId) { + paddle.Checkout.open({ + items: [ + { + priceId, + quantity: + quantity && !isNaN(parseInt(quantity)) ? parseInt(quantity) : 1 + } + ], + customer: email + ? { + email + } + : undefined, + settings: { displayMode: "overlay" } + }); + } })(); - }, [_ptxn]); + }, [_ptxn, priceId, email, quantity]); return isLoading ? (