2016-10-04 12:06:06 -03:00
|
|
|
'use strict';
|
2017-01-06 12:11:47 -05:00
|
|
|
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService, bitpayAccountService) {
|
2016-10-07 15:51:15 -03:00
|
|
|
|
2016-10-04 12:06:06 -03:00
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
2016-10-06 19:23:39 -03:00
|
|
|
if (data.stateParams && data.stateParams.secret) {
|
2016-12-23 11:37:19 -05:00
|
|
|
var pairData = {
|
2016-10-06 19:23:39 -03:00
|
|
|
secret: data.stateParams.secret,
|
|
|
|
|
email: data.stateParams.email,
|
|
|
|
|
otp: data.stateParams.otp
|
|
|
|
|
};
|
2017-01-06 12:11:47 -05:00
|
|
|
var pairingReason = gettextCatalog.getString('add your BitPay Visa card(s)');
|
|
|
|
|
bitpayAccountService.pair(pairData, pairingReason, function(err, paired, apiContext) {
|
2016-12-23 11:37:19 -05:00
|
|
|
if (err) {
|
2017-01-18 16:07:21 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('Error pairing Bitpay Account'), err);
|
2016-12-23 11:37:19 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (paired) {
|
2017-02-09 14:58:47 -05:00
|
|
|
bitpayCardService.sync(apiContext, function(err, cards) {
|
2016-12-23 11:37:19 -05:00
|
|
|
if (err) {
|
2017-01-27 17:54:41 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('Error updating Debit Cards'), err);
|
2016-12-23 11:37:19 -05:00
|
|
|
return;
|
2016-10-07 15:51:15 -03:00
|
|
|
}
|
2016-12-23 11:37:19 -05:00
|
|
|
// Set flag for nextStep
|
|
|
|
|
storageService.setNextStep('BitpayCard', 'true', function(err) {});
|
2017-01-27 17:54:41 -03:00
|
|
|
$ionicHistory.nextViewOptions({
|
|
|
|
|
disableAnimate: true
|
|
|
|
|
});
|
|
|
|
|
$state.go('tabs.home').then(function() {
|
2017-02-09 14:58:47 -05:00
|
|
|
if (cards[0]) {
|
2017-01-27 17:54:41 -03:00
|
|
|
$state.transitionTo('tabs.bitpayCard', {
|
2017-02-09 14:58:47 -05:00
|
|
|
id: cards[0].id
|
2017-01-27 17:54:41 -03:00
|
|
|
});
|
|
|
|
|
}
|
2016-12-23 11:37:19 -05:00
|
|
|
});
|
2016-10-07 15:51:15 -03:00
|
|
|
});
|
2016-12-23 11:37:19 -05:00
|
|
|
}
|
2016-10-06 19:23:39 -03:00
|
|
|
});
|
|
|
|
|
}
|
2017-01-06 12:11:47 -05:00
|
|
|
|
|
|
|
|
bitpayAccountService.getAccounts(function(err, accounts) {
|
|
|
|
|
if (err) {
|
|
|
|
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.accounts = accounts;
|
|
|
|
|
});
|
2016-10-04 12:06:06 -03:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 23:59:03 -04:00
|
|
|
$scope.bitPayCardInfo = function() {
|
|
|
|
|
var url = 'https://bitpay.com/visa/faq';
|
|
|
|
|
externalLinkService.open(url);
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-04 12:06:06 -03:00
|
|
|
$scope.orderBitPayCard = function() {
|
2016-10-20 18:55:36 -04:00
|
|
|
var url = 'https://bitpay.com/visa/get-started';
|
2016-10-13 20:11:02 -03:00
|
|
|
externalLinkService.open(url);
|
2016-10-04 12:06:06 -03:00
|
|
|
};
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
$scope.connectBitPayCard = function() {
|
2017-01-06 12:11:47 -05:00
|
|
|
if ($scope.accounts.length == 0) {
|
|
|
|
|
startPairBitPayAccount();
|
|
|
|
|
} else {
|
|
|
|
|
showAccountSelector();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var startPairBitPayAccount = function() {
|
2016-10-20 18:55:36 -04:00
|
|
|
var url = 'https://bitpay.com/visa/dashboard/add-to-bitpay-wallet-confirm';
|
2017-01-06 12:11:47 -05:00
|
|
|
externalLinkService.open(url);
|
2016-10-06 19:23:39 -03:00
|
|
|
};
|
2017-01-06 12:11:47 -05:00
|
|
|
|
|
|
|
|
var showAccountSelector = function() {
|
|
|
|
|
$scope.accountSelectorTitle = gettextCatalog.getString('From BitPay account');
|
|
|
|
|
$scope.showAccounts = ($scope.accounts != undefined);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.onAccountSelect = function(account) {
|
|
|
|
|
if (account == undefined) {
|
|
|
|
|
startPairBitPayAccount();
|
|
|
|
|
} else {
|
2017-02-09 14:58:47 -05:00
|
|
|
bitpayCardService.sync(account.apiContext, function(err, data) {
|
2017-01-06 12:11:47 -05:00
|
|
|
if (err) {
|
|
|
|
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
storageService.setNextStep('BitpayCard', 'true', function(err) {
|
|
|
|
|
$state.go('tabs.home');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-04 12:06:06 -03:00
|
|
|
});
|