-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
91 lines (66 loc) · 2.41 KB
/
server.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
81
82
83
84
85
86
87
88
89
90
91
import express from 'express'
const app = express()
import bodyParser from 'body-parser'
//const athenscb = require('./athenScb.js')
import * as athenScb from './athenScb.js'
//const requestGenerateQr = require('./requestGenerateQr.js')
import * as requestGenerateQr from './requestGenerateQr.js'
var server_port = process.env.YOUR_PORT || process.env.PORT || 3000;
var server_host = process.env.YOUR_HOST || '0.0.0.0';
//process.env.accessToken = athenscb.athenData[0].data.accessToken;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/', (req, res) => {
//athenscb.config.headers["resourceOwnerId"] = ""
//console.log(athenscb.config.headers["resourceOwnerId"])
//get access token
process.env.accessToken = athenscb.athenData[0].data.accessToken;
res.json("accessToken :"+athenscb.athenData[0].data.accessToken
)
})
app.get('/qr', (req, res) => {
//athenscb.config.headers["resourceOwnerId"] = ""
//console.log(athenscb.config.headers["resourceOwnerId"])
//get access token
console.log(process.env.accessToken)
console.log(requestGenerateQr.qrData)
res.json("qr:"+requestGenerateQr.qrData[0].data.qrRawData)
})
const circularReplacer = () => {
// Creating new WeakSet to keep
// track of previously seen objects
const seen = new WeakSet();
return (key, value) => {
// If type of value is an
// object or value is null
if (typeof(value) === "object"
&& value !== null) {
// If it has been seen before
if (seen.has(value)) {
return;
}
// Add current value to the set
seen.add(value);
}
// return the value
return value;
};
};
app.post('/scb/payment/confirm', (req,res) => {
//console.log(JSON.stringify(
// req, circularReplacer()))
//res.send(res)
console.log("accept bill")
console.log("req: "+ JSON.stringify(req.body))
//res.send("req: "+ JSON.stringify(req.body))
//console.log("res: "+JSON.stringify(events, circularReplacer() ) )
//console.log("res: "+JSON.stringify(res, circularReplacer()))
//console.log("req: "+JSON.stringify(req ))
if(req.body.transactionId)res.json("success")
else res.json(req.body)
})
app.listen(server_port , () => {
console.log('Listening on port %d', server_port);
})