From 23c9481c7d5cf3ed0a2d6ade3a765c39db0a31c2 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 20 Sep 2020 12:44:55 +0200 Subject: [PATCH] Update payment retry to support credit card payment --- routes/order.js | 9 +++++++-- routes/utils/lyfPay.js | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/routes/order.js b/routes/order.js index 9ad4754..988ffa4 100644 --- a/routes/order.js +++ b/routes/order.js @@ -28,9 +28,14 @@ router.post("/", async (req, res) => { }).post("/callback", async (req, res) => { await lyfPay.checkPayment(req, res); }).get("/retry", async (req, res) => { - let order = await models.Order.findByPk(req.session.lastOrder.id); + if (!req.session || !req.session.lastOrder) + return error(req, res, "Can't retrieve last order", 400); + + req.body.payment = req.session.lastOrder[1]; + + let order = await models.Order.findByPk(req.session.lastOrder[0].id); if (!order) - return error(req, res, "Can't retrieve last order", 400); + return error(req, res, "Last order doesn't exist", 400); else await lyfPay.sendPayment(req, res, order); diff --git a/routes/utils/lyfPay.js b/routes/utils/lyfPay.js index 4f87145..faaec30 100644 --- a/routes/utils/lyfPay.js +++ b/routes/utils/lyfPay.js @@ -63,7 +63,7 @@ async function sendPayment(req, res, order) { params.mac = macCalculator(params, config.secureKey); params.additionalDataEncoded = Buffer.from(params.additionalData).toString("base64"); - params.additionalData = undefined; + delete params.additionalData; if (req.body.payment === "creditCard") params.version = "v2.0"; @@ -71,7 +71,7 @@ async function sendPayment(req, res, order) { .map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k])) .join("&"); - req.session.lastOrder = order; + req.session.lastOrder = [order, req.body.payment]; res.redirect(307, url); }