Adds uuid for BitPay invoice
This commit is contained in:
parent
70ded721bf
commit
6db2d13b7d
2 changed files with 48 additions and 13 deletions
|
|
@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue