Commit eb9e33eda292057cb0c21f04790a961a595a58b6

Authored by adi surya
1 parent 5443b922a7
Exists in master

request to sds

Showing 14 changed files with 75 additions and 565 deletions Side-by-side Diff

1 1 {
2   - "name": "gateway-sds-ss",
  2 + "name": "gateway-sds",
3 3 "url": "http://localhost",
4 4 "port": 11330,
5 5 "apikey": "fd97cf519b979262d9d9004cba6a165629ca8b69350a6afdcaab6ab2c9a996ae",
lib/actions/buy-to-sds.js
... ... @@ -0,0 +1,68 @@
  1 +const MODULE_NAME = 'ACTIONS.BUY-TO-SDS';
  2 +
  3 +const logger = require('tektrans-logger');
  4 +const axios = require('axios').default;
  5 +
  6 +const config = require('../config');
  7 +
  8 +const client = axios.create({
  9 + baseURL: config.sds_ss.url,
  10 + timeout: config.sds_ss.request_timeout_ms,
  11 +});
  12 +
  13 +/**
  14 + * request buy to sds
  15 + *
  16 + * @param {string} xid
  17 + * @param {string} requestId
  18 + * @param {string} destination
  19 + * @param {string} productName
  20 + * @param {number} quantity
  21 + * @param {string} reverseUrl
  22 + */
  23 +module.exports = async (
  24 + xid,
  25 + requestId,
  26 + destination,
  27 + productName,
  28 + quantity,
  29 + reverseUrl,
  30 +) => {
  31 + logger.verbose(`${MODULE_NAME} 4AD4DF41: buy to sds`, {
  32 + requestId, destination, productName, xid,
  33 + });
  34 +
  35 + const params = {
  36 + request_id: requestId,
  37 + username: config.sds_ss.username,
  38 + password: config.komodo_http_get_x.password,
  39 + number: destination,
  40 + product: productName,
  41 + amount: quantity,
  42 + reverse_url: reverseUrl,
  43 + };
  44 +
  45 + try {
  46 + const response = await client.get('/request', {
  47 + params,
  48 + });
  49 + if (!response) {
  50 + throw new Error(`${MODULE_NAME} 6CE3E06E: Empty response sds`);
  51 + }
  52 + if (!response.data) {
  53 + throw new Error(`${MODULE_NAME} F236476F: Empty response sds`);
  54 + }
  55 +
  56 + return response.data;
  57 + } catch (err) {
  58 + logger.warn(`${MODULE_NAME} 48BAA6B7: Exception`, {
  59 + xid,
  60 + requestId,
  61 + destination,
  62 + productName,
  63 + quantity,
  64 + message: err.message,
  65 + });
  66 + throw err;
  67 + }
  68 +};
... ... @@ -6,7 +6,7 @@ const axios = require('axios').default;
6 6 const config = require('../config');
7 7 const configData = require('../config/data');
8 8  
9   -const topupToKomodo = require('./topup-to-komodo');
  9 +const buyToSDS = require('./buy-to-sds');
10 10  
11 11 const client = axios.create({
12 12 baseURL: config.core.url,
... ... @@ -40,14 +40,15 @@ module.exports = async (xid, transaction) => {
40 40 }
41 41  
42 42 const callbackUrl = `${iConfig.url}:${iConfig.port}/apikey/${iConfig.apikey}/updates`;
43   - const result = await topupToKomodo(
  43 + const result = await buyToSDS(
44 44 xid,
45 45 transaction.id,
46 46 transaction.destination,
47 47 productName,
  48 + transaction.quantity,
48 49 callbackUrl,
49 50 );
50   - logger.verbose(`${MODULE_NAME} 5BDFAF41: result from komodo`, {
  51 + logger.verbose(`${MODULE_NAME} 5BDFAF41: result from sds`, {
51 52 xid,
52 53 trxId: transaction.id,
53 54 result,
lib/actions/index.js
1 1 exports.buy = require('./buy');
2   -exports.inquiry = require('./inquiry');
3   -exports.pay = require('./pay');
  2 +
lib/actions/inquiry-to-komodo.js
... ... @@ -1,64 +0,0 @@
1   -const MODULE_NAME = 'ACTIONS.INQUIRY-TO-KOMODO';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -
6   -const config = require('../config');
7   -
8   -const client = axios.create({
9   - baseURL: config.komodo_http_get_x.url,
10   - timeout: config.komodo_http_get_x.request_timeout_ms,
11   -});
12   -
13   -/**
14   - * request inquiry transaction to komodo
15   - *
16   - * @param {string} xid
17   - * @param {string} requestId
18   - * @param {string} destination
19   - * @param {string} productName
20   - * @param {string} reverseUrl
21   - */
22   -module.exports = async (
23   - xid,
24   - requestId,
25   - destination,
26   - productName,
27   - reverseUrl,
28   -) => {
29   - logger.verbose(`${MODULE_NAME} 4AD4DF41: request inquiry to komodo`, {
30   - requestId, destination, productName, reverseUrl, xid,
31   - });
32   -
33   - const params = {
34   - request_id: requestId,
35   - terminal_name: config.komodo_http_get_x.terminal_name,
36   - password: config.komodo_http_get_x.password,
37   - destination,
38   - product_name: productName,
39   - reverse_url: reverseUrl,
40   - };
41   -
42   - try {
43   - const response = await client.get('/inquiry', {
44   - params,
45   - });
46   - if (!response) {
47   - throw new Error(`${MODULE_NAME} 6CE3E06E: Empty response from komodo`);
48   - }
49   - if (!response.data) {
50   - throw new Error(`${MODULE_NAME} F236476F: Empty response data from komodo`);
51   - }
52   -
53   - return response.data;
54   - } catch (err) {
55   - logger.warn(`${MODULE_NAME} 48BAA6B7: Exception`, {
56   - xid,
57   - requestId,
58   - destination,
59   - productName,
60   - message: err.message,
61   - });
62   - throw err;
63   - }
64   -};
lib/actions/inquiry.js
... ... @@ -1,71 +0,0 @@
1   -const MODULE_NAME = 'ACTIONS.INQUIRY';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -
6   -const config = require('../config');
7   -const configData = require('../config/data');
8   -
9   -const inquiryToKomodo = require('./inquiry-to-komodo');
10   -
11   -const client = axios.create({
12   - baseURL: config.core.url,
13   - timeout: config.core.request_timeout_ms,
14   - headers: {
15   - 'x-access-token': config.core.access_token,
16   - },
17   -});
18   -
19   -/**
20   - * Inquiry a product from supplier komodo
21   - *
22   - * @param {string} xid
23   - * @param {object} transaction
24   - *
25   - */
26   -module.exports = async (xid, transaction) => {
27   - try {
28   - logger.verbose(`${MODULE_NAME} ABE82225: Inquiry product to komodo`, {
29   - xid,
30   - transaction,
31   - });
32   - const iConfig = await configData.all();
33   -
34   - let productName = transaction.product_name;
35   - if (
36   - iConfig.postpaid_products[transaction.product_name]
37   - && iConfig.postpaid_products[transaction.product_name].remote
38   - ) {
39   - productName = iConfig.postpaid_products[transaction.product_name].remote;
40   - }
41   -
42   - const callbackUrl = `${iConfig.url}:${iConfig.port}/apikey/${iConfig.apikey}/updates`;
43   - const result = await inquiryToKomodo(
44   - xid,
45   - transaction.id,
46   - transaction.destination,
47   - productName,
48   - callbackUrl,
49   - );
50   - logger.verbose(`${MODULE_NAME} 076C1206: result from komodo`, {
51   - xid,
52   - trxId: transaction.id,
53   - result,
54   - });
55   - const params = {
56   - id: result.request_id,
57   - rc: result.rc,
58   - amount: result.amount || null,
59   - message: result.message,
60   - sn: result.sn || null,
61   - };
62   -
63   - await client.post('/transactions/gateway-update', params);
64   - } catch (e) {
65   - logger.warn(`${MODULE_NAME} D1A1B698: Exception`, {
66   - xid,
67   - message: e.message,
68   - code: e.code,
69   - });
70   - }
71   -};
lib/actions/pay.js
... ... @@ -1,71 +0,0 @@
1   -const MODULE_NAME = 'ACTIONS.PAY';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -
6   -const config = require('../config');
7   -const configData = require('../config/data');
8   -
9   -const paymentToKomodo = require('./payment-to-komodo');
10   -
11   -const client = axios.create({
12   - baseURL: config.core.url,
13   - timeout: config.core.request_timeout_ms,
14   - headers: {
15   - 'x-access-token': config.core.access_token,
16   - },
17   -});
18   -
19   -/**
20   - * Pay a product from supplier komodo
21   - *
22   - * @param {string} xid
23   - * @param {object} transaction
24   - *
25   - */
26   -module.exports = async (xid, transaction) => {
27   - try {
28   - logger.verbose(`${MODULE_NAME} CB9506E9: Pay product to komodo`, {
29   - xid,
30   - transaction,
31   - });
32   - const iConfig = await configData.all();
33   -
34   - let productName = transaction.product_name;
35   - if (
36   - iConfig.postpaid_products[transaction.product_name]
37   - && iConfig.postpaid_products[transaction.product_name].remote
38   - ) {
39   - productName = iConfig.postpaid_products[transaction.product_name].remote;
40   - }
41   -
42   - const callbackUrl = `${iConfig.url}:${iConfig.port}/apikey/${iConfig.apikey}/updates`;
43   - const result = await paymentToKomodo(
44   - xid,
45   - transaction.id,
46   - transaction.destination,
47   - productName,
48   - callbackUrl,
49   - );
50   - logger.verbose(`${MODULE_NAME} 4F45F9E3: result from komodo`, {
51   - xid,
52   - trxId: transaction.id,
53   - result,
54   - });
55   - const params = {
56   - id: result.request_id,
57   - rc: result.rc,
58   - amount: result.amount || null,
59   - message: result.message,
60   - sn: result.sn || null,
61   - };
62   -
63   - await client.post('/transactions/gateway-update', params);
64   - } catch (e) {
65   - logger.warn(`${MODULE_NAME} EF0EE887: Exception`, {
66   - xid,
67   - message: e.message,
68   - code: e.code,
69   - });
70   - }
71   -};
lib/actions/payment-to-komodo.js
... ... @@ -1,64 +0,0 @@
1   -const MODULE_NAME = 'ACTIONS.PAY-TO-KOMODO';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -
6   -const config = require('../config');
7   -
8   -const client = axios.create({
9   - baseURL: config.komodo_http_get_x.url,
10   - timeout: config.komodo_http_get_x.request_timeout_ms,
11   -});
12   -
13   -/**
14   - * request pay transaction to komodo
15   - *
16   - * @param {string} xid
17   - * @param {string} requestId
18   - * @param {string} destination
19   - * @param {string} productName
20   - * @param {string} reverseUrl
21   - */
22   -module.exports = async (
23   - xid,
24   - requestId,
25   - destination,
26   - productName,
27   - reverseUrl,
28   -) => {
29   - logger.verbose(`${MODULE_NAME} 740EF164: pay to komodo`, {
30   - requestId, destination, productName, xid,
31   - });
32   -
33   - const params = {
34   - request_id: requestId,
35   - terminal_name: config.komodo_http_get_x.terminal_name,
36   - password: config.komodo_http_get_x.password,
37   - destination,
38   - product_name: productName,
39   - reverse_url: reverseUrl,
40   - };
41   -
42   - try {
43   - const response = await client.get('/pay', {
44   - params,
45   - });
46   - if (!response) {
47   - throw new Error(`${MODULE_NAME} 29D8D56F: Empty response from komodo`);
48   - }
49   - if (!response.data) {
50   - throw new Error(`${MODULE_NAME} 288CD049: Empty response data from komodo`);
51   - }
52   -
53   - return response.data;
54   - } catch (err) {
55   - logger.warn(`${MODULE_NAME} DCE65215: Exception`, {
56   - xid,
57   - requestId,
58   - destination,
59   - productName,
60   - message: err.message,
61   - });
62   - throw err;
63   - }
64   -};
lib/actions/topup-to-komodo.js
... ... @@ -1,64 +0,0 @@
1   -const MODULE_NAME = 'ACTIONS.TOPUP-TO-KOMODO';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -
6   -const config = require('../config');
7   -
8   -const client = axios.create({
9   - baseURL: config.komodo_http_get_x.url,
10   - timeout: config.komodo_http_get_x.request_timeout_ms,
11   -});
12   -
13   -/**
14   - * request topup transaction to komodo
15   - *
16   - * @param {string} xid
17   - * @param {string} requestId
18   - * @param {string} destination
19   - * @param {string} productName
20   - * @param {string} reverseUrl
21   - */
22   -module.exports = async (
23   - xid,
24   - requestId,
25   - destination,
26   - productName,
27   - reverseUrl,
28   -) => {
29   - logger.verbose(`${MODULE_NAME} 4AD4DF41: topup to komodo`, {
30   - requestId, destination, productName, xid,
31   - });
32   -
33   - const params = {
34   - request_id: requestId,
35   - terminal_name: config.komodo_http_get_x.terminal_name,
36   - password: config.komodo_http_get_x.password,
37   - destination,
38   - product_name: productName,
39   - reverse_url: reverseUrl,
40   - };
41   -
42   - try {
43   - const response = await client.get('/topup', {
44   - params,
45   - });
46   - if (!response) {
47   - throw new Error(`${MODULE_NAME} 6CE3E06E: Empty response from komodo`);
48   - }
49   - if (!response.data) {
50   - throw new Error(`${MODULE_NAME} F236476F: Empty response data from komodo`);
51   - }
52   -
53   - return response.data;
54   - } catch (err) {
55   - logger.warn(`${MODULE_NAME} 48BAA6B7: Exception`, {
56   - xid,
57   - requestId,
58   - destination,
59   - productName,
60   - message: err.message,
61   - });
62   - throw err;
63   - }
64   -};
lib/http-server/routers/postpaid-products/index.js
... ... @@ -1,80 +0,0 @@
1   -const MODULE_NAME = 'HTTP-SERVER.ROUTER.POSTPAID-PRODUCTS';
2   -
3   -const express = require('express');
4   -const logger = require('tektrans-logger');
5   -
6   -const configData = require('../../../config/data');
7   -const configSaveProduct = require('../../../config/save-postpaid-product');
8   -const configRemoveProduct = require('../../../config/remove-postpaid-product');
9   -
10   -const router = express.Router();
11   -
12   -module.exports = router;
13   -
14   -const pageIndex = async (req, res) => {
15   - const { xid } = res.locals;
16   - try {
17   - logger.verbose(`${MODULE_NAME} 24D7D9B4: get postpaid product configuration`, { xid });
18   - const products = (await configData.all()).postpaid_products || {};
19   - res.json({ error: false, message: 'OK', result: products });
20   - } catch (e) {
21   - logger.warn(`${MODULE_NAME} 1DB45AC5: Exception.`, {
22   - xid, eMessage: e.message, eCode: e.code,
23   - });
24   - res.status(500).json({
25   - error: true,
26   - error_code: e.code,
27   - message: e.message,
28   - });
29   - }
30   -};
31   -
32   -const pageSave = async (req, res) => {
33   - const { xid } = res.locals;
34   - const { name, remote = null, active = 0 } = req.body;
35   - try {
36   - logger.verbose(`${MODULE_NAME} A083E9DC: save postpaid product configuration`, { xid, data: req.body });
37   -
38   - const params = {
39   - name,
40   - remote,
41   - active,
42   - };
43   - await configSaveProduct(xid, name, params);
44   - res.json({ error: false, message: 'OK' });
45   - } catch (e) {
46   - logger.warn(`${MODULE_NAME} 88B9218F: Exception.`, {
47   - xid, eMessage: e.message, eCode: e.code,
48   - });
49   - res.status(500).json({
50   - error: true,
51   - error_code: e.code,
52   - message: e.message,
53   - });
54   - }
55   -};
56   -
57   -const pageRemove = async (req, res) => {
58   - const { xid } = res.locals;
59   - const { name } = req.body;
60   - try {
61   - logger.verbose(`${MODULE_NAME} 7AD392AE: remove postpaid product configuration`, { xid, name });
62   -
63   - await configRemoveProduct(xid, name);
64   - res.json({ error: false, message: 'OK' });
65   - } catch (e) {
66   - logger.warn(`${MODULE_NAME} F714088B: Exception.`, {
67   - xid, eMessage: e.message, eCode: e.code,
68   - });
69   - res.status(500).json({
70   - error: true,
71   - error_code: e.code,
72   - message: e.message,
73   - });
74   - }
75   -};
76   -
77   -router.get('/', [express.json()], pageIndex);
78   -
79   -router.post('/save', [express.json()], pageSave);
80   -router.post('/remove', [express.json()], pageRemove);
lib/http-server/routers/updates/index.js
... ... @@ -26,7 +26,7 @@ const pageUpdate = async (req, res) => {
26 26 }
27 27  
28 28 try {
29   - logger.verbose(`${MODULE_NAME} 9E5C70C8: update from komodo`, { xid, data });
  29 + logger.verbose(`${MODULE_NAME} 9E5C70C8: update from sds`, { xid, data });
30 30 const params = {
31 31 id: data.request_id,
32 32 rc: data.rc,
lib/pull/get-inquiry.js
... ... @@ -1,70 +0,0 @@
1   -const MODULE_NAME = 'PULL.GET-INQUIRY';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -const uniqid = require('uniqid');
6   -const config = require('../config');
7   -const configData = require('../config/data');
8   -const actions = require('../actions');
9   -
10   -const client = axios.create({
11   - baseURL: config.core.url,
12   - timeout: config.core.request_timeout_ms,
13   - headers: {
14   - 'x-access-token': config.core.access_token,
15   - },
16   -});
17   -
18   -let onPull = false;
19   -
20   -/**
21   - * pull unprocessed inquiry transaction from core
22   - */
23   -module.exports = async () => {
24   - logger.verbose(`${MODULE_NAME} 64E2EFDE: Pull inquiry transaction from core`);
25   - if (onPull) {
26   - logger.verbose(`${MODULE_NAME} EECB3ECC: Pull inquiry already running`);
27   - return false;
28   - }
29   - onPull = true;
30   -
31   - const xid = uniqid();
32   -
33   - try {
34   - const products = await configData.getActiveProductPostpaidArray(xid);
35   - const response = await client.post('/transactions/inquiry-pull', {
36   - gateway: {
37   - name: `${config.name}-postpaid`,
38   - url: `${config.url}:${config.port}/apikey/${config.apikey}/postpaid`,
39   - postpaid: 1,
40   - },
41   - products,
42   - });
43   - if (response.data.error) {
44   - logger.info(`${MODULE_NAME} E082E007: Error when pulling inquiry transaction`, {
45   - xid,
46   - message: response.data.message,
47   - error: response.data.error,
48   - });
49   - }
50   -
51   - if (!response.data.result) {
52   - logger.info(`${MODULE_NAME} 72C1FAC5: Empty inquiry transaction result`, {
53   - xid,
54   - result: response.data.result,
55   - });
56   - return null;
57   - }
58   -
59   - await actions.inquiry(xid, response.data.result);
60   - } catch (e) {
61   - logger.warn(`${MODULE_NAME} 1E5D9D56: Exception`, {
62   - xid,
63   - message: e.message,
64   - code: e.code,
65   - });
66   - } finally {
67   - onPull = false;
68   - }
69   - return true;
70   -};
lib/pull/get-payment.js
... ... @@ -1,70 +0,0 @@
1   -const MODULE_NAME = 'PULL.GET-PAYMENT';
2   -
3   -const logger = require('tektrans-logger');
4   -const axios = require('axios').default;
5   -const uniqid = require('uniqid');
6   -const config = require('../config');
7   -const configData = require('../config/data');
8   -const actions = require('../actions');
9   -
10   -const client = axios.create({
11   - baseURL: config.core.url,
12   - timeout: config.core.request_timeout_ms,
13   - headers: {
14   - 'x-access-token': config.core.access_token,
15   - },
16   -});
17   -
18   -let onPull = false;
19   -
20   -/**
21   - * pull unprocessed payment transaction from core
22   - */
23   -module.exports = async () => {
24   - logger.verbose(`${MODULE_NAME} 68CB1245: Pull payment transaction from core`);
25   - if (onPull) {
26   - logger.verbose(`${MODULE_NAME} 576C1D1A: Pull payment already running`);
27   - return false;
28   - }
29   - onPull = true;
30   -
31   - const xid = uniqid();
32   -
33   - try {
34   - const products = await configData.getActiveProductPostpaidArray(xid);
35   - const response = await client.post('/transactions/payment-pull', {
36   - gateway: {
37   - name: `${config.name}-postpaid`,
38   - url: `${config.url}:${config.port}/apikey/${config.apikey}/postpaid`,
39   - postpaid: 1,
40   - },
41   - products,
42   - });
43   - if (response.data.error) {
44   - logger.info(`${MODULE_NAME} E3093F6D: Error when pulling payment transaction`, {
45   - xid,
46   - message: response.data.message,
47   - error: response.data.error,
48   - });
49   - }
50   -
51   - if (!response.data.result) {
52   - logger.info(`${MODULE_NAME} 230E9E0F: Empty payment transaction result`, {
53   - xid,
54   - result: response.data.result,
55   - });
56   - return null;
57   - }
58   -
59   - await actions.pay(xid, response.data.result);
60   - } catch (e) {
61   - logger.warn(`${MODULE_NAME} 7E6D9444: Exception`, {
62   - xid,
63   - message: e.message,
64   - code: e.code,
65   - });
66   - } finally {
67   - onPull = false;
68   - }
69   - return true;
70   -};
... ... @@ -2,9 +2,7 @@ const MODULE_NAME = 'PULL.RUN';
2 2 const logger = require('tektrans-logger');
3 3  
4 4 const config = require('../config');
5   -const getInquiry = require('./get-inquiry');
6 5 const getPrepaid = require('./get-prepaid');
7   -const getPayment = require('./get-payment');
8 6  
9 7 /**
10 8 * Run pulling schedule
... ... @@ -16,7 +14,5 @@ module.exports = async () => {
16 14 setInterval(() => {
17 15 logger.verbose(`${MODULE_NAME} 06B8C652: Pull run`);
18 16 getPrepaid();
19   - getInquiry();
20   - getPayment();
21 17 }, config.pull_interval_ms);
22 18 };