Allow a stripe plan to be superseded

If a plan has a direct corrolary, show that one as the selected plan
instead of showing the plan as deprecated even though it has the same
details
This commit is contained in:
Jake Moshenko 2015-08-12 10:48:40 -04:00
parent a5d0569e35
commit ec6bee35b6
4 changed files with 44 additions and 3 deletions

View file

@ -25,7 +25,13 @@ angular.module('quay').directive('planManager', function () {
};
$scope.isPlanVisible = function(plan, subscribedPlan) {
// A plan is visible if it is not deprecated, or if it is both not superseded
// by another plan, and also the active plan for the user.
if (plan['deprecated']) {
superseded = plan['superseded_by']
if (superseded) {
return !$scope.isPlanVisible(superseded, subscribedPlan);
}
return plan == subscribedPlan;
}
@ -36,6 +42,20 @@ angular.module('quay').directive('planManager', function () {
return true;
};
$scope.isPlanActive = function(plan, subscribedPlan) {
// A plan is active if it is either the plan directly subscribed to by the user
// or the plan which supersedes the plan to which the user is subscribed.
if (!subscribedPlan) {
return false;
}
if (subscribedPlan['deprecated'] && subscribedPlan['superseded_by']) {
return $scope.isPlanActive(plan, PlanService.getPlanImmediately(subscribedPlan['superseded_by']));
}
return (plan.stripeId === subscribedPlan.stripeId);
};
$scope.changeSubscription = function(planId, opt_async) {
if ($scope.planChanging) { return; }