Update payment retry to support credit card payment
This commit is contained in:
parent
b10424d158
commit
23c9481c7d
2 changed files with 9 additions and 4 deletions
|
@ -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 (!order)
|
||||
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, "Last order doesn't exist", 400);
|
||||
else
|
||||
await lyfPay.sendPayment(req, res, order);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Reference in a new issue