forked from hasura/3factor-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalDevelopment.js
80 lines (73 loc) · 2.18 KB
/
localDevelopment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const validateOrder = require('validate-order').validateOrder;
const makePayment = require('payment').makePayment;
const restaurantApproval = require('restaurant-approval').restaurantApproval;
const assignAgent = require('agent-assignment').assignAgent;
app.use(bodyParser.json());
app.post('/validate-order', async function (req, res) {
try{
var order;
if(req.body.event) {
order = req.body.event.data.new;
} else {
order = req.body;
}
var result = await validateOrder(order);
res.json(result);
} catch(e) {
console.log(e);
res.status(500).json(e.toString());
}
});
app.post('/payment', async function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
try {
if (req.method == "OPTIONS") {
res.json("");
return;
}
var paymentReq = req.body;
var result = await makePayment(paymentReq);
res.json(result);
} catch(e) {
console.log(e);
res.status(500).json(e.toString());
}
});
app.post('/restaurant-approval', async function (req, res) {
try {
var order;
if(req.body.event) {
order = req.body.event.data.new;
} else {
order = req.body;
}
var result = await restaurantApproval(order);
res.json(result);
} catch(e) {
console.log(e);
res.status(500).json(e.toString());
}
});
app.post('/agent-assignment', async function (req, res) {
try {
var order;
if(req.body.event) {
order = req.body.event.data.new;
} else {
order = req.body;
}
var result = await assignAgent(order);
res.json(result);
} catch(e) {
console.log(e);
res.status(500).json(e.toString());
}
});
var server = app.listen(8081, function () {
console.log("server listening on port 8081");
});