From 5028172c51a4b5ef27b03399c7a4583e6ff9fade Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 28 Aug 2014 16:10:06 -0400 Subject: [PATCH] Fix Stripe dialog in IE and mobile safari --- static/js/app.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index c26e5800d..51434ce39 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1543,7 +1543,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading }); }; - planService.changePlan = function($scope, orgname, planId, callbacks) { + planService.changePlan = function($scope, orgname, planId, callbacks, opt_async) { if (!Features.BILLING) { return; } if (callbacks['started']) { @@ -1556,7 +1556,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading planService.getCardInfo(orgname, function(cardInfo) { if (plan.price > 0 && (previousSubscribeFailure || !cardInfo.last4)) { var title = cardInfo.last4 ? 'Subscribe' : 'Start Trial ({{amount}} plan)'; - planService.showSubscribeDialog($scope, orgname, planId, callbacks, title); + planService.showSubscribeDialog($scope, orgname, planId, callbacks, title, /* async */true); return; } @@ -1629,9 +1629,34 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading return email; }; - planService.showSubscribeDialog = function($scope, orgname, planId, callbacks, opt_title) { + planService.showSubscribeDialog = function($scope, orgname, planId, callbacks, opt_title, opt_async) { if (!Features.BILLING) { return; } + // If the async parameter is true and this is a browser that does not allow async popup of the + // Stripe dialog (such as Mobile Safari or IE), show a bootbox to show the dialog instead. + var isIE = navigator.appName.indexOf("Internet Explorer") != -1; + var isMobileSafari = navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/); + + if (opt_async && (isIE || isMobileSafari)) { + bootbox.dialog({ + "message": "Please click 'Subscribe' to continue", + "buttons": { + "subscribe": { + "label": "Subscribe", + "className": "btn-primary", + "callback": function() { + planService.showSubscribeDialog($scope, orgname, planId, callbacks, opt_title, false); + } + }, + "close": { + "label": "Cancel", + "className": "btn-default" + } + } + }); + return; + } + if (callbacks['opening']) { callbacks['opening'](); } @@ -3904,7 +3929,7 @@ quayApp.directive('planManager', function () { return true; }; - $scope.changeSubscription = function(planId) { + $scope.changeSubscription = function(planId, opt_async) { if ($scope.planChanging) { return; } var callbacks = { @@ -3918,7 +3943,7 @@ quayApp.directive('planManager', function () { } }; - PlanService.changePlan($scope, $scope.organization, planId, callbacks); + PlanService.changePlan($scope, $scope.organization, planId, callbacks, opt_async); }; $scope.cancelSubscription = function() { @@ -3981,7 +4006,7 @@ quayApp.directive('planManager', function () { if ($scope.readyForPlan) { var planRequested = $scope.readyForPlan(); if (planRequested && planRequested != PlanService.getFreePlan()) { - $scope.changeSubscription(planRequested); + $scope.changeSubscription(planRequested, /* async */true); } } });