Archived
1
0
Fork 0

Update payment retry to support credit card payment

This commit is contained in:
Ethanell 2020-09-20 12:44:55 +02:00
parent b10424d158
commit 23c9481c7d
2 changed files with 9 additions and 4 deletions

View file

@ -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);

View file

@ -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);
}