move getPayProDetails method to its own service
This commit is contained in:
parent
22d4a92f7d
commit
08711f1f07
2 changed files with 54 additions and 40 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('incomingData', function($log, $state, $window, $timeout, bitcore, profileService, popupService, ongoingProcess, platformInfo, gettextCatalog, $rootScope) {
|
angular.module('copayApp.services').factory('incomingData', function($log, $state, $window, $timeout, bitcore, profileService, popupService, ongoingProcess, platformInfo, gettextCatalog, $rootScope, payproService) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
|
@ -8,6 +8,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
|
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$timeout(function() {
|
||||||
|
root.redir();
|
||||||
|
}, 2000);;
|
||||||
|
|
||||||
root.redir = function(data) {
|
root.redir = function(data) {
|
||||||
$log.debug('Processing incoming data: ' + data);
|
$log.debug('Processing incoming data: ' + data);
|
||||||
|
|
||||||
|
|
@ -47,6 +51,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
}
|
}
|
||||||
|
|
||||||
data = sanitizeUri(data);
|
data = sanitizeUri(data);
|
||||||
|
data = 'https://test.bitpay.com:443/i/YSHFLkxxVAZhQMGFi9Ptq9';
|
||||||
|
|
||||||
// BIP21
|
// BIP21
|
||||||
if (bitcore.URI.isValid(data)) {
|
if (bitcore.URI.isValid(data)) {
|
||||||
|
|
@ -58,7 +63,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
var amount = parsed.amount ? parsed.amount : '';
|
var amount = parsed.amount ? parsed.amount : '';
|
||||||
|
|
||||||
if (parsed.r) {
|
if (parsed.r) {
|
||||||
getPayProDetails(parsed.r, function(err, details) {
|
payproService.getPayProDetails(parsed.r, function(err, details) {
|
||||||
handlePayPro(details);
|
handlePayPro(details);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -77,7 +82,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
// Plain URL
|
// Plain URL
|
||||||
} else if (/^https?:\/\//.test(data)) {
|
} else if (/^https?:\/\//.test(data)) {
|
||||||
|
|
||||||
getPayProDetails(data, function(err, details) {
|
payproService.getPayProDetails(data, function(err, details) {
|
||||||
if(err) {
|
if(err) {
|
||||||
root.showMenu({data: data, type: 'url'});
|
root.showMenu({data: data, type: 'url'});
|
||||||
return;
|
return;
|
||||||
|
|
@ -135,43 +140,6 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPayProDetails(uri, cb) {
|
|
||||||
if (!cb) cb = function() {};
|
|
||||||
|
|
||||||
var wallet = profileService.getWallets({
|
|
||||||
onlyComplete: true
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (!wallet) return cb();
|
|
||||||
|
|
||||||
if (platformInfo.isChromeApp) {
|
|
||||||
popupService.showAlert(gettextCatalog.getString('Payment Protocol not supported on Chrome App'));
|
|
||||||
return cb(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$log.debug('Fetch PayPro Request...', uri);
|
|
||||||
|
|
||||||
ongoingProcess.set('fetchingPayPro', true);
|
|
||||||
|
|
||||||
wallet.fetchPayPro({
|
|
||||||
payProUrl: uri,
|
|
||||||
}, function(err, paypro) {
|
|
||||||
|
|
||||||
ongoingProcess.set('fetchingPayPro', false);
|
|
||||||
if (err) {
|
|
||||||
return cb(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!paypro.verified) {
|
|
||||||
$log.warn('Failed to verify payment protocol signatures');
|
|
||||||
popupService.showAlert(gettextCatalog.getString('Payment Protocol Invalid'));
|
|
||||||
return cb(true);
|
|
||||||
}
|
|
||||||
cb(null, paypro);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function goToAmountPage(toAddress) {
|
function goToAmountPage(toAddress) {
|
||||||
$state.go('tabs.send');
|
$state.go('tabs.send');
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
|
||||||
46
src/js/services/payproService.js
Normal file
46
src/js/services/payproService.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').factory('payproService',
|
||||||
|
function($window, profileService, platformInfo, popupService, gettextCatalog, ongoingProcess, $log, $state) {
|
||||||
|
|
||||||
|
var ret = {};
|
||||||
|
|
||||||
|
ret.getPayProDetails = function(uri, cb) {
|
||||||
|
if (!cb) cb = function() {};
|
||||||
|
|
||||||
|
var wallet = profileService.getWallets({
|
||||||
|
onlyComplete: true
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
if (!wallet) return cb();
|
||||||
|
|
||||||
|
if (platformInfo.isChromeApp) {
|
||||||
|
popupService.showAlert(gettextCatalog.getString('Payment Protocol not supported on Chrome App'));
|
||||||
|
return cb(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$log.debug('Fetch PayPro Request...', uri);
|
||||||
|
|
||||||
|
ongoingProcess.set('fetchingPayPro', true);
|
||||||
|
|
||||||
|
wallet.fetchPayPro({
|
||||||
|
payProUrl: uri,
|
||||||
|
}, function(err, paypro) {
|
||||||
|
|
||||||
|
ongoingProcess.set('fetchingPayPro', false);
|
||||||
|
if (err) {
|
||||||
|
return cb(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!paypro.verified) {
|
||||||
|
$log.warn('Failed to verify payment protocol signatures');
|
||||||
|
popupService.showAlert(gettextCatalog.getString('Payment Protocol Invalid'));
|
||||||
|
return cb(true);
|
||||||
|
}
|
||||||
|
cb(null, paypro);
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue