Commit 5a947e4006be36b51e8d5373e45066f7982ce0fc

Authored by Adhidarma Hadiwinoto
1 parent 1f837fd31a
Exists in master

siap coba dapat result

Showing 2 changed files with 51 additions and 6 deletions Side-by-side Diff

... ... @@ -25,5 +25,9 @@
25 25 "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git",
26 26 "soap": "^0.15.0",
27 27 "winston": "^2.2.0"
  28 + },
  29 + "devDependencies": {
  30 + "mocha": "^2.4.5",
  31 + "should": "^8.3.2"
28 32 }
29 33 }
partner-kospinjasa.js
1 1 var winston = require('winston');
2 2 var soap = require('soap');
  3 +var crypto = require('crypto');
  4 +var strftime = require('strftime');
3 5  
4 6 var max_retry = 10;
5 7 var sleep_before_retry = 5000;
... ... @@ -34,18 +36,57 @@ function topupRequest(task, retry) {
34 36 retry = max_retry;
35 37 }
36 38  
  39 + var remoteProduct = task.remoteProduct.split(',');
  40 +
37 41 soap.createClient(url, function(err, client) {
38   - client.MyFunction(args, function(err, result) {
39   - console.log(result);
  42 + var args = {
  43 + userName: config.h2h_out.userid,
  44 + productCode: remoteProduct[0] ,
  45 + terminal: 'terminal0',
  46 + transactionType: '50',
  47 + billNumber: createBillNumber(task.destination),
  48 + amount: remoteProduct[1],
  49 + bit61: createBillNumber(task.destination),
  50 + reff: task.requestId,
  51 + timeStamp: strftime('%d-%m-%Y %H:%M:%S', new Date());
  52 + }
  53 +
  54 + client.billpayment(args, function(err, result) {
  55 + if (err) {
  56 + logger.warn('Error requesting service', {err: err});
  57 + callbackReport(task.requestId, '68', 'something wrong');
  58 + return;
  59 + }
  60 +
  61 + logger.info('Got result', {result: result});
  62 + callbackReport(task.requestId, '68', 'got result');
40 63 });
41 64 });
42 65 }
43 66  
44   -function createSoapClient(url, callback) {
45   - soap.createClient(url, function(err, client) {
46   - callback(err, client);
47   - });
  67 +function createSignature(args, password) {
  68 + var passwordHash = crypto.createHash('sha256').update(password).digest().toString('hex');
  69 +
  70 + var result = crypto.createHash('sha1').update(
  71 + args.userName
  72 + + passwordHash
  73 + + args.productCode
  74 + + args.terminal
  75 + + args.transactionType
  76 + + args.billNumber
  77 + + args.amount
  78 + + args.ref
  79 + + args.timestamp
  80 + ).digest().toString('hex');
  81 +
  82 + return result;
  83 +}
  84 +
  85 +function createBillNumber(destination) {
  86 + return ("0000000000000" + destination).slice(-13);
48 87 }
49 88  
50 89 exports.start = start;
51 90 exports.topupRequest = topupRequest;
  91 +exports.createSignature = createSignature;
  92 +exports.createBillNumber = createBillNumber;