Commit 9ced2cfdf03e19f6c35901c59076ab1322236d6b
1 parent
635fc54bfa
Exists in
master
and in
1 other branch
PAY finished
Showing 3 changed files with 111 additions and 1 deletions Side-by-side Diff
lib/core-callback/sender.js
... | ... | @@ -26,9 +26,12 @@ const sender = async (data, xid, retry) => { |
26 | 26 | message: data.message, |
27 | 27 | amount: data.amount, |
28 | 28 | ending_balance: data.ending_balance, |
29 | - amount_to_charge: data.amount_to_charge, | |
30 | 29 | }; |
31 | 30 | |
31 | + if (data.command === 'INQUIRY' && data.amount_to_charge) { | |
32 | + params.amount_to_charge = data.amount_to_charge; | |
33 | + } | |
34 | + | |
32 | 35 | const fullUrl = urlConcatQs(data.reverse_url, params); |
33 | 36 | logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, { |
34 | 37 | xid, retry, params, fullUrl, |
lib/listener-partner/index.js
... | ... | @@ -10,6 +10,7 @@ const logger = require('komodo-sdk/logger'); |
10 | 10 | const middlewareCommon = require('../middlewares/common'); |
11 | 11 | |
12 | 12 | const routerInquiry = require('./routers/inquiry'); |
13 | +const routerPay = require('./routers/pay'); | |
13 | 14 | const routerTopup = require('./routers/topup'); |
14 | 15 | const routerTrxStatus = require('./routers/trx-status'); |
15 | 16 | |
... | ... | @@ -20,6 +21,7 @@ app.use(express.urlencoded({ extended: true })); |
20 | 21 | app.use(middlewareCommon); |
21 | 22 | |
22 | 23 | app.use('/inquiry', routerInquiry); |
24 | +app.use('/pay', routerPay); | |
23 | 25 | app.use('/topup', routerTopup); |
24 | 26 | app.use('/trx-status', routerTrxStatus); |
25 | 27 |
lib/listener-partner/routers/pay.js
... | ... | @@ -0,0 +1,105 @@ |
1 | +const axios = require('axios').default; | |
2 | +const express = require('express'); | |
3 | +const coreUrl = require('komodo-sdk/core-url'); | |
4 | + | |
5 | +const config = require('komodo-sdk/config'); | |
6 | +const logger = require('komodo-sdk/logger'); | |
7 | + | |
8 | +const getFromBodyQsParams = require('../../get-from-body-qs-params'); | |
9 | +const ipv6ToIpv4 = require('../../ipv6-to-ipv4'); | |
10 | + | |
11 | +const router = express.Router(); | |
12 | +module.exports = router; | |
13 | + | |
14 | +const CORE_ENDPOINT = `${coreUrl}/postpaid2/pay`; | |
15 | + | |
16 | +const mainHandler = async (req, res) => { | |
17 | + const { xid } = res.locals; | |
18 | + | |
19 | + const requestId = (getFromBodyQsParams(req, 'request_id') || '').toString().trim(); | |
20 | + const terminalNameWithoutIp = (getFromBodyQsParams(req, 'terminal_name') || '').toString().trim(); | |
21 | + const terminalName = `${terminalNameWithoutIp}@${ipv6ToIpv4(req.ip)}`; | |
22 | + const productName = (getFromBodyQsParams(req, 'product_name') || '').trim().toUpperCase(); | |
23 | + const destination = (getFromBodyQsParams(req, 'destination') || '').toString().trim(); | |
24 | + const password = getFromBodyQsParams(req, 'password'); | |
25 | + const reverseUrl = getFromBodyQsParams(req, 'reverse_url'); | |
26 | + | |
27 | + if (!requestId || !terminalNameWithoutIp || !productName || !destination) { | |
28 | + res.end('INVALID REQUEST. Missing request_id or terminal_name or product_name or destination.'); | |
29 | + return; | |
30 | + } | |
31 | + | |
32 | + const params = { | |
33 | + origin: config.name, | |
34 | + report_ip: config.listener.core.from_ip, | |
35 | + report_port: config.listener.core.port || 25614, | |
36 | + request_id: requestId, | |
37 | + terminal_name: terminalName, | |
38 | + product_name: productName, | |
39 | + destination, | |
40 | + terminal_password: password, | |
41 | + reverse_url: reverseUrl, | |
42 | + }; | |
43 | + | |
44 | + logger.info('Forwarding PAY request to CORE', { xid, params }); | |
45 | + try { | |
46 | + const result = await axios.get(CORE_ENDPOINT, { | |
47 | + params, | |
48 | + timeout: 10000, | |
49 | + }); | |
50 | + | |
51 | + if (!result || !result.data) { | |
52 | + const newError = new Error('0D428E4C: Empty CORE PAY direct-response'); | |
53 | + logger.warn(newError.message, { xid }); | |
54 | + throw newError; | |
55 | + } | |
56 | + | |
57 | + logger.verbose('Got PAY direct-response from CORE', { | |
58 | + xid, | |
59 | + coreResponse: result.data, | |
60 | + }); | |
61 | + | |
62 | + const resultForPartner = { | |
63 | + httpgetx_xid: xid, | |
64 | + command: result.data.command, | |
65 | + request_id: result.data.request_id && result.data.request_id.toString(), | |
66 | + transaction_id: result.data.transaction_id && result.data.transaction_id.toString(), | |
67 | + transaction_date: result.data.transaction_date, | |
68 | + store_name: result.data.store_name, | |
69 | + terminal_name: result.data.terminal_name, | |
70 | + product_name: result.data.product_name, | |
71 | + destination: result.data.destination, | |
72 | + rc: result.data.rc, | |
73 | + sn: result.data.sn, | |
74 | + message: result.data.message, | |
75 | + amount: result.data.amount, | |
76 | + ending_balance: result.data.ending_balance, | |
77 | + }; | |
78 | + | |
79 | + logger.verbose('Forwarding CORE PAY direct-response to partner', { | |
80 | + xid, | |
81 | + resultForPartner, | |
82 | + }); | |
83 | + | |
84 | + res.json(resultForPartner); | |
85 | + } catch (e) { | |
86 | + logger.warn('EXCEPTION on forwarding PAY request to CORE', { | |
87 | + xid, | |
88 | + errCode: e.code, | |
89 | + errMessage: e.message, | |
90 | + }); | |
91 | + | |
92 | + res.json({ | |
93 | + httpgetx_xid: xid, | |
94 | + command: 'PAY', | |
95 | + request_id: requestId, | |
96 | + terminal_name: terminalName, | |
97 | + product_name: productName, | |
98 | + destination, | |
99 | + rc: '68', | |
100 | + message: 'CORE tidak merespon dengan benar, tidak dapat mengetahui status request anda', | |
101 | + }); | |
102 | + } | |
103 | +}; | |
104 | + | |
105 | +router.all('/', mainHandler); |