2016-10-26 14:36:28 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.services').factory('payproService',
|
2016-10-26 16:09:21 -04:00
|
|
|
function($window, profileService, platformInfo, popupService, gettextCatalog, ongoingProcess, $log) {
|
2016-10-26 14:36:28 -04:00
|
|
|
|
|
|
|
|
var ret = {};
|
|
|
|
|
|
2016-10-26 16:03:20 -04:00
|
|
|
ret.getPayProDetails = function(uri, cb, disableLoader) {
|
2016-10-26 14:36:28 -04:00
|
|
|
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);
|
|
|
|
|
|
2016-10-26 16:03:20 -04:00
|
|
|
if(!disableLoader) {
|
|
|
|
|
ongoingProcess.set('fetchingPayPro', true);
|
|
|
|
|
}
|
2016-10-26 14:36:28 -04:00
|
|
|
|
|
|
|
|
wallet.fetchPayPro({
|
|
|
|
|
payProUrl: uri,
|
|
|
|
|
}, function(err, paypro) {
|
|
|
|
|
|
2016-10-26 16:03:20 -04:00
|
|
|
if(!disableLoader) {
|
|
|
|
|
ongoingProcess.set('fetchingPayPro', false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 14:36:28 -04:00
|
|
|
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;
|
|
|
|
|
});
|