2020-08-14 20:08:42 +02:00
|
|
|
let express = require("express");
|
|
|
|
let router = express.Router();
|
2020-08-15 20:17:36 +02:00
|
|
|
let models = require("../models");
|
2020-08-20 12:14:38 +02:00
|
|
|
let error = require("./utils/error");
|
2020-09-11 10:58:12 +02:00
|
|
|
let lyfPay = require("./utils/lyfPay");
|
2020-09-13 18:56:13 +02:00
|
|
|
let addOrder = require("./utils/addOrder");
|
2020-08-14 20:08:42 +02:00
|
|
|
|
2020-08-15 20:17:36 +02:00
|
|
|
|
|
|
|
router.post("/", async (req, res) => {
|
2020-09-13 18:56:13 +02:00
|
|
|
let order = await addOrder(req, res, {
|
|
|
|
department: req.body.department,
|
2020-08-15 20:17:36 +02:00
|
|
|
firstName: req.body.firstName,
|
|
|
|
lastName: req.body.lastName,
|
2020-09-13 18:56:13 +02:00
|
|
|
username: req.session ? req.session.user ? req.session.user.username : undefined : undefined,
|
|
|
|
sandwiches: req.body.sandwiches,
|
|
|
|
dates: req.body.dates
|
2020-08-15 20:17:36 +02:00
|
|
|
});
|
2020-09-11 10:58:12 +02:00
|
|
|
await lyfPay.sendPayment(req, res, order);
|
|
|
|
}).get("/success", (req, res) => {
|
|
|
|
res.render("order", {title: "SOD - Payment", state: "success"});
|
|
|
|
}).get("/cancel", (req, res) => {
|
|
|
|
res.render("order", {title: "SOD - Payment", state: "cancel"});
|
|
|
|
}).get("/error", (req, res) => {
|
|
|
|
res.render("order", {title: "SOD - Payment", state: "error"});
|
|
|
|
}).post("/callback", async (req, res) => {
|
|
|
|
await lyfPay.checkPayment(req, res);
|
2020-09-11 11:10:24 +02:00
|
|
|
}).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);
|
|
|
|
|
2020-08-14 20:08:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|