Commit a042446079a3c4e2e9fcfbc0abbfbd5f7311d796
1 parent
1fbcb90950
Exists in
master
Add log and config.only_direct_response
Showing 2 changed files with 17 additions and 4 deletions Inline Diff
config.sample.json
1 | { | 1 | { |
2 | "handler_name": "DUMMY2022", | 2 | "handler_name": "DUMMY2022", |
3 | "pull_interval_ms": 1000, | 3 | "pull_interval_ms": 1000, |
4 | "only_direct_response": false, | ||
4 | "apiserver": { | 5 | "apiserver": { |
5 | "apikey": "PLEASE_CHANGE_ME", | 6 | "apikey": "PLEASE_CHANGE_ME", |
6 | "port": 12602, | 7 | "port": 12602, |
7 | "url": "http://localhost:12602/apikey/PLEASE_CHANGE_ME" | 8 | "url": "http://localhost:12602/apikey/PLEASE_CHANGE_ME" |
8 | }, | 9 | }, |
9 | "products": [], | 10 | "products": [], |
10 | "remote_products": {} | 11 | "remote_products": {} |
11 | } | 12 | } |
12 | 13 |
lib/partner.js
1 | const MODULE_NAME = 'PARTNER'; | 1 | const MODULE_NAME = 'PARTNER'; |
2 | 2 | ||
3 | const uniqid = require('uniqid'); | 3 | const uniqid = require('uniqid'); |
4 | 4 | ||
5 | const logger = require('tektrans-logger'); | 5 | const logger = require('tektrans-logger'); |
6 | const config = require('komodo-sdk/config'); | 6 | const config = require('komodo-sdk/config'); |
7 | const { report } = require('komodo-sdk/gateway/pull'); | 7 | const { report } = require('komodo-sdk/gateway/pull'); |
8 | 8 | ||
9 | const parseRemoteProduct = require('./parse-remote-product'); | 9 | const parseRemoteProduct = require('./parse-remote-product'); |
10 | 10 | ||
11 | exports.buy = (task, callerXid) => { | 11 | exports.buy = (task, callerXid) => { |
12 | const xid = callerXid || uniqid(); | 12 | const xid = callerXid || uniqid(); |
13 | 13 | ||
14 | logger.info(`${MODULE_NAME} 1AEA18CE: Processing task`, { | 14 | logger.info(`${MODULE_NAME} 1AEA18CE: Processing task`, { |
15 | xid, task, | 15 | xid, task, |
16 | }); | 16 | }); |
17 | 17 | ||
18 | const remoteProduct = parseRemoteProduct(task.remote_product); | 18 | const remoteProduct = parseRemoteProduct(task.remote_product); |
19 | 19 | ||
20 | logger.verbose(`${MODULE_NAME} 6022C627: Remote product parsed`, { xid, remoteProduct }); | 20 | logger.verbose(`${MODULE_NAME} 6022C627: Remote product parsed`, { xid, remoteProduct }); |
21 | 21 | ||
22 | if (remoteProduct.ONLY_DIRECT_RESPONSE) { | 22 | if (config.only_direct_response || remoteProduct.ONLY_DIRECT_RESPONSE) { |
23 | logger.verbose(`${MODULE_NAME} 6CB89503: Sending final direct response`, { xid }); | ||
23 | report({ | 24 | report({ |
24 | trx_id: task.trx_id, | 25 | trx_id: task.trx_id, |
25 | rc: remoteProduct.RC || '00', | 26 | rc: remoteProduct.RC || '00', |
26 | amount: remoteProduct.AMOUNT || null, | 27 | amount: remoteProduct.AMOUNT || null, |
27 | message: { | 28 | message: { |
28 | xid, | 29 | xid, |
29 | msg: 'SELESAI', | 30 | msg: 'SELESAI', |
30 | }, | 31 | }, |
31 | }); | 32 | }); |
32 | 33 | ||
33 | return; | 34 | return; |
34 | } | 35 | } |
35 | 36 | ||
37 | logger.verbose(`${MODULE_NAME} 207C6F31: Sending intermediate report`, { xid }); | ||
38 | |||
36 | report({ | 39 | report({ |
37 | trx_id: task.trx_id, | 40 | trx_id: task.trx_id, |
38 | rc: '68', | 41 | rc: '68', |
39 | amount: remoteProduct.AMOUNT || null, | 42 | amount: remoteProduct.AMOUNT || null, |
40 | message: { | 43 | message: { |
41 | xid, | 44 | xid, |
42 | msg: 'DIPROSES', | 45 | msg: 'DIPROSES', |
43 | }, | 46 | }, |
44 | }); | 47 | }); |
45 | 48 | ||
49 | const delay = Math.floor( | ||
50 | Math.random() * (config.max_wait_ms_before_callback || 3000), | ||
51 | ); | ||
52 | |||
53 | logger.verbose(`${MODULE_NAME} 091163B7: Will send callback`, { | ||
54 | xid, | ||
55 | delay, | ||
56 | }); | ||
57 | |||
46 | setTimeout(() => { | 58 | setTimeout(() => { |
59 | logger.verbose(`${MODULE_NAME} 685B89B9: Sending final callback`, { xid }); | ||
60 | |||
47 | report({ | 61 | report({ |
48 | trx_id: task.trx_id, | 62 | trx_id: task.trx_id, |
49 | rc: remoteProduct.RC, | 63 | rc: remoteProduct.RC, |
50 | amount: remoteProduct.AMOUNT || null, | 64 | amount: remoteProduct.AMOUNT || null, |
51 | message: { | 65 | message: { |
52 | xid, | 66 | xid, |
53 | msg: 'SELESAI', | 67 | msg: 'SELESAI', |
54 | }, | 68 | }, |
55 | }, xid); | 69 | }, xid); |
56 | }, Math.floor( | 70 | }, delay); |
57 | Math.random() * (config.max_wait_ms_before_callback || 3000), | ||
58 | )); |