});
};
- Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, requestSeconds, cb) {
+ Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, requestSeconds, cb, cbStatus) {
var self = this, _reqData = {};
if (!this.webOTT) {
return cb({code: Errors.wrongFlow.code, type: Errors.wrongFlow.type, message: "Need to call getAccessNumber method before this."}, null);
return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing timeout/expiration period(in seconds)."}, null);
}
+ self.mobileStatus = self.mobileStatus || '';
if (typeof this.timeoutPeriod === "undefined") {
this.timeoutPeriod = timeoutSeconds * 1000;
this.request(_reqData, function (err, data) {
var _requestPeriod;
+
if (err) {
- if (err.status === 401 && self.timeoutPeriod > 0) {
- _requestPeriod = requestSeconds ? requestSeconds * 1000 : 3000;
- self.timeoutPeriod -= _requestPeriod;
-
- self.intervalID2 = setTimeout(function () {
- self.waitForMobileAuth.call(self, timeoutSeconds, requestSeconds, cb);
- }, _requestPeriod);
- return;
- } else if (self.timeoutPeriod <= 0) {
- delete self.timeoutPeriod;
- cb && cb(Errors.timeoutFinish, null);
- return;
- }
+ cb && cb(err, null);
} else {
- self._authenticate({mpinResponse: data}, cb);
+ authOTT = data.authOTT
+ delete data.authOTT
+
+ if(data.status === 'authenticate') {
+ cbStatus && cbStatus(data);
+ self._authenticate({mpinResponse: {authOTT: authOTT}}, cb);
+ } else {
+ if (self.timeoutPeriod > 0) {
+ _requestPeriod = requestSeconds ? requestSeconds * 1000 : 3000;
+ self.timeoutPeriod -= _requestPeriod;
+ if (data.status !== self.mobileStatus) {
+ self.mobileStatus = data.status;
+ cbStatus && cbStatus(data);
+ }
+ self.intervalID2 = setTimeout(function () {
+ self.waitForMobileAuth.call(self, timeoutSeconds, requestSeconds, cb, cbStatus);
+ }, _requestPeriod);
+ return;
+ } else if (self.timeoutPeriod <= 0) {
+ delete self.timeoutPeriod;
+ cb && cb(Errors.timeoutFinish, null);
+ return;
+ }
+ }
}
});
};