Commit caeb5ddbc6b80538500d816e7249691e9e74ac09

Authored by Adhidarma Hadiwinoto
1 parent 7f796c8131
Exists in master

typo

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

partner-kospinjasa.js
1 var winston = require('winston'); 1 var winston = require('winston');
2 var soap = require('soap'); 2 var soap = require('soap');
3 var crypto = require('crypto'); 3 var crypto = require('crypto');
4 var strftime = require('strftime'); 4 var strftime = require('strftime');
5 var easysoap = require('easysoap'); 5 var easysoap = require('easysoap');
6 6
7 var max_retry = 10; 7 var max_retry = 10;
8 var sleep_before_retry = 5000; 8 var sleep_before_retry = 5000;
9 9
10 var config; 10 var config;
11 var callbackReport; 11 var callbackReport;
12 var aaa; 12 var aaa;
13 var logger; 13 var logger;
14 var options; 14 var options;
15 15
16 function start(_config, _callbackReport, options) { 16 function start(_config, _callbackReport, options) {
17 config = _config; 17 config = _config;
18 callbackReport = _callbackReport 18 callbackReport = _callbackReport
19 19
20 if (options && options.aaa) { 20 if (options && options.aaa) {
21 aaa = options.aaa; 21 aaa = options.aaa;
22 } 22 }
23 23
24 if (options && options.logger) { 24 if (options && options.logger) {
25 logger = options.logger; 25 logger = options.logger;
26 } else { 26 } else {
27 logger = new winston.Logger({ 27 logger = new winston.Logger({
28 transports: [ 28 transports: [
29 new (winston.transports.Console)() 29 new (winston.transports.Console)()
30 ] 30 ]
31 }); 31 });
32 } 32 }
33 } 33 }
34 34
35 function topupRequest(task, retry) { 35 function topupRequest(task, retry) {
36 if (retry === undefined) { 36 if (retry === undefined) {
37 retry = max_retry; 37 retry = max_retry;
38 } 38 }
39 39
40 var remoteProduct = task.remoteProduct.split(','); 40 var remoteProduct = task.remoteProduct.split(',');
41 var args = { 41 var args = {
42 userName: config.h2h_out.userid, 42 userName: config.h2h_out.userid,
43 productCode: remoteProduct[0] , 43 productCode: remoteProduct[0] ,
44 terminal: 'terminal0', 44 terminal: 'terminal0',
45 transactionType: '50', 45 transactionType: '50',
46 billNumber: createBillNumber(task.destination), 46 billNumber: createBillNumber(task.destination),
47 amount: remoteProduct[1], 47 amount: remoteProduct[1],
48 bit61: createBillNumber(task.destination), 48 bit61: createBillNumber(task.destination),
49 reff: task.requestId, 49 reff: task.requestId,
50 timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()), 50 timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()),
51 } 51 }
52 52
53 var signature = createSignature(args, config.h2h_out.password); 53 var signature = createSignature(args, config.h2h_out.password);
54 args.signature = signature; 54 args.signature = signature;
55 55
56 topupRequestEasySoap(task, args, retry); 56 topupRequestEasySoap(task, args, retry);
57 } 57 }
58 58
59 function topupRequestEasySoap(task, args, retry) { 59 function topupRequestEasySoap(task, args, retry) {
60 //partner=http://203.130.243.155/ApiH2H/index.php?wsdl 60 //partner=http://203.130.243.155/ApiH2H/index.php?wsdl
61 61
62 var params = { 62 var params = {
63 host: '203.130.243.155', 63 host: '203.130.243.155',
64 path: '/ApiH2H/index.php' 64 path: '/ApiH2H/index.php',
65 wsdl: '/ApiH2H/index.php?wsdl' 65 wsdl: '/ApiH2H/index.php?wsdl'
66 } 66 }
67 67
68 var soapClient = easysoap.createClient(params); 68 var soapClient = easysoap.createClient(params);
69 soapClient.call({ 69 soapClient.call({
70 method: 'billpayment', 70 method: 'billpayment',
71 params: args, 71 params: args,
72 }) 72 })
73 .then((callResponse) => { 73 .then((callResponse) => {
74 console.log(callResponse.data); // response data as json 74 console.log(callResponse.data); // response data as json
75 console.log(callResponse.body); // response body 75 console.log(callResponse.body); // response body
76 console.log(callResponse.header); //response header 76 console.log(callResponse.header); //response header
77 }) 77 })
78 .catch((err) => { throw new Error(err); }); 78 .catch((err) => { throw new Error(err); });
79 79
80 callbackReport(task.requestId, '68', 'debug'); 80 callbackReport(task.requestId, '68', 'debug');
81 81
82 } 82 }
83 83
84 function topupRequestSoap(task, args, retry) { 84 function topupRequestSoap(task, args, retry) {
85 85
86 soap.createClient(config.h2h_out.partner, function(err, client) { 86 soap.createClient(config.h2h_out.partner, function(err, client) {
87 87
88 logger.info('Requesting to service', {url: config.h2h_out.partner, args: args}); 88 logger.info('Requesting to service', {url: config.h2h_out.partner, args: args});
89 89
90 client.apih2h.apih2hPort.billpayment(args, function(err, result) { 90 client.apih2h.apih2hPort.billpayment(args, function(err, result) {
91 if (err) { 91 if (err) {
92 logger.warn('Error requesting service', {err: err}); 92 logger.warn('Error requesting service', {err: err});
93 callbackReport(task.requestId, '68', 'something wrong'); 93 callbackReport(task.requestId, '68', 'something wrong');
94 return; 94 return;
95 } 95 }
96 96
97 var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value; 97 var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value;
98 98
99 logger.info('Got result: ' + responseMessageToST24, {result: result}); 99 logger.info('Got result: ' + responseMessageToST24, {result: result});
100 100
101 callbackReport(task.requestId, '68', responseMessageToST24); 101 callbackReport(task.requestId, '68', responseMessageToST24);
102 }); 102 });
103 }); 103 });
104 } 104 }
105 105
106 106
107 107
108 function createSignature(args, password) { 108 function createSignature(args, password) {
109 var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); 109 var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex');
110 110
111 var plain = 111 var plain =
112 args.userName 112 args.userName
113 + passwordHash 113 + passwordHash
114 + args.productCode 114 + args.productCode
115 + args.terminal 115 + args.terminal
116 + args.transactionType 116 + args.transactionType
117 + args.billNumber 117 + args.billNumber
118 + args.amount 118 + args.amount
119 + args.reff 119 + args.reff
120 + args.timeStamp; 120 + args.timeStamp;
121 121
122 var result = crypto.createHash('sha1').update(plain).digest().toString('hex'); 122 var result = crypto.createHash('sha1').update(plain).digest().toString('hex');
123 123
124 if (logger) { 124 if (logger) {
125 logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password}); 125 logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password});
126 } 126 }
127 127
128 return result; 128 return result;
129 } 129 }
130 130
131 function createBillNumber(destination) { 131 function createBillNumber(destination) {
132 return ("0000000000000" + destination).slice(-13); 132 return ("0000000000000" + destination).slice(-13);
133 } 133 }
134 134
135 exports.start = start; 135 exports.start = start;
136 exports.topupRequest = topupRequest; 136 exports.topupRequest = topupRequest;
137 exports.createSignature = createSignature; 137 exports.createSignature = createSignature;
138 exports.createBillNumber = createBillNumber; 138 exports.createBillNumber = createBillNumber;
139 139