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 Inline Diff

1 { 1 {
2 "name": "gateway-sds-ss", 2 "name": "gateway-sds",
3 "url": "http://localhost", 3 "url": "http://localhost",
4 "port": 11330, 4 "port": 11330,
5 "apikey": "fd97cf519b979262d9d9004cba6a165629ca8b69350a6afdcaab6ab2c9a996ae", 5 "apikey": "fd97cf519b979262d9d9004cba6a165629ca8b69350a6afdcaab6ab2c9a996ae",
6 "pull_interval_ms": 5000, 6 "pull_interval_ms": 5000,
7 "core": { 7 "core": {
8 "url": "http://localhost:26840", 8 "url": "http://localhost:26840",
9 "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnZW5lcmF0b3IiOiJDTEkiLCJjbGllbnQiOnsibmFtZSI6IktPTU9ETzItR1ctU0RTLVNTIn0sImlhdCI6MTY1ODkwODA4N30.2Ego28jwgPs3s9-iKSbYipO72FTH5gFC5gkVccqiN24", 9 "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnZW5lcmF0b3IiOiJDTEkiLCJjbGllbnQiOnsibmFtZSI6IktPTU9ETzItR1ctU0RTLVNTIn0sImlhdCI6MTY1ODkwODA4N30.2Ego28jwgPs3s9-iKSbYipO72FTH5gFC5gkVccqiN24",
10 "request_timeout_ms": 10000 10 "request_timeout_ms": 10000
11 }, 11 },
12 "products": { 12 "products": {
13 }, 13 },
14 "postpaid_products": { 14 "postpaid_products": {
15 }, 15 },
16 "sds_ss": { 16 "sds_ss": {
17 "url": "http://localhost:8187/request", 17 "url": "http://localhost:8187/request",
18 "request_timeout_ms": 10000, 18 "request_timeout_ms": 10000,
19 "username": "user", 19 "username": "user",
20 "password": "1234" 20 "password": "1234"
21 } 21 }
22 } 22 }
23 23
lib/actions/buy-to-sds.js
File was created 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 };
69
1 const MODULE_NAME = 'ACTIONS.BUY'; 1 const MODULE_NAME = 'ACTIONS.BUY';
2 2
3 const logger = require('tektrans-logger'); 3 const logger = require('tektrans-logger');
4 const axios = require('axios').default; 4 const axios = require('axios').default;
5 5
6 const config = require('../config'); 6 const config = require('../config');
7 const configData = require('../config/data'); 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 const client = axios.create({ 11 const client = axios.create({
12 baseURL: config.core.url, 12 baseURL: config.core.url,
13 timeout: config.core.request_timeout_ms, 13 timeout: config.core.request_timeout_ms,
14 headers: { 14 headers: {
15 'x-access-token': config.core.access_token, 15 'x-access-token': config.core.access_token,
16 }, 16 },
17 }); 17 });
18 18
19 /** 19 /**
20 * Buy a product from supplier komodo 20 * Buy a product from supplier komodo
21 * 21 *
22 * @param {string} xid 22 * @param {string} xid
23 * @param {object} transaction 23 * @param {object} transaction
24 * 24 *
25 */ 25 */
26 module.exports = async (xid, transaction) => { 26 module.exports = async (xid, transaction) => {
27 try { 27 try {
28 logger.verbose(`${MODULE_NAME} 4B139379: Buy product to komodo`, { 28 logger.verbose(`${MODULE_NAME} 4B139379: Buy product to komodo`, {
29 xid, 29 xid,
30 transaction, 30 transaction,
31 }); 31 });
32 const iConfig = await configData.all(); 32 const iConfig = await configData.all();
33 33
34 let productName = transaction.product_name; 34 let productName = transaction.product_name;
35 if ( 35 if (
36 iConfig.products[transaction.product_name] 36 iConfig.products[transaction.product_name]
37 && iConfig.products[transaction.product_name].remote 37 && iConfig.products[transaction.product_name].remote
38 ) { 38 ) {
39 productName = iConfig.products[transaction.product_name].remote; 39 productName = iConfig.products[transaction.product_name].remote;
40 } 40 }
41 41
42 const callbackUrl = `${iConfig.url}:${iConfig.port}/apikey/${iConfig.apikey}/updates`; 42 const callbackUrl = `${iConfig.url}:${iConfig.port}/apikey/${iConfig.apikey}/updates`;
43 const result = await topupToKomodo( 43 const result = await buyToSDS(
44 xid, 44 xid,
45 transaction.id, 45 transaction.id,
46 transaction.destination, 46 transaction.destination,
47 productName, 47 productName,
48 transaction.quantity,
48 callbackUrl, 49 callbackUrl,
49 ); 50 );
50 logger.verbose(`${MODULE_NAME} 5BDFAF41: result from komodo`, { 51 logger.verbose(`${MODULE_NAME} 5BDFAF41: result from sds`, {
51 xid, 52 xid,
52 trxId: transaction.id, 53 trxId: transaction.id,
53 result, 54 result,
54 }); 55 });
55 const params = { 56 const params = {
56 id: result.request_id, 57 id: result.request_id,
57 rc: result.rc, 58 rc: result.rc,
58 amount: result.amount || null, 59 amount: result.amount || null,
59 message: result.message, 60 message: result.message,
60 sn: result.sn || null, 61 sn: result.sn || null,
61 }; 62 };
62 63
63 await client.post('/transactions/gateway-update', params); 64 await client.post('/transactions/gateway-update', params);
64 } catch (e) { 65 } catch (e) {
65 logger.warn(`${MODULE_NAME} E9887C98: Exception`, { 66 logger.warn(`${MODULE_NAME} E9887C98: Exception`, {
66 xid, 67 xid,
67 message: e.message, 68 message: e.message,
68 code: e.code, 69 code: e.code,
69 }); 70 });
70 } 71 }
71 }; 72 };
72 73
lib/actions/index.js
1 exports.buy = require('./buy'); 1 exports.buy = require('./buy');
2 exports.inquiry = require('./inquiry'); 2
3 exports.pay = require('./pay');
4 3
lib/actions/inquiry-to-komodo.js
1 const MODULE_NAME = 'ACTIONS.INQUIRY-TO-KOMODO'; File was deleted
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 };
65 1 const MODULE_NAME = 'ACTIONS.INQUIRY-TO-KOMODO';
lib/actions/inquiry.js
1 const MODULE_NAME = 'ACTIONS.INQUIRY'; File was deleted
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 };
72 1 const MODULE_NAME = 'ACTIONS.INQUIRY';
lib/actions/pay.js
1 const MODULE_NAME = 'ACTIONS.PAY'; File was deleted
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 };
72 1 const MODULE_NAME = 'ACTIONS.PAY';
lib/actions/payment-to-komodo.js
1 const MODULE_NAME = 'ACTIONS.PAY-TO-KOMODO'; File was deleted
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 };
65 1 const MODULE_NAME = 'ACTIONS.PAY-TO-KOMODO';
lib/actions/topup-to-komodo.js
1 const MODULE_NAME = 'ACTIONS.TOPUP-TO-KOMODO'; File was deleted
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 };
65 1 const MODULE_NAME = 'ACTIONS.TOPUP-TO-KOMODO';
lib/http-server/routers/postpaid-products/index.js
1 const MODULE_NAME = 'HTTP-SERVER.ROUTER.POSTPAID-PRODUCTS'; File was deleted
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);
81 1 const MODULE_NAME = 'HTTP-SERVER.ROUTER.POSTPAID-PRODUCTS';
lib/http-server/routers/updates/index.js
1 const MODULE_NAME = 'HTTP-SERVER.ROUTER.UPDATES'; 1 const MODULE_NAME = 'HTTP-SERVER.ROUTER.UPDATES';
2 2
3 const express = require('express'); 3 const express = require('express');
4 const axios = require('axios').default; 4 const axios = require('axios').default;
5 const logger = require('tektrans-logger'); 5 const logger = require('tektrans-logger');
6 6
7 const config = require('../../../config'); 7 const config = require('../../../config');
8 8
9 const router = express.Router(); 9 const router = express.Router();
10 10
11 module.exports = router; 11 module.exports = router;
12 12
13 const client = axios.create({ 13 const client = axios.create({
14 baseURL: config.core.url, 14 baseURL: config.core.url,
15 timeout: config.core.request_timeout_ms, 15 timeout: config.core.request_timeout_ms,
16 headers: { 16 headers: {
17 'x-access-token': config.core.access_token, 17 'x-access-token': config.core.access_token,
18 }, 18 },
19 }); 19 });
20 20
21 const pageUpdate = async (req, res) => { 21 const pageUpdate = async (req, res) => {
22 const { xid } = res.locals; 22 const { xid } = res.locals;
23 let data = req.query; 23 let data = req.query;
24 if (req.method.toUpperCase() !== 'GET') { 24 if (req.method.toUpperCase() !== 'GET') {
25 data = req.body; 25 data = req.body;
26 } 26 }
27 27
28 try { 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 const params = { 30 const params = {
31 id: data.request_id, 31 id: data.request_id,
32 rc: data.rc, 32 rc: data.rc,
33 amount: data.amount || null, 33 amount: data.amount || null,
34 message: data.message, 34 message: data.message,
35 sn: data.sn || null, 35 sn: data.sn || null,
36 bill_count: data.bill_count, 36 bill_count: data.bill_count,
37 bill_amount: data.bill_amount, 37 bill_amount: data.bill_amount,
38 related_data: null, 38 related_data: null,
39 amount_to_charge: data.amount_to_charge, 39 amount_to_charge: data.amount_to_charge,
40 }; 40 };
41 41
42 client.post('/transactions/gateway-update', params).then((result) => { 42 client.post('/transactions/gateway-update', params).then((result) => {
43 logger.verbose(`${MODULE_NAME} A8DA0D04: response from core2`, { 43 logger.verbose(`${MODULE_NAME} A8DA0D04: response from core2`, {
44 xid, 44 xid,
45 response: result.data, 45 response: result.data,
46 }); 46 });
47 }).catch((err) => { 47 }).catch((err) => {
48 logger.warn(`${MODULE_NAME} 32EB485C: Exception on request to core2`, { 48 logger.warn(`${MODULE_NAME} 32EB485C: Exception on request to core2`, {
49 xid, 49 xid,
50 eMessage: err.message, 50 eMessage: err.message,
51 eCode: err.code, 51 eCode: err.code,
52 }); 52 });
53 }); 53 });
54 54
55 res.json({ error: false, message: 'OK' }); 55 res.json({ error: false, message: 'OK' });
56 } catch (e) { 56 } catch (e) {
57 logger.warn(`${MODULE_NAME} B12B4A2C: Exception.`, { 57 logger.warn(`${MODULE_NAME} B12B4A2C: Exception.`, {
58 xid, eMessage: e.message, eCode: e.code, 58 xid, eMessage: e.message, eCode: e.code,
59 }); 59 });
60 res.status(500).json({ 60 res.status(500).json({
61 error: true, 61 error: true,
62 error_code: e.code, 62 error_code: e.code,
63 message: e.message, 63 message: e.message,
64 }); 64 });
65 } 65 }
66 }; 66 };
67 67
68 router.get('/', pageUpdate); 68 router.get('/', pageUpdate);
69 router.post('/', [express.urlencoded({ extended: true }), express.json()], pageUpdate); 69 router.post('/', [express.urlencoded({ extended: true }), express.json()], pageUpdate);
70 70
lib/pull/get-inquiry.js
1 const MODULE_NAME = 'PULL.GET-INQUIRY'; File was deleted
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 };
71 1 const MODULE_NAME = 'PULL.GET-INQUIRY';
lib/pull/get-payment.js
1 const MODULE_NAME = 'PULL.GET-PAYMENT'; File was deleted
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 };
71 1 const MODULE_NAME = 'PULL.GET-PAYMENT';
1 const MODULE_NAME = 'PULL.RUN'; 1 const MODULE_NAME = 'PULL.RUN';
2 const logger = require('tektrans-logger'); 2 const logger = require('tektrans-logger');
3 3
4 const config = require('../config'); 4 const config = require('../config');
5 const getInquiry = require('./get-inquiry');
6 const getPrepaid = require('./get-prepaid'); 5 const getPrepaid = require('./get-prepaid');
7 const getPayment = require('./get-payment');
8 6
9 /** 7 /**
10 * Run pulling schedule 8 * Run pulling schedule
11 */ 9 */
12 module.exports = async () => { 10 module.exports = async () => {
13 logger.verbose(`${MODULE_NAME} 34022A49: Run pulling schedule`, { 11 logger.verbose(`${MODULE_NAME} 34022A49: Run pulling schedule`, {
14 interval: config.pull_interval_ms, 12 interval: config.pull_interval_ms,
15 }); 13 });
16 setInterval(() => { 14 setInterval(() => {
17 logger.verbose(`${MODULE_NAME} 06B8C652: Pull run`); 15 logger.verbose(`${MODULE_NAME} 06B8C652: Pull run`);
18 getPrepaid(); 16 getPrepaid();
19 getInquiry();
20 getPayment();
21 }, config.pull_interval_ms); 17 }, config.pull_interval_ms);
22 }; 18 };
23 19