2016-06-13 15:00:17 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-06-13 21:50:48 -03:00
|
|
|
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $timeout, amazonService, ongoingProcess) {
|
2016-06-13 15:00:17 -03:00
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
};
|
2016-06-13 21:50:48 -03:00
|
|
|
ongoingProcess.set('Canceling gift card...', true);
|
2016-06-13 15:00:17 -03:00
|
|
|
amazonService.cancelGiftCard(dataSrc, function(err, data) {
|
2016-06-13 21:50:48 -03:00
|
|
|
ongoingProcess.set('Canceling gift card...', false);
|
2016-06-13 15:00:17 -03:00
|
|
|
if (err || data.status != 'SUCCESS') {
|
|
|
|
|
$scope.error = err || data.status;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.refreshGiftCard();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.remove = function() {
|
|
|
|
|
amazonService.saveGiftCard($scope.card, {remove: true}, function(err) {
|
|
|
|
|
$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
|
|
|
|
|
};
|
2016-06-13 21:50:48 -03:00
|
|
|
ongoingProcess.set('Updating gift card...', true);
|
2016-06-13 15:00:17 -03:00
|
|
|
amazonService.createGiftCard(dataSrc, function(err, data) {
|
2016-06-13 21:50:48 -03:00
|
|
|
ongoingProcess.set('Updating gift card...', false);
|
2016-06-13 15:00:17 -03:00
|
|
|
if (err) {
|
|
|
|
|
$scope.error = err;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.card = data;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
|
$scope.amazonCardDetailsModal.hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|