Commit 97991a1dc4df63ecb9c77272529389c899d1264c
1 parent
6998514971
Exists in
master
pakai whiskers
Showing 3 changed files with 96 additions and 1 deletions Side-by-side Diff
message.xml
... | ... | @@ -0,0 +1,27 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | + | |
3 | +<SOAP-ENV:Envelope | |
4 | + SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" | |
5 | + xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" | |
6 | + xmlns:xsd="http://www.w3.org/2001/XMLSchema" | |
7 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
8 | + xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" | |
9 | + xmlns:tns="urn:apih2h"> | |
10 | + | |
11 | + <SOAP-ENV:Body> | |
12 | + <tns:billpayment xmlns:tns="urn:apih2h"> | |
13 | + <inputCheck xsi:type="tns:inputCheck"> | |
14 | + <userName xsi:type="xsd:string">{ params.userName }</userName> | |
15 | + <signature xsi:type="xsd:string">{ params.signature }</signature> | |
16 | + <productCode xsi:type="xsd:string">{ params.productCode }</productCode> | |
17 | + <terminal xsi:type="xsd:string">{ params.terminal }</terminal> | |
18 | + <transactionType xsi:type="xsd:string">{ params.transactionType }</transactionType> | |
19 | + <billNumber xsi:type="xsd:string">{ params.billNumber }</billNumber> | |
20 | + <amount xsi:type="xsd:string">{ params.amount }</amount> | |
21 | + <bit61 xsi:type="xsd:string">{ params.bit61 }</bit61> | |
22 | + <reff xsi:type="xsd:string">{ params.reff }</reff> | |
23 | + <timeStamp xsi:type="xsd:string">{ params.timeStamp }</timeStamp> | |
24 | + </inputCheck> | |
25 | + </tns:billpayment> | |
26 | + </SOAP-ENV:Body> | |
27 | +</SOAP-ENV:Envelope> |
package.json
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | "sate24": "git+http://gitlab.kodesumber.com/reload97/node-sate24.git", |
26 | 26 | "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git", |
27 | 27 | "soap": "^0.15.0", |
28 | + "whiskers": "^0.3.3", | |
28 | 29 | "winston": "^2.2.0" |
29 | 30 | }, |
30 | 31 | "devDependencies": { |
partner-kospinjasa.js
... | ... | @@ -2,6 +2,12 @@ var winston = require('winston'); |
2 | 2 | var soap = require('soap'); |
3 | 3 | var crypto = require('crypto'); |
4 | 4 | var strftime = require('strftime'); |
5 | +var fs = require("fs"); | |
6 | +var whiskers = require("whiskers"); | |
7 | +var http = require("http"); | |
8 | + | |
9 | +process.chdir(__dirname); | |
10 | +var soapTemplate = fs.readFileSync("message.xml"); | |
5 | 11 | |
6 | 12 | var max_retry = 10; |
7 | 13 | var sleep_before_retry = 5000; |
... | ... | @@ -52,7 +58,7 @@ function topupRequest(task, retry) { |
52 | 58 | var signature = createSignature(params, config.h2h_out.password); |
53 | 59 | params.signature = signature; |
54 | 60 | |
55 | - topupRequestSoap(task, params, retry); | |
61 | + topupRequestSoapDIY(task, params, retry); | |
56 | 62 | } |
57 | 63 | |
58 | 64 | function topupRequestSoap(task, params, retry) { |
... | ... | @@ -93,6 +99,67 @@ function topupRequestSoap(task, params, retry) { |
93 | 99 | }); |
94 | 100 | } |
95 | 101 | |
102 | +function topupRequestSoapDIY(task, params, retry) { | |
103 | + var message = whiskers.render(soapTemplate, params); | |
104 | + logger.verbose("Generating SOAP message", {message: message}); | |
105 | + | |
106 | + var partnerUrl = url.parse(config.h2h_out.partner); | |
107 | + var postRequest = { | |
108 | + host: partnerUrl.hostname, | |
109 | + path: partnerUrl.path, | |
110 | + port: partnerUrl.port, | |
111 | + method: "POST", | |
112 | + headers: { | |
113 | + 'Content-Type': 'application/soap', | |
114 | + 'Content-Length': Buffer.byteLength(message) | |
115 | + } | |
116 | + }; | |
117 | + | |
118 | + logger.info('POST to partner', {postRequest: postRequest}); | |
119 | + var req = http.request(postRequest, function( res ) { | |
120 | + | |
121 | + logger.verbose('Request status code: ' + res.statusCode ); | |
122 | + var buffer = ""; | |
123 | + | |
124 | + res.on( "data", function( data ) { | |
125 | + buffer = buffer + data; | |
126 | + }); | |
127 | + | |
128 | + res.on( "end", function( data ) { | |
129 | + topupResponseHandler(buffer, task); | |
130 | + }); | |
131 | + | |
132 | + }); | |
133 | + | |
134 | + req.on('error', function(e) { | |
135 | + logger.warn('problem with request: ' + e.message); | |
136 | + callbackReport(task.requestId, '68', e.message); | |
137 | + | |
138 | + topupRequestRetry(task); | |
139 | + }); | |
140 | + | |
141 | + req.write(message); | |
142 | + req.end(); | |
143 | +} | |
144 | + | |
145 | +function topupResponseHandler(response, task) { | |
146 | + logger.verbose('Got response', {response: response, task: task}); | |
147 | + callbackReport(task.requestId, '68', 'Got response'); | |
148 | +} | |
149 | + | |
150 | +function topupRequestRetry(task) { | |
151 | + task.retry--; | |
152 | + | |
153 | + if (task.retry > 0) { | |
154 | + logger.info('Retrying in ' + sleepBeforeRetry + 's'); | |
155 | + setTimeout(topupRequest, sleepBeforeRetry * 1000, task, task.retry); | |
156 | + } | |
157 | + else { | |
158 | + logger.warn('Maximum retry for pending status exceeded', {task: task}); | |
159 | + } | |
160 | +} | |
161 | + | |
162 | + | |
96 | 163 | |
97 | 164 | |
98 | 165 | function createSignature(params, password) { |