Adds uuid for BitPay invoice

This commit is contained in:
Gustavo Maximiliano Cortez 2016-06-07 15:34:11 -03:00
parent 70ded721bf
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();
};
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() {
$http({
method: 'GET',
@ -172,19 +191,23 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
};
root.createBitPayInvoice = function(data, cb) {
var data = {
price: data.price,
currency: data.currency,
orderId: data.orderId
};
_checkLimit(data.price, function(err) {
if (err) return cb(err);
$http(_postBitPay('/invoices', data)).then(function(data) {
$log.info('BitPay Create Invoice: SUCCESS');
return cb(null, data.data);
}, function(data) {
$log.error('BitPay Create Invoice: ERROR ' + data.data.error);
return cb(data.data.error);
_getUuid(function(uuid) {
if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID');
var dataSrc = {
price: data.price,
currency: data.currency,
orderId: data.orderId,
posData: '{uuid:' + uuid + '}'
};
_checkLimit(data.price, function(err) {
if (err) return cb(err);
$http(_postBitPay('/invoices', dataSrc)).then(function(data) {
$log.info('BitPay Create Invoice: SUCCESS');
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);
};
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;
});