Archived
1
0
Fork 0

Setup retry route

This commit is contained in:
Ethanell 2020-09-11 11:10:24 +02:00
parent 7707ab611d
commit 6c67927e5c
3 changed files with 13 additions and 2 deletions

View file

@ -78,6 +78,13 @@ router.post("/", async (req, res) => {
res.render("order", {title: "SOD - Payment", state: "error"}); res.render("order", {title: "SOD - Payment", state: "error"});
}).post("/callback", async (req, res) => { }).post("/callback", async (req, res) => {
await lyfPay.checkPayment(req, res); await lyfPay.checkPayment(req, res);
}).get("/retry", async (req, res) => {
let order = await models.Order.findByPk(req.session.lastOrder.id);
if (!order)
return error(req, res, "Can't retrieve last order", 400);
else
await lyfPay.sendPayment(req, res, order);
}); });
module.exports = router; module.exports = router;

View file

@ -8,6 +8,9 @@ function macCalculator(params, key) {
} }
async function sendPayment(req, res, order) { async function sendPayment(req, res, order) {
if (order.paid)
return error(req, res, "Order already paid !", 400);
let payment = await models.Payment.create(); let payment = await models.Payment.create();
await payment.setOrder(order); await payment.setOrder(order);
await payment.reload(); await payment.reload();
@ -45,6 +48,8 @@ async function sendPayment(req, res, order) {
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k])) .map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
.join("&"); .join("&");
req.session.lastOrder = order;
res.redirect(307, url); res.redirect(307, url);
} }
@ -79,7 +84,6 @@ async function checkPayment(req, res) {
await payment.save(); await payment.save();
if (payment.status) { if (payment.status) {
console.log(payment);
payment.Order.paid = payment.status; payment.Order.paid = payment.status;
await payment.Order.save(); await payment.Order.save();
} }

View file

@ -10,5 +10,5 @@ block content
else if (state === "error") else if (state === "error")
h2 An error occurred with the payment h2 An error occurred with the payment
if (state !== "success") if (state !== "success")
a a(href="/order/retry")
button Retry button Retry