amazon integration refactor
This commit is contained in:
parent
42a8176d7c
commit
6dff2840c8
12 changed files with 336 additions and 454 deletions
|
|
@ -1,53 +1,45 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $timeout, amazonService, ongoingProcess) {
|
||||
|
||||
$scope.cancelGiftCard = function() {
|
||||
var dataSrc = {
|
||||
creationRequestId: $scope.card.creationRequestId,
|
||||
gcId: $scope.card.gcId,
|
||||
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
|
||||
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
|
||||
date: $scope.card.date
|
||||
};
|
||||
ongoingProcess.set('Canceling gift card...', true);
|
||||
amazonService.cancelGiftCard(dataSrc, function(err, data) {
|
||||
ongoingProcess.set('Canceling gift card...', false);
|
||||
if (err || data.status != 'SUCCESS') {
|
||||
$scope.error = err || data.status;
|
||||
return;
|
||||
}
|
||||
$scope.refreshGiftCard();
|
||||
});
|
||||
};
|
||||
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, bwcError, amazonService, lodash, ongoingProcess) {
|
||||
|
||||
$scope.remove = function() {
|
||||
amazonService.saveGiftCard($scope.card, {remove: true}, function(err) {
|
||||
amazonService.savePendingGiftCard($scope.card, {
|
||||
remove: true
|
||||
}, function(err) {
|
||||
$scope.$emit('UpdateAmazonList');
|
||||
$scope.cancel();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.refreshGiftCard = function() {
|
||||
var dataSrc = {
|
||||
creationRequestId: $scope.card.creationRequestId,
|
||||
amount: $scope.card.cardInfo.value.amount,
|
||||
currencyCode: $scope.card.cardInfo.value.currencyCode,
|
||||
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
|
||||
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
|
||||
date: $scope.card.date
|
||||
};
|
||||
ongoingProcess.set('Updating gift card...', true);
|
||||
amazonService.createGiftCard(dataSrc, function(err, data) {
|
||||
ongoingProcess.set('Updating gift card...', false);
|
||||
amazonService.getPendingGiftCards(function(err, gcds) {
|
||||
if (err) {
|
||||
$scope.error = err;
|
||||
self.error = err;
|
||||
return;
|
||||
}
|
||||
$scope.$emit('UpdateAmazonList');
|
||||
$scope.card = data;
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
lodash.forEach(gcds, function(dataFromStorage) {
|
||||
if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) {
|
||||
$log.debug("creating gift card");
|
||||
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
|
||||
if (err) {
|
||||
self.error = bwcError.msg(err);
|
||||
$log.debug(bwcError.msg(err));
|
||||
return;
|
||||
}
|
||||
if (!lodash.isEmpty(giftCard)) {
|
||||
var newData = {};
|
||||
lodash.merge(newData, dataFromStorage, giftCard);
|
||||
amazonService.savePendingGiftCard(newData, null, function(err) {
|
||||
$log.debug("Saving new gift card");
|
||||
$scope.card = newData;
|
||||
$scope.$emit('UpdateAmazonList');
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
});
|
||||
});
|
||||
} else $log.debug("pending gift card not available yet");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue