From b476b3af74e2178d8a85bcd29e7130f332d1b321 Mon Sep 17 00:00:00 2001 From: ih-abir Date: Wed, 7 Feb 2024 19:31:37 +0600 Subject: [PATCH] update redirect url --- src/workers/dilmahtea-me-stripe/src/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/workers/dilmahtea-me-stripe/src/index.js b/src/workers/dilmahtea-me-stripe/src/index.js index 97ed458d..59f5b125 100644 --- a/src/workers/dilmahtea-me-stripe/src/index.js +++ b/src/workers/dilmahtea-me-stripe/src/index.js @@ -63,7 +63,9 @@ const handlePOST = async (request, env, ctx) => { }); const queryString = searchParams.toString(), - cancel_url = origin_url + "?" + queryString; + cancel_url = origin_url + "?" + queryString, + success_url = success_url + + (payment_type === "ecommerce" ? "&paymentID=" + paymentID : ""); const paymentID = crypto.randomUUID(), paymentData = { ...validatedData, request_headers }; @@ -107,11 +109,7 @@ const handlePOST = async (request, env, ctx) => { metadata: { paymentID, payment_type }, }); - const confirmPaymentIntent = await stripe.paymentIntents.confirm( - paymentIntent.id, - {return_url: success_url + - (payment_type === "ecommerce" ? "&paymentID=" + paymentID : "")} - ); + const confirmPaymentIntent = await stripe.paymentIntents.confirm(paymentIntent.id); ctx.waitUntil( createBaserowRecord( @@ -138,7 +136,9 @@ const handlePOST = async (request, env, ctx) => { }), ); - return Response.redirect(session.url, 303); + const return_url = confirmPaymentIntent.status === 'succeeded' ? success_url : cancel_url; + + return Response.redirect(return_url, 303); }; handlePOST.catchError = true;