Commit 422b88762a1a3dce4032e3dd9b4e029e946eb133

Authored by Adhidarma Hadiwinoto
1 parent 6ec424b07d
Exists in master

topupCheck

Showing 1 changed file with 63 additions and 5 deletions Side-by-side Diff

partner-bayarkilat.js
... ... @@ -8,6 +8,9 @@ var aaa;
8 8 var callbackReport;
9 9 var logger;
10 10  
  11 +var maxCheckRetry = 20;
  12 +var delayBeforeCheckRetry = 30 * 1000;
  13 +
11 14 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
12 15  
13 16 function start(_config, _callbackReport, options) {
... ... @@ -29,21 +32,27 @@ function start(_config, _callbackReport, options) {
29 32 }
30 33 }
31 34  
32   -
33   -function topupRequest(task, retry) {
34   - aaa.insertTaskToMongoDb(task);
  35 +function createRequestOptions(methodName, task) {
  36 + if (('PURCHASE', 'CHECKING').indexOf(methodName) < 0) {
  37 + return;
  38 + }
35 39  
36 40 var partnerUrl = url.parse(config.h2h_out.partner);
37 41 var product = prepareRemoteProductCode(task.remoteProduct);
38 42  
  43 + var destination = task.destination;
  44 + if (methodName == 'CHECKING') {
  45 + destination = paddingDestination(destination);
  46 + }
  47 +
39 48 var options = {
40 49 url: config.h2h_out.partner,
41 50 qs: {
42   - request: 'PURCHASE*'
  51 + request: methodName + '*'
43 52 + task.requestId + '*'
44 53 + product.product + '*'
45 54 + product.productDetail + '*'
46   - + task.destination + '*'
  55 + + destination + '*'
47 56 + product.nominal + '*'
48 57 + '0*'
49 58 + config.h2h_out.noid + '*'
... ... @@ -52,6 +61,41 @@ function topupRequest(task, retry) {
52 61 }
53 62 };
54 63  
  64 + return options;
  65 +}
  66 +
  67 +function topupCheck(task, retry) {
  68 + if (retry === null || retry === undefined) {
  69 + retry = maxCheckRetry + 1;
  70 + }
  71 +
  72 + retry = retry - 1;
  73 +
  74 + if (retry < 0) {
  75 + var message = 'Max retry check transaction retry exceeded';
  76 + var response = {
  77 + raw: message,
  78 + parsed: {
  79 + MESSAGE: message
  80 + }
  81 + }
  82 + aaa.pushResponseToMongoDb(task, response, '68');
  83 + callbackReport(task.requestId, '68', message);
  84 + return;
  85 + }
  86 +
  87 + requestToPartner('CHECKING', task, retry);
  88 +}
  89 +
  90 +function topupRequest(task) {
  91 + requestToPartner('PURCHASE', task);
  92 +}
  93 +
  94 +function requestToPartner(methodName, task, retry) {
  95 + aaa.insertTaskToMongoDb(task);
  96 +
  97 + var options = createRequestOptions(methodName, task);
  98 +
55 99 logger.info('Requesting to partner', {requestOption: options});
56 100 request(options, function(error, response, body) {
57 101 if (error) {
... ... @@ -67,6 +111,13 @@ function topupRequest(task, retry) {
67 111 }
68 112 aaa.pushResponseToMongoDb(task, _response, '68');
69 113  
  114 + setTimeout(
  115 + topupCheck,
  116 + delayBeforeCheckRetry,
  117 + task,
  118 + retry
  119 + );
  120 +
70 121 return;
71 122 }
72 123  
... ... @@ -86,6 +137,13 @@ function topupRequest(task, retry) {
86 137 }
87 138 aaa.pushResponseToMongoDb(task, _response, '68');
88 139  
  140 + setTimeout(
  141 + topupCheck,
  142 + delayBeforeCheckRetry,
  143 + task,
  144 + retry
  145 + );
  146 +
89 147 return;
90 148 }
91 149