Commit 240466132b1eb6a670d0f5271b923e9480bbdf95

Authored by Adhidarma Hadiwinoto
1 parent 35d5bfc57e
Exists in master

remove callbackReportWrapper

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

1 var im = require('./im.js') 1 var im = require('./im.js')
2 var YM = require('yahoomessenger'); 2 var YM = require('yahoomessenger');
3 var imAdaptor = require('./adaptor-ym'); 3 var imAdaptor = require('./adaptor-ym');
4 4
5 var config; 5 var config;
6 var aaa; 6 var aaa;
7 var logger; 7 var logger;
8 var callbackReport; 8 var callbackReport;
9 9
10 function onLoginSuccessful() { 10 function onLoginSuccessful() {
11 logger.info('Login successful, resuming aaa communication'); 11 logger.info('Login successful, resuming aaa communication');
12 aaa.resume(); 12 aaa.resume();
13 } 13 }
14 14
15 function onPM(from, msg) { 15 function onPM(from, msg) {
16 16
17 if (!im.isAllowedFrom(from)) { 17 if (!im.isAllowedFrom(from)) {
18 logger.info('Ignoring message from unknown sender', {from: from, msg: msg}); 18 logger.info('Ignoring message from unknown sender', {from: from, msg: msg});
19 return; 19 return;
20 } 20 }
21 21
22 var remoteProduct = im.getRemoteProductFromMessage(msg); 22 var remoteProduct = im.getRemoteProductFromMessage(msg);
23 var destination = im.getDestinationFromMessage(msg); 23 var destination = im.getDestinationFromMessage(msg);
24 24
25 if (!remoteProduct && !destination) { 25 if (!remoteProduct && !destination) {
26 logger.warn('Missing remote product or destination', {remoteProduct: remoteProduct, destination: destination, msg: msg}); 26 logger.warn('Missing remote product or destination', {remoteProduct: remoteProduct, destination: destination, msg: msg});
27 return; 27 return;
28 } 28 }
29 29
30 logger.info('Got report from partner', {remoteProduct: remoteProduct, destination: destination, msg: msg}); 30 logger.info('Got report from partner', {remoteProduct: remoteProduct, destination: destination, msg: msg});
31 im.getTask(remoteProduct, destination, function(err, task) { 31 im.getTask(remoteProduct, destination, function(err, task) {
32 if (err) { 32 if (err) {
33 logger.warn('Error getting relevant task'); 33 logger.warn('Error getting relevant task');
34 return; 34 return;
35 } 35 }
36 36
37 if (!task) { 37 if (!task) {
38 logger.warn('Something wrong, undefined task without error') 38 logger.warn('Something wrong, undefined task without error')
39 return; 39 return;
40 } 40 }
41 41
42 logger.verbose('Got relevant task', {task: task, msg: msg}); 42 logger.verbose('Got relevant task', {task: task, msg: msg});
43 var rc = im.getRcFromMessage(msg); 43 var rc = im.getRcFromMessage(msg);
44 if (rc == '00') { 44 if (rc == '00') {
45 var sn = im.getSnFromMessage(msg); 45 var sn = im.getSnFromMessage(msg);
46 if (sn) { 46 if (sn) {
47 msg = 'SN=' + sn + ';' + msg; 47 msg = 'SN=' + sn + ';' + msg;
48 } 48 }
49 } 49 }
50 50
51 if (['00', '55', '68'].indexOf(rc) == -1) { 51 if (['00', '55', '68'].indexOf(rc) == -1) {
52 im.deleteTask(remoteProduct, destination); 52 im.deleteTask(remoteProduct, destination);
53 } 53 }
54 54
55 if (rc != '68') { 55 if (rc != '68') {
56 im.cancelResendDelay(task); 56 im.cancelResendDelay(task);
57 } 57 }
58 58
59 callbackReportWrapper(task.requestId, rc, msg); 59 callbackReport(task.requestId, rc, msg);
60 }); 60 });
61 } 61 }
62 62
63 function start(options) { 63 function start(options) {
64 if (options && options.config) { 64 if (options && options.config) {
65 config = options.config; 65 config = options.config;
66 } else { 66 } else {
67 console.log('Unknown options.config'); 67 console.log('Unknown options.config');
68 process.exit('1'); 68 process.exit('1');
69 } 69 }
70 70
71 if (options && options.aaa) { 71 if (options && options.aaa) {
72 aaa = options.aaa; 72 aaa = options.aaa;
73 } 73 }
74 74
75 if (options && options.aaa && options.aaa.callbackReport) { 75 if (options && options.aaa && options.aaa.callbackReport) {
76 callbackReport = options.aaa.callbackReport; 76 callbackReport = options.aaa.callbackReport;
77 } else { 77 } else {
78 console.log('Unknown options.aaa.callbackReport') 78 console.log('Unknown options.aaa.callbackReport')
79 process.exit(2); 79 process.exit(2);
80 } 80 }
81 81
82 if (options && options.logger) { 82 if (options && options.logger) {
83 logger = options.logger; 83 logger = options.logger;
84 } else { 84 } else {
85 logger = new winston.Logger({ 85 logger = new winston.Logger({
86 transports: [ 86 transports: [
87 new (winston.transports.Console)() 87 new (winston.transports.Console)()
88 ] 88 ]
89 }); 89 });
90 } 90 }
91 91
92 var callbacks = { 92 var callbacks = {
93 onLoginSuccessful: onLoginSuccessful, 93 onLoginSuccessful: onLoginSuccessful,
94 onPM: onPM, 94 onPM: onPM,
95 } 95 }
96 96
97 im.init(options); 97 im.init(options);
98 imAdaptor.init(config.h2h_out.ym_id, config.h2h_out.ym_password, logger, callbacks); 98 imAdaptor.init(config.h2h_out.ym_id, config.h2h_out.ym_password, logger, callbacks);
99 } 99 }
100 100
101 function onSameDayDupe(task, archivedTask) { 101 function onSameDayDupe(task, archivedTask) {
102 if (task.requestId == archivedTask.requestId) { 102 if (task.requestId == archivedTask.requestId) {
103 logger.info('Mengulang trx untuk advice', {task: task}); 103 logger.info('Mengulang trx untuk advice', {task: task});
104 _topupRequest(task); 104 _topupRequest(task);
105 } else { 105 } else {
106 logger.info('Terdeteksi trx sama dalam satu hari yang sama', {task: task}); 106 logger.info('Terdeteksi trx sama dalam satu hari yang sama', {task: task});
107 callbackReport(task.requestId, '55', 'Terdeteksi trx sama dalam satu hari yang sama'); 107 callbackReport(task.requestId, '55', 'Terdeteksi trx sama dalam satu hari yang sama');
108 } 108 }
109 } 109 }
110 110
111 function _topupRequest(task) { 111 function _topupRequest(task) {
112 var pattern = config.h2h_out.request_pattern; 112 var pattern = config.h2h_out.request_pattern;
113 113
114 var keywords = { 114 var keywords = {
115 remoteProduct: task.remoteProduct, 115 remoteProduct: task.remoteProduct,
116 destination: task.destination, 116 destination: task.destination,
117 pin: config.h2h_out.pin 117 pin: config.h2h_out.pin
118 } 118 }
119 119
120 im.saveTask(task, function() { 120 im.saveTask(task, function() {
121 im.registerResendDelay(task); 121 im.registerResendDelay(task);
122 122
123 var msg = im.createMessage(pattern, keywords); 123 var msg = im.createMessage(pattern, keywords);
124 imAdaptor.sendMessage(config.h2h_out.partner, msg); 124 imAdaptor.sendMessage(config.h2h_out.partner, msg);
125 }); 125 });
126 126
127 } 127 }
128 128
129 function topupRequest(task) { 129 function topupRequest(task) {
130 if (!aaa.isTodayTrx(task)) { 130 if (!aaa.isTodayTrx(task)) {
131 logger.warn('Maaf, transaksi beda hari tidak dapat dilakukan'); 131 logger.warn('Maaf, transaksi beda hari tidak dapat dilakukan');
132 callbackReport(task.requestId, '68', 'Maaf, transaksi beda hari tidak dapat dilakukan'); 132 callbackReport(task.requestId, '68', 'Maaf, transaksi beda hari tidak dapat dilakukan');
133 im.cancelResendDelay(task); 133 im.cancelResendDelay(task);
134 return; 134 return;
135 } 135 }
136 136
137 im.checkForSameDayDuplicate(task, _topupRequest, onSameDayDupe, _topupRequest); 137 im.checkForSameDayDuplicate(task, _topupRequest, onSameDayDupe, _topupRequest);
138 } 138 }
139 139
140 exports.start = start; 140 exports.start = start;
141 exports.topupRequest = topupRequest; 141 exports.topupRequest = topupRequest;
142 142