Skip to content

Commit

Permalink
update redirect url
Browse files Browse the repository at this point in the history
  • Loading branch information
ih-abir committed Feb 7, 2024
1 parent df77283 commit b476b3a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/workers/dilmahtea-me-stripe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit b476b3a

Please sign in to comment.