Commit 67a5d925449467a6eff2ed62ff1863ce164138cd
1 parent
492595ffb6
Exists in
master
siap ditest
Showing 4 changed files with 136 additions and 1 deletions Side-by-side Diff
index.js
... | ... | @@ -0,0 +1,26 @@ |
1 | +var fs = require('fs'); | |
2 | +var ini = require('ini'); | |
3 | +var expresso = require('sate24-expresso'); | |
4 | +var config = ini.parse(fs.readFileSync(__dirname + '/config.ini', 'utf-8')); | |
5 | + | |
6 | +process.chdir(__dirname); | |
7 | + | |
8 | +var logger = require('sate24/logger.js').start(); | |
9 | +var HttpServer = require('sate24/httpserver.js'); | |
10 | +var aaa = require('sate24/aaa.js'); | |
11 | +var partner = require('./partner-bayarkilat.js'); | |
12 | + | |
13 | +var matrix = aaa.prepareMatrix(); | |
14 | + | |
15 | +var options = { | |
16 | + 'aaa': aaa, | |
17 | + 'logger': logger, | |
18 | + 'config': config, | |
19 | + 'matrix': matrix, | |
20 | +} | |
21 | + | |
22 | +var httpServer = HttpServer.start(config, options); | |
23 | + | |
24 | +partner.start(config, aaa.callbackReport, options); | |
25 | +aaa.start(config, partner, options); | |
26 | +expresso.start(options); |
package.json
... | ... | @@ -18,5 +18,12 @@ |
18 | 18 | "bayarkilat" |
19 | 19 | ], |
20 | 20 | "author": "Adhidarma Hadiwinoto <me@adhisimon.org>", |
21 | - "license": "ISC" | |
21 | + "license": "ISC", | |
22 | + "dependencies": { | |
23 | + "sate24": "git+http://gitlab.kodesumber.com/reload97/node-sate24.git", | |
24 | + "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git" | |
25 | + }, | |
26 | + "devDependencies": { | |
27 | + "should": "^9.0.2" | |
28 | + } | |
22 | 29 | } |
partner-bayarkilat.js
... | ... | @@ -0,0 +1,87 @@ |
1 | +var request = require('request'); | |
2 | +var url = require('url'); | |
3 | +var winston = require('winston'); | |
4 | + | |
5 | +var config; | |
6 | +var aaa; | |
7 | +var callbackReport; | |
8 | +var logger; | |
9 | + | |
10 | +function start(_config, _callbackReport, options) { | |
11 | + config = _config; | |
12 | + callbackReport = _callbackReport; | |
13 | + | |
14 | + if (options && options.aaa) { | |
15 | + aaa = options.aaa; | |
16 | + } | |
17 | + | |
18 | + if (options && options.logger) { | |
19 | + logger = options.logger; | |
20 | + } else { | |
21 | + logger = new winston.Logger({ | |
22 | + transports: [ | |
23 | + new (winston.transports.Console)() | |
24 | + ] | |
25 | + }); | |
26 | + } | |
27 | +} | |
28 | + | |
29 | + | |
30 | +function topupRequest(task, retry) { | |
31 | + aaa.insertTaskToMongoDb(task); | |
32 | + | |
33 | + var partnerUrl = url.parse(config.h2h_out.partner); | |
34 | + var product = prepareRemoteProductCode(task.remoteProduct); | |
35 | + | |
36 | + var options = { | |
37 | + host: partnerUrl.hostname, | |
38 | + path: partnerUrl.pathname, | |
39 | + port: partnerUrl.port, | |
40 | + qs: { | |
41 | + request: 'PURCHASE*' | |
42 | + + task.requestId + '*' | |
43 | + + product.product + '*' | |
44 | + + product.productDetail + '*' | |
45 | + + task.destination + '*' | |
46 | + + task.nominal + '*' | |
47 | + + '0*' | |
48 | + + config.h2h_out.noid + '*' | |
49 | + + config.h2h_out.userid + '*' | |
50 | + + config.h2h_out.password | |
51 | + } | |
52 | + }; | |
53 | + | |
54 | + request(options, function(error, response, body) { | |
55 | + if (error) { | |
56 | + logger.warn('Error requesting to partner', {error: error}); | |
57 | + callbackReport(task.requestId, '68', 'Error requesting to partner. ' + error); | |
58 | + return; | |
59 | + } | |
60 | + | |
61 | + if (response.statusCode != 200) { | |
62 | + var message = 'Partner response with http status code other that 200 (' + response.statusCode +')'; | |
63 | + | |
64 | + logger.warn(message); | |
65 | + callbackReport(task.requestId, '68', message); | |
66 | + return; | |
67 | + } | |
68 | + | |
69 | + callbackReport(task.requestId, '68', body); | |
70 | + }); | |
71 | +} | |
72 | + | |
73 | +function prepareRemoteProductCode(remoteProduct) { | |
74 | + var product = remoteProduct.split(','); | |
75 | + | |
76 | + if (product.length != 3) { | |
77 | + return; | |
78 | + } | |
79 | + | |
80 | + return { | |
81 | + product: product[0], | |
82 | + productDetail: product[1], | |
83 | + nominal: product[2] | |
84 | + } | |
85 | +} | |
86 | + | |
87 | +exports.prepareRemoteProductCode = prepareRemoteProductCode; |
test.js
... | ... | @@ -0,0 +1,15 @@ |
1 | +var should = require('should'); | |
2 | +var partner = require('./partner-bayarkilat'); | |
3 | + | |
4 | +describe('#partner-bayarkilat', function() { | |
5 | + | |
6 | + describe('#prepareRemoteProductCode', function() { | |
7 | + product = partner.prepareRemoteProductCode('PULSA,TELKOMSEL10,10000'); | |
8 | + | |
9 | + it('should return correct object', function() { | |
10 | + product.product.should.equal('PULSA'); | |
11 | + product.productDetail.should.equal('TELKOMSEL10'); | |
12 | + product.nominal.should.equal('10000'); | |
13 | + }); | |
14 | + }); | |
15 | +}); |