From 01054e4c9aad1249a78b38dbf49399d354383d5a Mon Sep 17 00:00:00 2001 From: Diptesh Choudhuri Date: Fri, 25 Oct 2024 23:01:45 +0530 Subject: [PATCH] feat(website): close checkout overlay when it is completed --- apps/website/app/routes/me.tsx | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/apps/website/app/routes/me.tsx b/apps/website/app/routes/me.tsx index 2bb02632d7..2f5cdb795a 100644 --- a/apps/website/app/routes/me.tsx +++ b/apps/website/app/routes/me.tsx @@ -172,23 +172,27 @@ export default function Index() { initializePaddle({ token: loaderData.clientToken, environment: loaderData.isSandbox ? "sandbox" : undefined, - eventCallback: (data) => { - if (data.name === CheckoutEventNames.CHECKOUT_COMPLETED) { - paddle?.Checkout.close(); - const transactionId = data.data?.transaction_id; - if (!transactionId) throw new Error("Transaction ID not found"); - submit( - { transactionId }, - { - method: "POST", - encType: "application/json", - action: withQuery(".", { intent: "processPurchase" }), - }, - ); - } - }, }).then((paddleInstance) => { - if (paddleInstance) setPaddle(paddleInstance); + if (paddleInstance) { + paddleInstance.Update({ + eventCallback: (data) => { + if (data.name === CheckoutEventNames.CHECKOUT_COMPLETED) { + paddleInstance.Checkout.close(); + const transactionId = data.data?.transaction_id; + if (!transactionId) throw new Error("Transaction ID not found"); + submit( + { transactionId }, + { + method: "POST", + encType: "application/json", + action: withQuery(".", { intent: "processPurchase" }), + }, + ); + } + }, + }); + setPaddle(paddleInstance); + } }); }, []);