-
Notifications
You must be signed in to change notification settings - Fork 21
/
listener.js
123 lines (99 loc) · 2.46 KB
/
listener.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const prettyjson = require('prettyjson');
const options = {
noColor: true
};
const express = require('express'),
bodyParser = require('body-parser'),
app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
/*
B2C ResultURL
URL: /b2c/result
*/
app.post('/b2c/result', (req, res) => {
console.log('-----------B2C CALLBACK------------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResponseCode": "00000000",
"ResponseDesc": "success"
};
res.json(message);
});
/*
B2C QueueTimeoutURL
URL: /b2c/timeout
*/
app.post('/b2c/timeout', (req, res) => {
console.log('-----------B2C TIMEOUT------------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResponseCode": "00000000",
"ResponseDesc": "success"
};
res.json(message);
});
/*
C2B ValidationURL
URL: /c2b/validation
*/
app.post('/c2b/validation', (req, res) => {
console.log('-----------C2B VALIDATION REQUEST-----------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResultCode": 0,
"ResultDesc": "Success",
"ThirdPartyTransID": "1234567890"
};
res.json(message);
});
/*
C2B ConfirmationURL
URL: /c2b/confirmation
*/
app.post('/c2b/confirmation', (req, res) => {
console.log('-----------C2B CONFIRMATION REQUEST------------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResultCode": 0,
"ResultDesc": "Success"
};
res.json(message);
});
/*
B2B ResultURL
URL: /b2b/result
*/
app.post('/b2b/result', (req, res) => {
console.log('-----------B2B CALLBACK------------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResponseCode": "00000000",
"ResponseDesc": "success"
};
res.json(message);
});
/*
B2B QueueTimeoutURL
URL: /api/v1/b2b/timeout
*/
app.post('/b2b/timeout', (req, res) => {
console.log('-----------B2B TIMEOUT------------');
console.log(prettyjson.render(req.body, options));
console.log('-----------------------');
let message = {
"ResponseCode": "00000000",
"ResponseDesc": "success"
};
res.json(message);
});
const server = app.listen(8310, () => {
let host = server.address().address;
let port = server.address().port;
console.log(`M-Pesa Listener is listening at http://${host}:${port}` );
});