Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/routes/order.js

37 lines
1.3 KiB
JavaScript
Raw Normal View History

let express = require("express");
let router = express.Router();
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");
let addOrder = require("./utils/addOrder");
router.post("/", async (req, res) => {
let order = await addOrder(req, res, {
department: req.body.department,
firstName: req.body.firstName,
lastName: req.body.lastName,
username: req.session ? req.session.user ? req.session.user.username : undefined : undefined,
sandwiches: req.body.sandwiches,
dates: req.body.dates
});
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);
});
module.exports = router;