Commit 35d3e5057e3b1a66e5e3a98862885fe3fae32d5d
1 parent
5a947e4006
Exists in
master
pakai signature
Showing 2 changed files with 12 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 | 5 | ||
6 | var max_retry = 10; | 6 | var max_retry = 10; |
7 | var sleep_before_retry = 5000; | 7 | var sleep_before_retry = 5000; |
8 | 8 | ||
9 | var config; | 9 | var config; |
10 | var callbackReport; | 10 | var callbackReport; |
11 | var aaa; | 11 | var aaa; |
12 | var logger; | 12 | var logger; |
13 | var options; | 13 | var options; |
14 | 14 | ||
15 | function start(_config, _callbackReport, options) { | 15 | function start(_config, _callbackReport, options) { |
16 | config = _config; | 16 | config = _config; |
17 | callbackReport = _callbackReport | 17 | callbackReport = _callbackReport |
18 | 18 | ||
19 | if (options && options.aaa) { | 19 | if (options && options.aaa) { |
20 | aaa = options.aaa; | 20 | aaa = options.aaa; |
21 | } | 21 | } |
22 | 22 | ||
23 | if (options && options.logger) { | 23 | if (options && options.logger) { |
24 | logger = options.logger; | 24 | logger = options.logger; |
25 | } else { | 25 | } else { |
26 | logger = new winston.Logger({ | 26 | logger = new winston.Logger({ |
27 | transports: [ | 27 | transports: [ |
28 | new (winston.transports.Console)() | 28 | new (winston.transports.Console)() |
29 | ] | 29 | ] |
30 | }); | 30 | }); |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | function topupRequest(task, retry) { | 34 | function topupRequest(task, retry) { |
35 | if (retry === undefined) { | 35 | if (retry === undefined) { |
36 | retry = max_retry; | 36 | retry = max_retry; |
37 | } | 37 | } |
38 | 38 | ||
39 | var remoteProduct = task.remoteProduct.split(','); | 39 | var remoteProduct = task.remoteProduct.split(','); |
40 | 40 | ||
41 | soap.createClient(url, function(err, client) { | 41 | soap.createClient(url, function(err, client) { |
42 | var args = { | 42 | var args = { |
43 | userName: config.h2h_out.userid, | 43 | userName: config.h2h_out.userid, |
44 | productCode: remoteProduct[0] , | 44 | productCode: remoteProduct[0] , |
45 | terminal: 'terminal0', | 45 | terminal: 'terminal0', |
46 | transactionType: '50', | 46 | transactionType: '50', |
47 | billNumber: createBillNumber(task.destination), | 47 | billNumber: createBillNumber(task.destination), |
48 | amount: remoteProduct[1], | 48 | amount: remoteProduct[1], |
49 | bit61: createBillNumber(task.destination), | 49 | bit61: createBillNumber(task.destination), |
50 | reff: task.requestId, | 50 | reff: task.requestId, |
51 | timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()); | 51 | timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date()), |
52 | } | 52 | } |
53 | 53 | ||
54 | var signature = createSignature(args, config.h2h_out.password); | ||
55 | args.signature = signature; | ||
56 | |||
54 | client.billpayment(args, function(err, result) { | 57 | client.billpayment(args, function(err, result) { |
55 | if (err) { | 58 | if (err) { |
56 | logger.warn('Error requesting service', {err: err}); | 59 | logger.warn('Error requesting service', {err: err}); |
57 | callbackReport(task.requestId, '68', 'something wrong'); | 60 | callbackReport(task.requestId, '68', 'something wrong'); |
58 | return; | 61 | return; |
59 | } | 62 | } |
60 | 63 | ||
61 | logger.info('Got result', {result: result}); | 64 | logger.info('Got result', {result: result}); |
62 | callbackReport(task.requestId, '68', 'got result'); | 65 | callbackReport(task.requestId, '68', 'got result'); |
63 | }); | 66 | }); |
64 | }); | 67 | }); |
65 | } | 68 | } |
66 | 69 | ||
67 | function createSignature(args, password) { | 70 | function createSignature(args, password) { |
68 | var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); | 71 | var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex'); |
69 | 72 | ||
70 | var result = crypto.createHash('sha1').update( | 73 | var result = crypto.createHash('sha1').update( |
71 | args.userName | 74 | args.userName |
72 | + passwordHash | 75 | + passwordHash |
73 | + args.productCode | 76 | + args.productCode |
74 | + args.terminal | 77 | + args.terminal |
75 | + args.transactionType | 78 | + args.transactionType |
76 | + args.billNumber | 79 | + args.billNumber |
77 | + args.amount | 80 | + args.amount |
78 | + args.ref | 81 | + args.ref |
79 | + args.timestamp | 82 | + args.timestamp |
80 | ).digest().toString('hex'); | 83 | ).digest().toString('hex'); |
81 | 84 | ||
82 | return result; | 85 | return result; |
83 | } | 86 | } |
84 | 87 | ||
85 | function createBillNumber(destination) { | 88 | function createBillNumber(destination) { |
86 | return ("0000000000000" + destination).slice(-13); | 89 | return ("0000000000000" + destination).slice(-13); |
87 | } | 90 | } |
88 | 91 | ||
89 | exports.start = start; | 92 | exports.start = start; |
90 | exports.topupRequest = topupRequest; | 93 | exports.topupRequest = topupRequest; |
91 | exports.createSignature = createSignature; | 94 | exports.createSignature = createSignature; |
92 | exports.createBillNumber = createBillNumber; | 95 | exports.createBillNumber = createBillNumber; |
93 | 96 |
test.js
File was created | 1 | var should = require("should"); | |
2 | var partner = require("./partner-kospinjasa"); | ||
3 | |||
4 | describe("#partner-kospinjasa", function() { | ||
5 | it('should return correct billNumber', function() { | ||
6 | partner.createBillNumber('0818').should.equal('0000000000818'); | ||
7 | }); | ||
8 | }); | ||
9 |