From 1d1b632886f5f73d31417083df3db53932d741ed Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 28 Nov 2016 17:01:07 -0300 Subject: [PATCH 1/6] New send flow for the Amazon integration --- src/js/controllers/amazon.js | 17 +++++- src/js/controllers/amount.js | 53 +++++++++++++++++- src/js/controllers/confirm.js | 84 +++++++++++++++++++++++++++- src/js/routes.js | 30 ++++++++++ src/js/services/bitpayCardService.js | 2 +- src/sass/views/amount.scss | 3 + src/sass/views/confirm.scss | 3 + www/views/amazon.html | 3 +- www/views/amount.html | 7 ++- www/views/confirm.html | 5 +- 10 files changed, 197 insertions(+), 10 deletions(-) diff --git a/src/js/controllers/amazon.js b/src/js/controllers/amazon.js index 6bc4a4108..9e1787f57 100644 --- a/src/js/controllers/amazon.js +++ b/src/js/controllers/amazon.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('amazonController', - function($scope, $timeout, $ionicModal, $log, lodash, bwcError, amazonService, platformInfo, externalLinkService, popupService) { + function($scope, $timeout, $ionicModal, $log, lodash, amazonService, platformInfo, externalLinkService, popupService, gettextCatalog) { $scope.network = amazonService.getEnvironment(); @@ -19,6 +19,14 @@ angular.module('copayApp.controllers').controller('amazonController', $timeout(function() { $scope.$digest(); }); + if ($scope.cardClaimCode) { + var card = lodash.find($scope.giftCards, { claimCode: $scope.cardClaimCode }); + if (lodash.isEmpty(card)) { + popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Card not found')); + return; + } + $scope.openCardModal(card); + } }); $scope.updatePendingGiftCards(); }; @@ -26,12 +34,16 @@ angular.module('copayApp.controllers').controller('amazonController', $scope.updatePendingGiftCards = lodash.debounce(function() { amazonService.getPendingGiftCards(function(err, gcds) { + $timeout(function() { + $scope.giftCards = gcds; + $scope.$digest(); + }); lodash.forEach(gcds, function(dataFromStorage) { if (dataFromStorage.status == 'PENDING') { $log.debug("creating gift card"); amazonService.createGiftCard(dataFromStorage, function(err, giftCard) { if (err) { - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); + popupService.showAlert(gettextCatalog.getString('Error'), err); return; } if (giftCard.status != 'PENDING') { @@ -84,6 +96,7 @@ angular.module('copayApp.controllers').controller('amazonController', }; $scope.$on("$ionicView.beforeEnter", function(event, data) { + $scope.cardClaimCode = data.stateParams.cardClaimCode; initAmazon(); }); }); diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 73c53515d..589269b27 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService) { +angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, amazonService) { var unitToSatoshi; var satToUnit; @@ -16,17 +16,18 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.$on("$ionicView.beforeEnter", function(event, data) { + $scope.buyAmazon = data.stateParams.buyAmazon; $scope.isWallet = data.stateParams.isWallet; $scope.cardId = data.stateParams.cardId; $scope.toAddress = data.stateParams.toAddress; $scope.toName = data.stateParams.toName; $scope.toEmail = data.stateParams.toEmail; - $scope.showAlternativeAmount = !!$scope.cardId; + $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.buyAmazon; $scope.toColor = data.stateParams.toColor; $scope.customAmount = data.stateParams.customAmount; - if (!$scope.cardId && !data.stateParams.toAddress) { + if (!$scope.cardId && !$scope.buyAmazon && !data.stateParams.toAddress) { $log.error('Bad params at amount') throw ('bad params'); } @@ -201,6 +202,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ amount: amountUSD, currency: 'USD' }; + ongoingProcess.set('Preparing transaction...', true); $timeout(function() { @@ -240,6 +242,51 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); }); + } else if ($scope.buyAmazon) { + ongoingProcess.set('Preparing transaction...', true); + var amountUSD = $scope.showAlternativeAmount ? _amount : $filter('formatFiatAmount')(toFiat(_amount)); + var dataSrc = { + currency: 'USD', + amount: amountUSD, + uuid: moment().unix() * 1000 + }; + + amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) { + if (err) { + ongoingProcess.set('Preparing transaction...', false); + popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); + return; + } + + amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) { + if (err) { + popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); + return; + } + + var payProUrl = invoice.paymentUrls.BIP73; + + payproService.getPayProDetails(payProUrl, function(err, payProDetails) { + ongoingProcess.set('Preparing transaction...', false); + if (err) { + popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); + return; + } + var stateParams = { + giftAmountUSD: amountUSD, + giftAccessKey: dataInvoice.accessKey, + giftInvoiceTime: invoice.invoiceTime, + giftUUID: dataSrc.uuid, + toAmount: payProDetails.amount, + toAddress: payProDetails.toAddress, + description: payProDetails.memo, + paypro: payProDetails + }; + + $state.transitionTo('tabs.giftcards.amazon.confirm', stateParams); + }, true); + }); + }); } else { var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount; if ($scope.customAmount) { diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 3c8ac591d..386934ee8 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService) { +angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, amazonService) { var cachedTxp = {}; var isChromeApp = platformInfo.isChromeApp; var countDown = null; @@ -8,6 +8,11 @@ angular.module('copayApp.controllers').controller('confirmController', function( $ionicConfig.views.swipeBackEnabled(false); $scope.$on("$ionicView.beforeEnter", function(event, data) { + $scope.buyAmazon = data.stateParams.buyAmazon; + $scope.giftAmountUSD = data.stateParams.giftAmountUSD; + $scope.giftAccessKey = data.stateParams.giftAccessKey; + $scope.giftInvoiceTime = data.stateParams.giftInvoiceTime; + $scope.giftUUID = data.stateParams.giftUUID; $scope.isWallet = data.stateParams.isWallet; $scope.cardId = data.stateParams.cardId; $scope.toAmount = data.stateParams.toAmount; @@ -373,6 +378,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.onSuccessConfirm = function() { var previousView = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName; var fromBitPayCard = previousView.match(/tabs.bitpayCard/) ? true : false; + var fromAmazon = previousView.match(/tabs.giftcards.amazon/) ? true : false; $ionicHistory.nextViewOptions({ disableAnimate: true @@ -386,6 +392,17 @@ angular.module('copayApp.controllers').controller('confirmController', function( id: $stateParams.cardId }); }, 100); + } else if (fromAmazon) { + $ionicHistory.nextViewOptions({ + disableAnimate: true, + historyRoot: true + }); + $ionicHistory.clearHistory(); + $state.go('tabs.home').then(function() { + $state.transitionTo('tabs.giftcards.amazon', { + cardClaimCode: $scope.amazonGiftCard ? $scope.amazonGiftCard.claimCode : null + }); + }); } else { $state.go('tabs.send'); } @@ -394,6 +411,71 @@ angular.module('copayApp.controllers').controller('confirmController', function( function publishAndSign(wallet, txp, onSendStatusChange) { walletService.publishAndSign(wallet, txp, function(err, txp) { if (err) return setSendError(err); + + var previousView = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName; + var fromAmazon = previousView.match(/tabs.giftcards.amazon/) ? true : false; + if (fromAmazon) { + var count = 0; + var invoiceId = JSON.parse($scope.paypro.merchant_data).invoiceId; + var dataSrc = { + currency: 'USD', + amount: $scope.giftAmountUSD, + uuid: $scope.giftUUID, + accessKey: $scope.giftAccessKey, + invoiceId: invoiceId, + invoiceUrl: $scope.paypro.url, + invoiceTime: $scope.giftInvoiceTime + }; + debounceCreate(count, dataSrc, onSendStatusChange); + } }, onSendStatusChange); } + + var debounceCreate = lodash.throttle(function(count, dataSrc) { + debounceCreateGiftCard(count, dataSrc); + }, 8000, { + 'leading': true + }); + + var debounceCreateGiftCard = function(count, dataSrc, onSendStatusChange) { + + amazonService.createGiftCard(dataSrc, function(err, giftCard) { + $log.debug("creating gift card " + count); + if (err) { + giftCard = {}; + giftCard.status = 'FAILURE'; + popupService.showAlert(gettextCatalog.getString('Error'), err); + } + + if (giftCard.status == 'PENDING' && count < 3) { + $log.debug("pending gift card not available yet"); + debounceCreate(count + 1, dataSrc); + return; + } + + var now = moment().unix() * 1000; + + var newData = giftCard; + newData['invoiceId'] = dataSrc.invoiceId; + newData['accessKey'] = dataSrc.accessKey; + newData['invoiceUrl'] = dataSrc.invoiceUrl; + newData['amount'] = dataSrc.amount; + newData['date'] = dataSrc.invoiceTime || now; + newData['uuid'] = dataSrc.uuid; + + if (newData.status == 'expired') { + amazonService.savePendingGiftCard(newData, { + remove: true + }, function(err) { + $log.error(err); + return; + }); + } + + amazonService.savePendingGiftCard(newData, null, function(err) { + $log.debug("Saving new gift card with status: " + newData.status); + $scope.amazonGiftCard = newData; + }); + }); + }; }); diff --git a/src/js/routes.js b/src/js/routes.js index 6aa16fa48..43c3c4fc4 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -965,6 +965,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr controller: 'amazonController', templateUrl: 'views/amazon.html' } + }, + params: { + cardClaimCode: null } }) .state('tabs.giftcards.amazon.buy', { @@ -977,6 +980,33 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } } }) + .state('tabs.giftcards.amazon.amount', { + url: '/amount', + views: { + 'tab-home@tabs': { + controller: 'amountController', + templateUrl: 'views/amount.html' + } + }, + params: { + buyAmazon: true, + toName: 'Amazon.com Gift Card' + } + }) + .state('tabs.giftcards.amazon.confirm', { + url: '/confirm/:toAmount/:toAddress/:description/:giftAmountUSD/:giftAccessKey/:giftInvoiceTime/:giftUUID', + views: { + 'tab-home@tabs': { + controller: 'confirmController', + templateUrl: 'views/confirm.html' + } + }, + params: { + buyAmazon: true, + toName: 'Amazon.com Gift Card', + paypro: null + } + }) /* * diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index 1d6d52983..656078fd7 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -136,7 +136,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; root.bitAuthPair = function(obj, cb) { - var deviceName = 'Unknow device'; + var deviceName = 'Unknown device'; if (platformInfo.isNW) { deviceName = require('os').platform(); } else if (platformInfo.isCordova) { diff --git a/src/sass/views/amount.scss b/src/sass/views/amount.scss index 0933f08ad..7c4c1681e 100644 --- a/src/sass/views/amount.scss +++ b/src/sass/views/amount.scss @@ -11,6 +11,9 @@ .icon-bitpay-card { background-image: url("../img/icon-bitpay.svg"); } + .icon-amazon { + background-image: url("../img/icon-amazon.svg"); + } @media(max-width: 480px) { .bitcoin-address { .icon { diff --git a/src/sass/views/confirm.scss b/src/sass/views/confirm.scss index 4f6cbc0af..2372290ce 100644 --- a/src/sass/views/confirm.scss +++ b/src/sass/views/confirm.scss @@ -1,5 +1,8 @@ #view-confirm { @extend .deflash-blue; + .icon-amazon { + background-image: url("../img/icon-amazon.svg"); + } .tx-details-content > .scroll { padding-bottom: .25rem; } diff --git a/www/views/amazon.html b/www/views/amazon.html index 8e17d5559..f3f45af49 100644 --- a/www/views/amazon.html +++ b/www/views/amazon.html @@ -30,7 +30,8 @@
diff --git a/www/views/confirm.html b/www/views/confirm.html index 500a79671..e84ed5b93 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -28,8 +28,11 @@
To - + + +
+
From 1af5d2a0fc8c594e815dfb92142c5546e2b6b123 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 29 Nov 2016 10:50:48 -0300 Subject: [PATCH 2/6] Uses walletID as UUID. Fix buy now link --- src/js/controllers/amount.js | 15 +++++++++++++-- www/views/amazon.html | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 589269b27..4ff6ada67 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, amazonService) { +angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, amazonService, profileService) { var unitToSatoshi; var satToUnit; @@ -244,11 +244,22 @@ angular.module('copayApp.controllers').controller('amountController', function($ } else if ($scope.buyAmazon) { ongoingProcess.set('Preparing transaction...', true); + // Get first wallet as UUID + var uuid; + try { + uuid = profileService.getWallets({ + onlyComplete: true, + network: 'livenet', + })[0].id; + } catch(err) { + popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('No wallet found!')); + return; + }; var amountUSD = $scope.showAlternativeAmount ? _amount : $filter('formatFiatAmount')(toFiat(_amount)); var dataSrc = { currency: 'USD', amount: amountUSD, - uuid: moment().unix() * 1000 + uuid: uuid }; amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) { diff --git a/www/views/amazon.html b/www/views/amazon.html index f3f45af49..444046cda 100644 --- a/www/views/amazon.html +++ b/www/views/amazon.html @@ -18,7 +18,7 @@
- From 3c987bcf99709d6890ed59798a23de6c3ced453d Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 29 Nov 2016 12:07:02 -0300 Subject: [PATCH 3/6] Adds limit note --- www/views/amount.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/www/views/amount.html b/www/views/amount.html index 36611acee..a19348795 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -33,8 +33,11 @@
-
-
Amount
+
+
+ Amount + (Purchase Amount is limited to USD 500 per day) +
From e7de57f6302807bad1143f38fc583d60de24e7b3 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 29 Nov 2016 12:08:54 -0300 Subject: [PATCH 4/6] Removes unused files --- src/js/controllers/buyAmazon.js | 224 -------------------------------- www/views/buyAmazon.html | 154 ---------------------- 2 files changed, 378 deletions(-) delete mode 100644 src/js/controllers/buyAmazon.js delete mode 100644 www/views/buyAmazon.html diff --git a/src/js/controllers/buyAmazon.js b/src/js/controllers/buyAmazon.js deleted file mode 100644 index ca2aede91..000000000 --- a/src/js/controllers/buyAmazon.js +++ /dev/null @@ -1,224 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('buyAmazonController', - function($scope, $log, $timeout, $state, lodash, profileService, bwcError, gettextCatalog, configService, walletService, amazonService, ongoingProcess, platformInfo, externalLinkService, popupService) { - - var self = this; - var network = amazonService.getEnvironment(); - var wallet; - - $scope.$on('Wallet/Changed', function(event, w) { - if (lodash.isEmpty(w)) { - $log.debug('No wallet provided'); - return; - } - wallet = w; - $log.debug('Wallet changed: ' + w.name); - }); - - $scope.openExternalLink = function(url, optIn, title, message, okText, cancelText) { - externalLinkService.open(url, optIn, title, message, okText, cancelText); - }; - - this.confirm = function() { - var message = gettextCatalog.getString('Amazon.com Gift Card purchase for ${{amount}} USD', { - amount: $scope.formData.fiat - }); - var ok = gettextCatalog.getString('Buy'); - popupService.showConfirm(null, message, ok, null, function(res) { - if (res) self.createTx(); - }); - }; - - this.createTx = function() { - self.errorInfo = null; - - if (lodash.isEmpty(wallet)) return; - - if (!wallet.canSign() && !wallet.isPrivKeyExternal()) { - $log.info('No signing proposal: No private key'); - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg('MISSING_PRIVATE_KEY')); - return; - } - - var dataSrc = { - currency: 'USD', - amount: $scope.formData.fiat, - uuid: wallet.id - }; - var outputs = []; - var config = configService.getSync(); - var configWallet = config.wallet; - var walletSettings = configWallet.settings; - - - ongoingProcess.set('Processing Transaction...', true); - $timeout(function() { - amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) { - if (err) { - ongoingProcess.set('Processing Transaction...', false); - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); - return; - } - - amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) { - if (err) { - ongoingProcess.set('Processing Transaction...', false); - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); - return; - } - - $log.debug('Fetch PayPro Request...', invoice.paymentUrls.BIP73); - - wallet.fetchPayPro({ - payProUrl: invoice.paymentUrls.BIP73, - }, function(err, paypro) { - - if (err) { - ongoingProcess.set('Processing Transaction...', false); - $log.warn('Could not fetch payment request:', err); - var msg = err.toString(); - if (msg.match('HTTP')) { - msg = gettextCatalog.getString('Could not fetch payment information'); - } - popupService.showAlert(gettextCatalog.getString('Error'), msg); - return; - } - - if (!paypro.verified) { - ongoingProcess.set('Processing Transaction...', false); - $log.warn('Failed to verify payment protocol signatures'); - popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Payment Protocol Invalid')); - $timeout(function() { - $scope.$digest(); - }); - return; - } - - var address, comment, amount, url; - - address = paypro.toAddress; - amount = paypro.amount; - url = paypro.url; - comment = 'Amazon.com Gift Card'; - - outputs.push({ - 'toAddress': address, - 'amount': amount, - 'message': comment - }); - - var txp = { - toAddress: address, - amount: amount, - outputs: outputs, - message: comment, - payProUrl: url, - excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true, - feeLevel: walletSettings.feeLevel || 'normal' - }; - - walletService.createTx(wallet, txp, function(err, createdTxp) { - ongoingProcess.set('Processing Transaction...', false); - if (err) { - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); - return; - } - walletService.publishAndSign(wallet, createdTxp, function(err, tx) { - if (err) { - ongoingProcess.set('Processing Transaction...', false); - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); - walletService.removeTx(wallet, tx, function(err) { - if (err) $log.debug(err); - }); - $timeout(function() { - $scope.$digest(); - }); - return; - } - var count = 0; - ongoingProcess.set('Processing Transaction...', true); - - dataSrc.accessKey = dataInvoice.accessKey; - dataSrc.invoiceId = invoice.id; - dataSrc.invoiceUrl = invoice.url; - dataSrc.invoiceTime = invoice.invoiceTime; - - self.debounceCreate(count, dataSrc); - }); - }); - }); - }); - }); - }, 100); - }; - - self.debounceCreate = lodash.throttle(function(count, dataSrc) { - self.debounceCreateGiftCard(count, dataSrc); - }, 8000, { - 'leading': true - }); - - self.debounceCreateGiftCard = function(count, dataSrc) { - - amazonService.createGiftCard(dataSrc, function(err, giftCard) { - $log.debug("creating gift card " + count); - if (err) { - giftCard = {}; - giftCard.status = 'FAILURE'; - ongoingProcess.set('Processing Transaction...', false); - popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); - self.errorInfo = dataSrc; - $timeout(function() { - $scope.$digest(); - }); - } - - if (giftCard.status == 'PENDING' && count < 3) { - $log.debug("pending gift card not available yet"); - self.debounceCreate(count + 1, dataSrc, dataSrc); - return; - } - - var now = moment().unix() * 1000; - - var newData = giftCard; - newData['invoiceId'] = dataSrc.invoiceId; - newData['accessKey'] = dataSrc.accessKey; - newData['invoiceUrl'] = dataSrc.invoiceUrl; - newData['amount'] = dataSrc.amount; - newData['date'] = dataSrc.invoiceTime || now; - newData['uuid'] = dataSrc.uuid; - - if (newData.status == 'expired') { - amazonService.savePendingGiftCard(newData, { - remove: true - }, function(err) { - return; - }); - } - - amazonService.savePendingGiftCard(newData, null, function(err) { - ongoingProcess.set('Processing Transaction...', false); - $log.debug("Saving new gift card with status: " + newData.status); - - self.giftCard = newData; - if (newData.status == 'PENDING') $state.transitionTo('tabs.giftcards.amazon'); - $timeout(function() { - $scope.$digest(); - }); - }); - }); - }; - - $scope.$on("$ionicView.enter", function(event, data) { - $scope.formData = { - fiat: null - }; - $scope.wallets = profileService.getWallets({ - network: network, - onlyComplete: true - }); - }); - - }); diff --git a/www/views/buyAmazon.html b/www/views/buyAmazon.html deleted file mode 100644 index 69ac4b790..000000000 --- a/www/views/buyAmazon.html +++ /dev/null @@ -1,154 +0,0 @@ - - - - - Buy - - - - - - -
-
-

Gift card could not be created

-
- There was an error when trying to create the Amazon.com Gift Card. Status: {{buy.giftCard.status}} -
-
- - This is a temporary/recoverable system failure that can be - resolved retrying the request from your list of cards - - - This failure could not be recoverable. Request your refund from your list of cards - - -
-
-
-
- Thank you for participating in the BitPay offer. It is our pleasure to send - you this Amazon.com Gift Card* that can be redeemed towards millions of items at - www.amazon.com. - You may want to print this screen for easy reference later you will need the gift card claim code below. -
- -
- Amazon.com Gift Cards -
- Gift Card Amount: - - {{buy.giftCard.amount | currency : '$ ' : 2 }} - -
-
- Claim code: {{buy.giftCard.claimCode}} -
-
- -
- -
-
- To redeem your gift card, follow these steps: - -
    -
  1. 1. Visit www.amazon.com/gc -
  2. 2. Click Apply to Account and enter the Claim Code when prompted. -
  3. 3. Gift card funds will be applied automatically to eligible orders during the checkout process. -
  4. 4. You must pay for any remaining balance on your order with another payment method. -
- -

- Your gift card claim code may also be entered when prompted during checkout. To redeem your gift card using - the Amazon.com 1-Click® service, first add the gift card funds to Your Account. -

- -

- If you have questions about redeeming your gift card, please visit - www.amazon.com/gc-redeem. - If you have questions regarding the BitPay Introductory offer, please contact BitPay. -

- -
-
-
- -
- * Amazon.com is not a sponsor of this promotion. - Except as required by law, Amazon.com - Gift Cards ("GCs") cannot be transferred for value or redeemed for cash. GCs may be used only for purchases of - eligible goods at Amazon.com or certain of its - affiliated websites. For complete terms and conditions, see - www.amazon.com/gc-legal. - GCs are issued by ACI Gift Cards, Inc., a Washington corporation. All Amazon ®, ™ & © are IP - of Amazon.com, Inc. or its affiliates. - No expiration date or service fees. -
- - - From 52308e48bed906f4d6b3869075c2edae21458225 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 29 Nov 2016 12:55:40 -0300 Subject: [PATCH 5/6] Limit to wallet n-1 --- src/js/controllers/confirm.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 386934ee8..39337a823 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -54,6 +54,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( var wallets = profileService.getWallets({ onlyComplete: true, network: networkName, + n: $scope.buyAmazon ? true : false }); if (!wallets || !wallets.length) { From 67a1111c56cca48cc1231bf82958045fe19a06b6 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 29 Nov 2016 21:49:56 -0300 Subject: [PATCH 6/6] Fixes names --- src/js/controllers/amount.js | 16 ++++++++-------- src/js/controllers/confirm.js | 27 +++++++++++++++++---------- src/js/routes.js | 16 +++------------- www/views/amount.html | 6 +++--- www/views/confirm.html | 4 ++-- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 4ff6ada67..4d83a4bd7 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -16,18 +16,18 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.$on("$ionicView.beforeEnter", function(event, data) { - $scope.buyAmazon = data.stateParams.buyAmazon; + $scope.isGiftCard = data.stateParams.isGiftCard; $scope.isWallet = data.stateParams.isWallet; $scope.cardId = data.stateParams.cardId; $scope.toAddress = data.stateParams.toAddress; $scope.toName = data.stateParams.toName; $scope.toEmail = data.stateParams.toEmail; - $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.buyAmazon; + $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard; $scope.toColor = data.stateParams.toColor; $scope.customAmount = data.stateParams.customAmount; - if (!$scope.cardId && !$scope.buyAmazon && !data.stateParams.toAddress) { + if (!$scope.cardId && !$scope.isGiftCard && !data.stateParams.toAddress) { $log.error('Bad params at amount') throw ('bad params'); } @@ -242,7 +242,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); }); - } else if ($scope.buyAmazon) { + } else if ($scope.isGiftCard) { ongoingProcess.set('Preparing transaction...', true); // Get first wallet as UUID var uuid; @@ -284,10 +284,10 @@ angular.module('copayApp.controllers').controller('amountController', function($ return; } var stateParams = { - giftAmountUSD: amountUSD, - giftAccessKey: dataInvoice.accessKey, - giftInvoiceTime: invoice.invoiceTime, - giftUUID: dataSrc.uuid, + giftCardAmountUSD: amountUSD, + giftCardAccessKey: dataInvoice.accessKey, + giftCardInvoiceTime: invoice.invoiceTime, + giftCardUUID: dataSrc.uuid, toAmount: payProDetails.amount, toAddress: payProDetails.toAddress, description: payProDetails.memo, diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 39337a823..4919263d8 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -4,15 +4,22 @@ angular.module('copayApp.controllers').controller('confirmController', function( var cachedTxp = {}; var isChromeApp = platformInfo.isChromeApp; var countDown = null; + var giftCardAmountUSD; + var giftCardAccessKey; + var giftCardInvoiceTime; + var giftCardUUID; $scope.isCordova = platformInfo.isCordova; $ionicConfig.views.swipeBackEnabled(false); $scope.$on("$ionicView.beforeEnter", function(event, data) { - $scope.buyAmazon = data.stateParams.buyAmazon; - $scope.giftAmountUSD = data.stateParams.giftAmountUSD; - $scope.giftAccessKey = data.stateParams.giftAccessKey; - $scope.giftInvoiceTime = data.stateParams.giftInvoiceTime; - $scope.giftUUID = data.stateParams.giftUUID; + + // Amazon.com Gift Card parameters + $scope.isGiftCard = data.stateParams.isGiftCard; + giftCardAmountUSD = data.stateParams.giftCardAmountUSD; + giftCardAccessKey = data.stateParams.giftCardAccessKey; + giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime; + giftCardUUID = data.stateParams.giftCardUUID; + $scope.isWallet = data.stateParams.isWallet; $scope.cardId = data.stateParams.cardId; $scope.toAmount = data.stateParams.toAmount; @@ -54,7 +61,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( var wallets = profileService.getWallets({ onlyComplete: true, network: networkName, - n: $scope.buyAmazon ? true : false + n: $scope.isGiftCard ? true : false }); if (!wallets || !wallets.length) { @@ -420,12 +427,12 @@ angular.module('copayApp.controllers').controller('confirmController', function( var invoiceId = JSON.parse($scope.paypro.merchant_data).invoiceId; var dataSrc = { currency: 'USD', - amount: $scope.giftAmountUSD, - uuid: $scope.giftUUID, - accessKey: $scope.giftAccessKey, + amount: giftCardAmountUSD, + uuid: giftCardUUID, + accessKey: giftCardAccessKey, invoiceId: invoiceId, invoiceUrl: $scope.paypro.url, - invoiceTime: $scope.giftInvoiceTime + invoiceTime: giftCardInvoiceTime }; debounceCreate(count, dataSrc, onSendStatusChange); } diff --git a/src/js/routes.js b/src/js/routes.js index 43c3c4fc4..d86d0c8ab 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -970,16 +970,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr cardClaimCode: null } }) - .state('tabs.giftcards.amazon.buy', { - url: '/buy', - views: { - 'tab-home@tabs': { - controller: 'buyAmazonController', - controllerAs: 'buy', - templateUrl: 'views/buyAmazon.html' - } - } - }) .state('tabs.giftcards.amazon.amount', { url: '/amount', views: { @@ -989,12 +979,12 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }, params: { - buyAmazon: true, + isGiftCard: true, toName: 'Amazon.com Gift Card' } }) .state('tabs.giftcards.amazon.confirm', { - url: '/confirm/:toAmount/:toAddress/:description/:giftAmountUSD/:giftAccessKey/:giftInvoiceTime/:giftUUID', + url: '/confirm/:toAmount/:toAddress/:description/:giftCardAmountUSD/:giftCardAccessKey/:giftCardInvoiceTime/:giftCardUUID', views: { 'tab-home@tabs': { controller: 'confirmController', @@ -1002,7 +992,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }, params: { - buyAmazon: true, + isGiftCard: true, toName: 'Amazon.com Gift Card', paypro: null } diff --git a/www/views/amount.html b/www/views/amount.html index a19348795..6892406a7 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -16,13 +16,13 @@ - +
- +
@@ -36,7 +36,7 @@
Amount - (Purchase Amount is limited to USD 500 per day) + (Purchase Amount is limited to USD 500 per day)
diff --git a/www/views/confirm.html b/www/views/confirm.html index e84ed5b93..85d9006d4 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -28,9 +28,9 @@
To - + - +