Adds uuid for BitPay invoice

This commit is contained in:
Gustavo Maximiliano Cortez 2016-06-07 15:34:11 -03:00
commit 6db2d13b7d
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
2 changed files with 48 additions and 13 deletions

View file

@ -30,6 +30,25 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
_healthCheckRequest(); _healthCheckRequest();
}; };
var _getUuid = function(cb) {
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
storageService.getAmazonUuid(network, function(err, uuid) {
if (err) {
$log.error(err);
return cb();
}
if (!lodash.isEmpty(uuid)) return cb(uuid);
uuid = 'Copay-' + moment().unix();
storageService.setAmazonUuid(network, uuid, function(err) {
if (err) {
$log.error(err);
return cb();
}
return cb(uuid);
});
});
};
var _healthCheckRequest = function() { var _healthCheckRequest = function() {
$http({ $http({
method: 'GET', method: 'GET',
@ -172,19 +191,23 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
root.createBitPayInvoice = function(data, cb) { root.createBitPayInvoice = function(data, cb) {
var data = { _getUuid(function(uuid) {
price: data.price, if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID');
currency: data.currency, var dataSrc = {
orderId: data.orderId price: data.price,
}; currency: data.currency,
_checkLimit(data.price, function(err) { orderId: data.orderId,
if (err) return cb(err); posData: '{uuid:' + uuid + '}'
$http(_postBitPay('/invoices', data)).then(function(data) { };
$log.info('BitPay Create Invoice: SUCCESS'); _checkLimit(data.price, function(err) {
return cb(null, data.data); if (err) return cb(err);
}, function(data) { $http(_postBitPay('/invoices', dataSrc)).then(function(data) {
$log.error('BitPay Create Invoice: ERROR ' + data.data.error); $log.info('BitPay Create Invoice: SUCCESS');
return cb(data.data.error); return cb(null, data.data);
}, function(data) {
$log.error('BitPay Create Invoice: ERROR ' + data.data.error);
return cb(data.data.error);
});
}); });
}); });
}; };

View file

@ -342,5 +342,17 @@ angular.module('copayApp.services')
storage.remove('amazonLimits-' + network, cb); storage.remove('amazonLimits-' + network, cb);
}; };
root.setAmazonUuid = function(network, uuid, cb) {
storage.set('amazonUuid-' + network, uuid, cb);
};
root.getAmazonUuid = function(network, cb) {
storage.get('amazonUuid-' + network, cb);
};
root.removeAmazonUuid = function(network, cb) {
storage.remove('amazonUuid-' + network, cb);
};
return root; return root;
}); });