2016-05-13 11:48:48 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('amazonController',
|
2016-06-05 19:19:07 -03:00
|
|
|
function($rootScope, $scope, $timeout, $modal, profileService, configService, amazonService, animationService, lodash) {
|
2016-05-13 11:48:48 -03:00
|
|
|
|
|
|
|
|
window.ignoreMobilePause = true;
|
|
|
|
|
|
|
|
|
|
this.init = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
2016-06-07 21:20:13 -03:00
|
|
|
self.sandbox = network == 'testnet' ? true : false;
|
2016-05-13 11:48:48 -03:00
|
|
|
amazonService.setCredentials(network);
|
|
|
|
|
amazonService.getGiftCards(function(err, gcds) {
|
|
|
|
|
if (err) {
|
|
|
|
|
self.error = err;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.giftCards = gcds;
|
2016-05-19 20:20:06 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
2016-05-13 11:48:48 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.openCardModal = function(card) {
|
|
|
|
|
$rootScope.modalOpened = true;
|
|
|
|
|
var self = this;
|
|
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
|
$scope.card = card;
|
|
|
|
|
|
2016-05-19 17:29:24 -03:00
|
|
|
$scope.cancelGiftCard = function() {
|
|
|
|
|
$scope.refresh = true;
|
|
|
|
|
var dataSrc = {
|
|
|
|
|
creationRequestId: $scope.card.creationRequestId,
|
|
|
|
|
gcId: $scope.card.gcId,
|
|
|
|
|
bitpayInvoiceId: $scope.card.bitpayInvoiceId,
|
|
|
|
|
bitpayInvoiceUrl: $scope.card.bitpayInvoiceUrl,
|
|
|
|
|
date: $scope.card.date
|
|
|
|
|
};
|
|
|
|
|
$scope.loading = true;
|
|
|
|
|
amazonService.cancelGiftCard(dataSrc, function(err, data) {
|
|
|
|
|
$scope.loading = null;
|
|
|
|
|
if (err || data.status != 'SUCCESS') {
|
|
|
|
|
$scope.error = err || data.status;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.refreshGiftCard();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.remove = function() {
|
|
|
|
|
amazonService.saveGiftCard($scope.card, {remove: true}, function(err) {
|
|
|
|
|
$modalInstance.close(true);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.refreshGiftCard = function() {
|
|
|
|
|
$scope.refresh = true;
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
$scope.loading = true;
|
|
|
|
|
amazonService.createGiftCard(dataSrc, function(err, data) {
|
|
|
|
|
$scope.loading = null;
|
|
|
|
|
if (err) {
|
|
|
|
|
$scope.error = err;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.card = data;
|
2016-05-19 20:20:06 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
2016-05-19 17:29:24 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-13 11:48:48 -03:00
|
|
|
$scope.cancel = lodash.debounce(function() {
|
2016-05-19 17:29:24 -03:00
|
|
|
$modalInstance.close($scope.refresh);
|
2016-05-13 11:48:48 -03:00
|
|
|
}, 0, 1000);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var modalInstance = $modal.open({
|
|
|
|
|
templateUrl: 'views/modals/amazon-card-details.html',
|
|
|
|
|
windowClass: animationService.modalAnimated.slideRight,
|
|
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var disableCloseModal = $rootScope.$on('closeModal', function() {
|
2016-05-19 17:29:24 -03:00
|
|
|
modalInstance.close($scope.refresh);
|
2016-05-13 11:48:48 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
|
$rootScope.modalOpened = false;
|
|
|
|
|
disableCloseModal();
|
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
|
|
|
|
m.addClass(animationService.modalAnimated.slideOutRight);
|
|
|
|
|
});
|
2016-05-19 17:29:24 -03:00
|
|
|
|
|
|
|
|
modalInstance.result.then(function(refresh) {
|
|
|
|
|
if (refresh) self.init();
|
|
|
|
|
}, function() {});
|
2016-05-13 11:48:48 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|