From 249d4d6a28829d6942e5de7e88d7a85d22b91ee8 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Mon, 15 Jul 2024 17:19:40 +0700 Subject: [PATCH] Experimental POST on prepaid --- config.sample.json | 1 + lib/hit/prepaid-topup.js | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) 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, -- 1.9.0