From 6db2d13b7ddb0ec9092052db2669d4108a25a19e Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 7 Jun 2016 15:34:11 -0300 Subject: [PATCH] Adds uuid for BitPay invoice --- src/js/services/amazonService.js | 49 +++++++++++++++++++++++-------- src/js/services/storageService.js | 12 ++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index e0b7ccb3c..001f53f2a 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -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); + }); }); }); }; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index aeaab2e48..b610b61d7 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -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; });