partner.js
1.85 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
const MODULE_NAME = 'PARTNER';
const uniqid = require('uniqid');
const logger = require('tektrans-logger');
const config = require('komodo-sdk/config');
const { report } = require('komodo-sdk/gateway/pull');
const parseRemoteProduct = require('./parse-remote-product');
exports.buy = (task, callerXid) => {
const xid = callerXid || uniqid();
logger.info(`${MODULE_NAME} 1AEA18CE: Processing task`, {
xid, task,
});
const remoteProduct = parseRemoteProduct(task.remote_product);
logger.verbose(`${MODULE_NAME} 6022C627: Remote product parsed`, { xid, remoteProduct });
if (config.only_direct_response || remoteProduct.ONLY_DIRECT_RESPONSE) {
logger.verbose(`${MODULE_NAME} 6CB89503: Sending final direct response`, { xid });
report({
trx_id: task.trx_id,
rc: remoteProduct.RC || '00',
amount: remoteProduct.AMOUNT || null,
message: {
xid,
msg: 'SELESAI',
},
});
return;
}
logger.verbose(`${MODULE_NAME} 207C6F31: Sending intermediate report`, { xid });
report({
trx_id: task.trx_id,
rc: '68',
amount: remoteProduct.AMOUNT || null,
message: {
xid,
msg: 'DIPROSES',
},
});
const delay = Math.floor(
Math.random() * (config.max_wait_ms_before_callback || 3000),
);
logger.verbose(`${MODULE_NAME} 091163B7: Will send callback`, {
xid,
delay,
});
setTimeout(() => {
logger.verbose(`${MODULE_NAME} 685B89B9: Sending final callback`, { xid });
report({
trx_id: task.trx_id,
rc: remoteProduct.RC,
amount: remoteProduct.AMOUNT || null,
message: {
xid,
msg: 'SELESAI',
},
}, xid);
}, delay);
};