Commit b6b185202d8a1134a5de5fc49851d7881acebfcb

Authored by Adhidarma Hadiwinoto
1 parent db96f57031
Exists in master

inputCheck

Showing 1 changed file with 20 additions and 19 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 params = {
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(params, config.h2h_out.password);
54 args.signature = signature; 54 params.signature = signature;
55 55
56 topupRequestEasySoap(task, args, retry); 56 topupRequestSoap(task, params, 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 clientParams = { 62 var clientParams = {
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 clientOptions = { 68 var clientOptions = {
69 secure: false, 69 secure: false,
70 } 70 }
71 71
72 var soapClient = new easysoap.Client(clientParams, clientOptions); 72 var soapClient = new easysoap.Client(clientParams, clientOptions);
73 soapClient.call( 73 soapClient.call(
74 {method: 'billpayment', params: args} 74 {method: 'billpayment', params: args}
75 ).done( 75 ).done(
76 //success 76 //success
77 function(res) { 77 function(res) {
78 res.data // response data as array 78 res.data // response data as array
79 res.response // full response data (including xml) 79 res.response // full response data (including xml)
80 res.header // response header 80 res.header // response header
81 }, 81 },
82 82
83 //method fail 83 //method fail
84 function(err) { 84 function(err) {
85 console.log(err); 85 console.log(err);
86 } 86 }
87 ); 87 );
88 88
89 callbackReport(task.requestId, '68', 'debug'); 89 callbackReport(task.requestId, '68', 'debug');
90 } 90 }
91 91
92 function topupRequestSoap(task, args, retry) { 92 function topupRequestSoap(task, params, retry) {
93 93
94 soap.createClient(config.h2h_out.partner, function(err, client) { 94 soap.createClient(config.h2h_out.partner, function(err, soapClient) {
95 95
96 logger.info('Requesting to service', {url: config.h2h_out.partner, args: args}); 96 logger.info('Requesting to service', {url: config.h2h_out.partner, params: params});
97
98 soapClient.apih2h.apih2hPort.billpayment({inputCheck: params}, function(err, result) {
97 99
98 client.apih2h.apih2hPort.billpayment(args, function(err, result) {
99 if (err) { 100 if (err) {
100 logger.warn('Error requesting service', {err: err}); 101 logger.warn('Error requesting service', {err: err});
101 callbackReport(task.requestId, '68', 'something wrong'); 102 callbackReport(task.requestId, '68', 'something wrong');
102 return; 103 return;
103 } 104 }
104 105
105 var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value; 106 var responseMessageToST24 = result.outputParameter.resultCode.$value + ' - ' + result.outputParameter.resultDesc.$value;
106 107
107 logger.info('Got result: ' + responseMessageToST24, {result: result}); 108 logger.info('Got result: ' + responseMessageToST24, {result: result});
108 109
109 callbackReport(task.requestId, '68', responseMessageToST24); 110 callbackReport(task.requestId, '68', responseMessageToST24);
110 }); 111 });
111 }); 112 });
112 } 113 }
113 114
114 115
115 116
116 function createSignature(args, password) { 117 function createSignature(params, password) {
117 var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); 118 var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex');
118 119
119 var plain = 120 var plain =
120 args.userName 121 params.userName
121 + passwordHash 122 + passwordHash
122 + args.productCode 123 + params.productCode
123 + args.terminal 124 + params.terminal
124 + args.transactionType 125 + params.transactionType
125 + args.billNumber 126 + params.billNumber
126 + args.amount 127 + params.amount
127 + args.reff 128 + params.reff
128 + args.timeStamp; 129 + params.timeStamp;
129 130
130 var result = crypto.createHash('sha1').update(plain).digest().toString('hex'); 131 var result = crypto.createHash('sha1').update(plain).digest().toString('hex');
131 132
132 if (logger) { 133 if (logger) {
133 logger.verbose('Calculating signature', {plain: plain, result: result, args: args, password: password}); 134 logger.verbose('Calculating signature', {plain: plain, result: result, params: params, password: password});
134 } 135 }
135 136
136 return result; 137 return result;
137 } 138 }
138 139
139 function createBillNumber(destination) { 140 function createBillNumber(destination) {
140 return ("0000000000000" + destination).slice(-13); 141 return ("0000000000000" + destination).slice(-13);
141 } 142 }
142 143
143 exports.start = start; 144 exports.start = start;
144 exports.topupRequest = topupRequest; 145 exports.topupRequest = topupRequest;
145 exports.createSignature = createSignature; 146 exports.createSignature = createSignature;
146 exports.createBillNumber = createBillNumber; 147 exports.createBillNumber = createBillNumber;