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
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