mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-25 07:47:02 +01:00
Add checkout API
This commit is contained in:
parent
281dcea2c0
commit
8ff4f43f0b
1 changed files with 312 additions and 241 deletions
|
@ -190,15 +190,13 @@ router.post("/login", async (req, res) => {
|
|||
let session = JSON.parse(response[0].session);
|
||||
session.push({
|
||||
user_agent: req.body.ua || req.headers["user-agent"],
|
||||
ip:
|
||||
req.body.ip ||
|
||||
ip: req.body.ip ||
|
||||
req.headers["x-forwarded-for"] ||
|
||||
req.socket.remoteAddress,
|
||||
session: token,
|
||||
});
|
||||
conn.query(
|
||||
'UPDATE users SET ? WHERE email ="' + req.body.email + '"',
|
||||
{
|
||||
'UPDATE users SET ? WHERE email ="' + req.body.email + '"', {
|
||||
session: JSON.stringify(session),
|
||||
},
|
||||
function (err, result) {
|
||||
|
@ -289,4 +287,77 @@ router.get("/verify-mail", async (req, res) => {
|
|||
);
|
||||
});
|
||||
|
||||
router.post("/checkout", async (req, res) => {
|
||||
if (
|
||||
!req.body.firstName ||
|
||||
!req.body.lastName ||
|
||||
!req.body.phoneNumber ||
|
||||
!req.body.streetAddress1 ||
|
||||
!req.body.streetAddress2 ||
|
||||
!req.body.region ||
|
||||
!req.body.province ||
|
||||
!req.body.city ||
|
||||
!req.body.district ||
|
||||
!req.body.subDistrict ||
|
||||
!req.body.postalCode ||
|
||||
!req.body.logistic ||
|
||||
!req.body.data
|
||||
) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
message: "Bad Request",
|
||||
});
|
||||
} else {
|
||||
const conn = db.connect();
|
||||
var data = {
|
||||
firstName: req.body.firstName,
|
||||
lastName: req.body.lastName,
|
||||
phoneNumber: req.body.phoneNumber,
|
||||
streetAddress1: req.body.streetAddress1,
|
||||
streetAddress2: req.body.streetAddress2,
|
||||
region: req.body.region,
|
||||
province: req.body.province,
|
||||
city: req.body.city,
|
||||
district: req.body.district,
|
||||
subDistrict: req.body.subDistrict,
|
||||
postalCode: req.body.postalCode,
|
||||
logistic: req.body.logistic,
|
||||
paymentMethod: '-',
|
||||
data: req.body.data,
|
||||
userId: 14,
|
||||
paid: '0',
|
||||
status: 'pending'
|
||||
};
|
||||
conn.query(
|
||||
"INSERT INTO transactions SET ?",
|
||||
data,
|
||||
function (error, response, fields) {
|
||||
if (error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
message: "Bad Request",
|
||||
});
|
||||
} else {
|
||||
conn.query(
|
||||
'SELECT * FROM transactions WHERE id ="' + response.insertId + '"',
|
||||
function (err, result) {
|
||||
if (err) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
message: "Bad Request",
|
||||
});
|
||||
} else {
|
||||
res.status(201);
|
||||
res.json({
|
||||
'order_id': result[0].id,
|
||||
'data': result[0].data
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in a new issue