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:
parent
a5d0569e35
commit
ec6bee35b6
4 changed files with 44 additions and 3 deletions
|
@ -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; }
|
||||
|
||||
|
|
|
@ -148,6 +148,13 @@ function(KeyService, UserService, CookieService, ApiService, Features, Config) {
|
|||
});
|
||||
};
|
||||
|
||||
planService.getPlanImmediately = function(planId) {
|
||||
// Get the plan by name, without bothering to check if the plans are loaded.
|
||||
// This method will return undefined if planId is undefined or null, or if
|
||||
// the planDict has not yet been loaded.
|
||||
return planDict[planId];
|
||||
};
|
||||
|
||||
planService.getMinimumPlan = function(privateCount, isBusiness, callback) {
|
||||
planService.getPlans(function(plans) {
|
||||
for (var i = 0; i < plans.length; i++) {
|
||||
|
|
Reference in a new issue