Add a visible free plan. Tweak the plans and pricing page. Move all plans to a central plans service to have a single point for editing. Support the free plan on the user admin page. Tweak the landing page.
This commit is contained in:
parent
8d40f12165
commit
3eca5f65e1
7 changed files with 194 additions and 139 deletions
|
@ -77,7 +77,9 @@ function HeaderCtrl($scope, UserService) {
|
|||
});
|
||||
}
|
||||
|
||||
function PlansCtrl($scope, UserService) {
|
||||
function PlansCtrl($scope, UserService, PlanService) {
|
||||
$scope.plans = PlanService.planList();
|
||||
|
||||
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
|
||||
$scope.user = currentUser;
|
||||
}, true);
|
||||
|
@ -440,38 +442,18 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|||
});
|
||||
}
|
||||
|
||||
function UserAdminCtrl($scope, Restangular) {
|
||||
$scope.plans = [
|
||||
{
|
||||
title: 'Micro',
|
||||
price: 700,
|
||||
privateRepos: 5,
|
||||
stripeId: 'micro',
|
||||
},
|
||||
{
|
||||
title: 'Basic',
|
||||
price: 1200,
|
||||
privateRepos: 10,
|
||||
stripeId: 'small',
|
||||
},
|
||||
{
|
||||
title: 'Medium',
|
||||
price: 2200,
|
||||
privateRepos: 20,
|
||||
stripeId: 'medium',
|
||||
},
|
||||
];
|
||||
|
||||
var planDict = {};
|
||||
var i;
|
||||
for(i = 0; i < $scope.plans.length; i++) {
|
||||
planDict[$scope.plans[i].stripeId] = $scope.plans[i];
|
||||
}
|
||||
function UserAdminCtrl($scope, Restangular, PlanService, $routeParams) {
|
||||
$scope.plans = PlanService.planList();
|
||||
|
||||
var subscribedToPlan = function(sub) {
|
||||
$scope.subscription = sub;
|
||||
$scope.subscribedPlan = planDict[sub.plan];
|
||||
$scope.subscribedPlan = PlanService.getPlan(sub.plan);
|
||||
$scope.planUsagePercent = sub.usedPrivateRepos * 100 / $scope.subscribedPlan.privateRepos;
|
||||
|
||||
if (sub.usedPrivateRepos > $scope.subscribedPlan.privateRepos) {
|
||||
$scope.errorMessage = 'You are using more private repositories than your plan allows, please upgrate your subscription to avoid disruptions in your service.';
|
||||
}
|
||||
|
||||
$scope.planLoading = false;
|
||||
$scope.planChanging = false;
|
||||
}
|
||||
|
@ -505,8 +487,7 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
});
|
||||
};
|
||||
|
||||
console.log('Got request for plan: ' + planId);
|
||||
var planDetails = planDict[planId]
|
||||
var planDetails = PlanService.getPlan(planId)
|
||||
StripeCheckout.open({
|
||||
key: 'pk_test_uEDHANKm9CHCvVa2DLcipGRh',
|
||||
address: false, // TODO change to true
|
||||
|
@ -536,34 +517,14 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
};
|
||||
|
||||
$scope.cancelSubscription = function() {
|
||||
$scope.planChanging = true;
|
||||
$scope.errorMessage = undefined;
|
||||
var unsubscribeRequest = Restangular.one('user/plan');
|
||||
unsubscribeRequest.customDELETE().then(function() {
|
||||
$scope.subscription = undefined;
|
||||
$scope.subscribedPlan = undefined;
|
||||
$scope.planUsagePercent = 0;
|
||||
$scope.planChanging = false;
|
||||
}, function() {
|
||||
// Failure
|
||||
$scope.errorMessage = 'Unable to unsubscribe.';
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
$scope.changeSubscription('free');
|
||||
};
|
||||
|
||||
// Show the subscribe dialog if a plan was requested.
|
||||
if (location.hash.indexOf('?') >= 0) {
|
||||
var query = location.hash.substr(1).split('?')[1];
|
||||
var data = query.split("&");
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var item = data[i].split("=");
|
||||
if (item[0] == 'plan') {
|
||||
var planId = item[1];
|
||||
if (planDict[planId]) {
|
||||
$scope.subscribe(planId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
var requested = $routeParams['plan']
|
||||
if (requested !== undefined && requested !== 'free') {
|
||||
if (PlanService.getPlan(requested) !== undefined) {
|
||||
$scope.subscribe(requested);
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue