trx-status.js
4.04 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const MODULE_NAME = 'PARTNER-LISTENER.ROUTERS.TRX-STATUS';
const express = require('express');
const moment = require('moment');
const logger = require('tektrans-logger');
const coreapi = require('../../coreapi');
const dumper = require('../dumper');
const router = express.Router();
module.exports = router;
async function pageIndex(req, res) {
const { xid } = res.locals;
if (!req.body) req.body = {};
if (!req.body.terminal_name && !req.query.terminal_name) {
const msg = 'Parameter terminal_name tidak terdefinisi';
res.json({
httpgetx_xid: xid,
error: true,
message: msg,
});
dumper(xid, req, msg);
return;
}
if (!req.body.password && !req.query.password) {
const msg = 'Parameter password tidak terdefinisi';
res.json({
httpgetx_xid: xid,
error: true,
message: msg,
});
dumper(xid, req, msg);
return;
}
if (!req.body.request_id && !req.query.request_id) {
const msg = 'Parameter request_id tidak terdefinisi';
res.json({
httpgetx_xid: xid,
error: true,
message: msg,
});
dumper(xid, req, msg);
return;
}
const remoteIp = req.ip.replace(/^::ffff:/, '');
const askerTerminalName = `${req.body.terminal_name || req.query.terminal_name}@${remoteIp}`;
const coreResponse = await coreapi({
xid,
path: '/trx-status/view',
qs: {
asker_terminal_name: askerTerminalName,
asker_terminal_password: req.body.password || req.query.password,
request_id: req.body.request_id || req.query.request_id,
},
});
if (!coreResponse || !coreResponse.status) {
const msg = 'Status transaksi tidak dapat diketahui karena suatu kesalahan pada sistem';
logger.warn(`${MODULE_NAME} 9983DB34: ${msg}`, {
xid,
ip: req.ip,
terminal_name: req.body.terminal_name || req.query.terminal_name,
request_id: req.body.request_id || req.query.request_id,
});
const responseBody = {
httpgetx_xid: xid,
error: true,
from_ip: remoteIp,
terminal_name: req.body.terminal_name || req.query.terminal_name,
full_terminal_name: askerTerminalName,
password: req.body.password || req.query.password,
message: msg,
};
res.json(responseBody);
dumper(xid, req, responseBody);
return;
}
const trx = coreResponse && coreResponse.result ? {
id: coreResponse.result.id,
request_id: coreResponse.result.request_id,
store_id: coreResponse.result.store_id,
store_name: coreResponse.result.store_name,
terminal_id: coreResponse.result.terminal_id,
terminal_name: coreResponse.result.terminal_name,
created: moment(coreResponse.result.created).format('YYYY-MM-DD HH:mm:ss'),
modified: moment(coreResponse.result.modified).format('YYYY-MM-DD HH:mm:ss'),
product_name: coreResponse.result.product_name,
destination: coreResponse.result.destination,
amount: coreResponse.result.amount,
ending_balance: coreResponse.result.ending_balance,
rc: coreResponse.result.rc,
message: coreResponse.result.reply_message,
sn: coreResponse.result.sn,
}
: null;
const result = {
httpgetx_xid: xid,
error: coreResponse.status !== 'OK',
from_ip: remoteIp,
terminal_name: req.body.terminal_name || req.query.terminal_name,
full_terminal_name: askerTerminalName,
message: coreResponse.message,
trx_found: !!trx,
trx,
// original_trx: coreResponse.result,
};
res.json(result);
logger.info(`${MODULE_NAME} 480C4BB0: Partner request responded`, {
xid,
processing_time_in_ms: new Date() - res.locals.x_http_request_ts,
result,
});
dumper(xid, req, result);
}
router.get('/', pageIndex);