partner.js
2 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
const moment = require('moment');
const logger = require('tektrans-logger');
const config = require('komodo-sdk/config');
const pull = require('komodo-sdk/gateway/pull');
function buy(task, xid) {
logger.verbose('Got task from CORE', { xid, task });
const [remoteProduct, amount] = task.remote_product.split(/ *, */);
pull.report({
trx_id: task.trx_id,
rc: '68',
message: {
xid,
msg: 'Waiting for result',
},
}, xid);
setTimeout(
() => {
const destination = task.destination.toString();
if ((destination % 10) === 0) {
pull.report({
trx_id: task.trx_id,
rc: '68',
balance: config.supplier_ending_balance,
message: {
xid,
msg: `PENDING karena nomor tujuan ${task.destination} diakhiri 0`,
},
}, xid);
} else if (destination % 2) {
pull.report({
trx_id: task.trx_id,
rc: '14',
balance: config.supplier_ending_balance,
message: {
xid,
msg: `GAGAL karena nomor tujuan ${task.destination} adalah nomor ganjil`,
},
}, xid);
} else {
pull.report({
trx_id: task.trx_id,
rc: '00',
sn: moment().format('YYYYMMDDHHmmssSSS'),
amount,
remote_product: remoteProduct,
balance: config.supplier_ending_balance,
message: {
xid,
msg: `BERHASIL karena nomor tujuan ${task.destination} adalah nomor genap`,
},
}, xid);
}
},
(config.max_result_timeout_ms || 2000) * Math.random(),
);
}
exports.buy = buy;