diff --git a/config.sample.json b/config.sample.json index 897cb0d..e9bfd93 100644 --- a/config.sample.json +++ b/config.sample.json @@ -6,6 +6,7 @@ "terminal_name": "PLEASE_CHANGE_ME", "password": "PLEASE_CHANGE_ME", "dump_request": true, + "method": "GET", "callback": { "port": 14000, "url": "http://PLEASE_CHANGE_ME:14000", diff --git a/lib/hit/prepaid-topup.js b/lib/hit/prepaid-topup.js index fec8b31..d9b921f 100644 --- a/lib/hit/prepaid-topup.js +++ b/lib/hit/prepaid-topup.js @@ -43,7 +43,9 @@ module.exports = async (xid, task) => { xid, endpointUrl, params, - fullEndpointUrl, + fullEndpointUrl: (!config.partner.method || config.partner.method === 'GET') + ? fullEndpointUrl + : endpointUrl, }); report(xid, { @@ -52,17 +54,25 @@ module.exports = async (xid, task) => { message: { xid, msg: 'Sending request to partner', + method: config.partner.method || 'GET', endpointUrl, }, }); - const response = await axios.get(endpointUrl, { - headers: { - 'User-Agent': 'KOMODO-GW-HTTPGETX', - }, - timeout: config.partner.hit_timeout_ms || 60 * 1000, - params, - }); + const response = config.partner.method === 'POST' + ? await axios.post(endpointUrl, new URLSearchParams(params), { + headers: { + 'User-Agent': 'KOMODO-GW-HTTPGETX', + }, + timeout: config.partner.hit_timeout_ms || 60 * 1000, + }) + : await axios.get(endpointUrl, { + headers: { + 'User-Agent': 'KOMODO-GW-HTTPGETX', + }, + timeout: config.partner.hit_timeout_ms || 60 * 1000, + params, + }); if (!response) { const e = new Error(`${MODULE_NAME} 8CF4E04D: Empty response`); @@ -138,7 +148,7 @@ module.exports = async (xid, task) => { dumpReqRes( xid, task, - 'GET', + config.partner.method || 'GET', endpointUrl, params, lastResponse && lastResponse.data,