Setup retry route
This commit is contained in:
parent
7707ab611d
commit
6c67927e5c
3 changed files with 13 additions and 2 deletions
|
@ -78,6 +78,13 @@ router.post("/", async (req, res) => {
|
|||
res.render("order", {title: "SOD - Payment", state: "error"});
|
||||
}).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)
|
||||
return error(req, res, "Can't retrieve last order", 400);
|
||||
else
|
||||
await lyfPay.sendPayment(req, res, order);
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -8,6 +8,9 @@ function macCalculator(params, key) {
|
|||
}
|
||||
|
||||
async function sendPayment(req, res, order) {
|
||||
if (order.paid)
|
||||
return error(req, res, "Order already paid !", 400);
|
||||
|
||||
let payment = await models.Payment.create();
|
||||
await payment.setOrder(order);
|
||||
await payment.reload();
|
||||
|
@ -45,6 +48,8 @@ async function sendPayment(req, res, order) {
|
|||
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
|
||||
.join("&");
|
||||
|
||||
req.session.lastOrder = order;
|
||||
|
||||
res.redirect(307, url);
|
||||
}
|
||||
|
||||
|
@ -79,7 +84,6 @@ async function checkPayment(req, res) {
|
|||
await payment.save();
|
||||
|
||||
if (payment.status) {
|
||||
console.log(payment);
|
||||
payment.Order.paid = payment.status;
|
||||
await payment.Order.save();
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ block content
|
|||
else if (state === "error")
|
||||
h2 An error occurred with the payment
|
||||
if (state !== "success")
|
||||
a
|
||||
a(href="/order/retry")
|
||||
button Retry
|
||||
|
|
Reference in a new issue