From a246475168a4428796a6c4f0efcfbd9a87a2b896 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <gua@adhisimon.org>
Date: Thu, 19 Apr 2018 18:13:23 +0700
Subject: [PATCH] config.force_all_to_pending

---
 config.sample.json |  3 ++-
 lib/partner.js     | 21 ++++++++++++++-------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/config.sample.json b/config.sample.json
index 08e13f7..146ee5c 100644
--- a/config.sample.json
+++ b/config.sample.json
@@ -25,5 +25,6 @@
     "control_panel": {
         "listen_port": 27441
     },
-    "do_not_verbose_log_report": true
+    "do_not_verbose_log_report": true,
+    "force_all_to_pending": false
 }
diff --git a/lib/partner.js b/lib/partner.js
index 1d5afbd..7176da7 100644
--- a/lib/partner.js
+++ b/lib/partner.js
@@ -12,6 +12,7 @@ const config = require('komodo-sdk/config');
 const logger = require('komodo-sdk/logger');
 const matrix = require('komodo-sdk/matrix');
 const pull = require('komodo-sdk/gateway/pull');
+const resendDelay = require('komodo-sdk/gateway/resend-delay');
 
 const st24 = require('./st24');
 
@@ -80,13 +81,6 @@ function _topUpRequest(task, isAdvice) {
                 }
             });
 
-            if (rc === '68') {
-                setTimeout(
-                    function() { advice(task); },
-                    5 * 60 * 1000
-                );
-            }
-
             return;
         }
 
@@ -180,8 +174,21 @@ function report(data) {
         return;
     }
 
+    if (config && config.force_all_to_pending) {
+        data.rc = '68';
+    }
+
     matrix.last_report_to_core = data;
     pull.report(data);
+
+    if (!resendDelay.isEnabled()) return;
+
+    if (data.task && data.rc && data.rc === '68') {
+        resendDelay.register(data.task, advice);
+    }
+    else {
+        resendDelay.cancel(data.trx_id);
+    }
 }
 
 exports.buy = buy;
-- 
1.9.0