2016-10-04 12:06:06 -03:00
|
|
|
'use strict';
|
2017-01-27 17:54:41 -03:00
|
|
|
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService, appIdentityService, bitpayService, lodash) {
|
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-18 16:07:21 -03:00
|
|
|
|
|
|
|
|
var pairingReason = gettextCatalog.getString('BitPay Visa card');
|
|
|
|
|
|
2016-12-23 11:37:19 -05:00
|
|
|
bitpayService.pair(pairData, pairingReason, function(err, paired, apiContext) {
|
2017-01-18 16:07:21 -03:00
|
|
|
|
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-01-27 17:54:41 -03: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() {
|
|
|
|
|
if (cards[0]) {
|
|
|
|
|
$state.transitionTo('tabs.bitpayCard', {
|
|
|
|
|
id: cards[0].id
|
|
|
|
|
});
|
|
|
|
|
}
|
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
|
|
|
});
|
|
|
|
|
} else {
|
2017-01-23 17:16:08 -05:00
|
|
|
appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) {
|
2016-10-10 11:12:26 -03:00
|
|
|
if (err) popupService.showAlert(null, err);
|
2016-12-23 11:37:19 -05:00
|
|
|
else $log.info('App identity: OK');
|
2016-10-07 19:21:46 -03:00
|
|
|
});
|
2016-10-06 19:23:39 -03:00
|
|
|
}
|
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() {
|
2016-10-20 18:55:36 -04:00
|
|
|
var url = 'https://bitpay.com/visa/dashboard/add-to-bitpay-wallet-confirm';
|
2016-10-13 20:11:02 -03:00
|
|
|
externalLinkService.open(url);
|
2016-10-06 19:23:39 -03:00
|
|
|
};
|
2016-10-04 12:06:06 -03:00
|
|
|
});
|