Support the additional stripe callbacks
This commit is contained in:
parent
68e1658849
commit
0f473a3a82
3 changed files with 49 additions and 41 deletions
|
@ -212,23 +212,31 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failure);
|
createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failure);
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, started, success, failure) {
|
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, callbacks) {
|
||||||
if (!hasExistingSubscription) {
|
if (!hasExistingSubscription) {
|
||||||
planService.showSubscribeDialog($scope, orgname, planId, started, success, failure);
|
planService.showSubscribeDialog($scope, orgname, planId, callbacks);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
started();
|
if (callbacks['started']) {
|
||||||
planService.setSubscription(orgname, planId, success, failure);
|
callbacks['started']();
|
||||||
|
}
|
||||||
|
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.showSubscribeDialog = function($scope, orgname, planId, started, success, failure) {
|
planService.showSubscribeDialog = function($scope, orgname, planId, callbacks) {
|
||||||
|
if (callbacks['opening']) {
|
||||||
|
callbacks['opening']();
|
||||||
|
}
|
||||||
|
|
||||||
var submitToken = function(token) {
|
var submitToken = function(token) {
|
||||||
mixpanel.track('plan_subscribe');
|
mixpanel.track('plan_subscribe');
|
||||||
|
|
||||||
$scope.$apply(function() {
|
$scope.$apply(function() {
|
||||||
started();
|
if (callbacks['started']) {
|
||||||
planService.setSubscription(orgname, planId, success, failure);
|
callbacks['started']();
|
||||||
|
}
|
||||||
|
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -255,7 +263,9 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
description: 'Up to ' + planDetails.privateRepos + ' private repositories',
|
description: 'Up to ' + planDetails.privateRepos + ' private repositories',
|
||||||
panelLabel: 'Subscribe',
|
panelLabel: 'Subscribe',
|
||||||
token: submitToken,
|
token: submitToken,
|
||||||
image: 'static/img/quay-icon-stripe.png'
|
image: 'static/img/quay-icon-stripe.png',
|
||||||
|
opened: function() { $scope.$apply(function() { callbacks['opened']() }); },
|
||||||
|
closed: function() { $scope.$apply(function() { callbacks['closed']() }); }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -629,16 +639,16 @@ quayApp.directive('planManager', function () {
|
||||||
$scope.changeSubscription = function(planId) {
|
$scope.changeSubscription = function(planId) {
|
||||||
if ($scope.planChanging) { return; }
|
if ($scope.planChanging) { return; }
|
||||||
|
|
||||||
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, function() {
|
var callbacks = {
|
||||||
// Started.
|
'opening': function() { $scope.planChanging = true; },
|
||||||
$scope.planChanging = true;
|
'started': function() { $scope.planChanging = true; },
|
||||||
}, function(sub) {
|
'opened': function() { $scope.planChanging = true; },
|
||||||
// Success.
|
'closed': function() { $scope.planChanging = false; },
|
||||||
subscribedToPlan(sub);
|
'success': subscribedToPlan,
|
||||||
}, function() {
|
'failure': function() { $scope.planChanging = false; }
|
||||||
// Failure.
|
};
|
||||||
$scope.planChanging = false;
|
|
||||||
});
|
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, callbacks);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.cancelSubscription = function() {
|
$scope.cancelSubscription = function() {
|
||||||
|
|
|
@ -1038,17 +1038,14 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.upgradePlan = function() {
|
$scope.upgradePlan = function() {
|
||||||
PlanService.changePlan($scope, null, $scope.planRequired.stripeId, null, function() {
|
var callbacks = {
|
||||||
// Subscribing.
|
'opened': function() { $scope.planChanging = true; },
|
||||||
$scope.planChanging = true;
|
'closed': function() { $scope.planChanging = false; },
|
||||||
}, function(plan) {
|
'success': subscribedToPlan,
|
||||||
// Subscribed.
|
'failure': function() { $('#couldnotsubscribeModal').modal(); $scope.planChanging = false; }
|
||||||
subscribedToPlan(plan);
|
};
|
||||||
}, function() {
|
|
||||||
// Failure.
|
PlanService.changePlan($scope, null, $scope.planRequired.stripeId, null, callbacks);
|
||||||
$('#couldnotsubscribeModal').modal();
|
|
||||||
$scope.planChanging = false;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watch the namespace on the repo. If it changes, we update the plan and the public/private
|
// Watch the namespace on the repo. If it changes, we update the plan and the public/private
|
||||||
|
@ -1364,24 +1361,25 @@ function NewOrgCtrl($scope, $routeParams, $timeout, $location, UserService, Plan
|
||||||
// Reset the organizations list.
|
// Reset the organizations list.
|
||||||
UserService.load();
|
UserService.load();
|
||||||
|
|
||||||
|
var showOrg = function() {
|
||||||
|
$location.path('/organization/' + org.name + '/');
|
||||||
|
};
|
||||||
|
|
||||||
// If the selected plan is free, simply move to the org page.
|
// If the selected plan is free, simply move to the org page.
|
||||||
if ($scope.currentPlan.price == 0) {
|
if ($scope.currentPlan.price == 0) {
|
||||||
$location.path('/organization/' + org.name + '/');
|
showOrg();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, show the subscribe for the plan.
|
// Otherwise, show the subscribe for the plan.
|
||||||
PlanService.changePlan($scope, org.name, $scope.currentPlan.stripeId, false, function() {
|
var callbacks = {
|
||||||
// Started.
|
'opened': function() { $scope.creating = true; },
|
||||||
$scope.creating = true;
|
'closed': showOrg,
|
||||||
}, function(sub) {
|
'success': showOrg,
|
||||||
// Success.
|
'failure': showOrg
|
||||||
$location.path('/organization/' + org.name + '/');
|
};
|
||||||
}, function() {
|
|
||||||
// Failure.
|
|
||||||
$location.path('/organization/' + org.name + '/');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
PlanService.changePlan($scope, org.name, $scope.currentPlan.stripeId, false, callbacks);
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
$scope.creating = false;
|
$scope.creating = false;
|
||||||
$scope.createError = result.data.message || result.data;
|
$scope.createError = result.data.message || result.data;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block added_dependencies %}
|
{% block added_dependencies %}
|
||||||
<script src="https://checkout.stripe.com/v2/checkout.js"></script>
|
<script src="https://checkout.stripe.com/checkout.js"></script>
|
||||||
|
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
|
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script>
|
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script>
|
||||||
|
|
Reference in a new issue