Allow user to unsubscribe and change their plan.
This commit is contained in:
parent
da8eccef11
commit
35c1e6e53b
3 changed files with 65 additions and 8 deletions
|
@ -461,6 +461,7 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
$scope.subscribedPlan = planDict[sub.plan];
|
||||
$scope.planUsagePercent = sub.usedPrivateRepos * 100 / $scope.subscribedPlan.privateRepos;
|
||||
$scope.planLoading = false;
|
||||
$scope.planChanging = false;
|
||||
}
|
||||
|
||||
$scope.planLoading = true;
|
||||
|
@ -470,9 +471,13 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
$scope.planLoading = false;
|
||||
});
|
||||
|
||||
$scope.planChanging = false;
|
||||
$scope.subscribe = function(planId) {
|
||||
var submitToken = function(token) {
|
||||
$scope.$apply(function() {
|
||||
$scope.planChanging = true;
|
||||
$scope.errorMessage = undefined;
|
||||
|
||||
var subscriptionDetails = {
|
||||
token: token.id,
|
||||
plan: planId,
|
||||
|
@ -483,7 +488,7 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
var createSubscriptionRequest = Restangular.one('user/plan');
|
||||
createSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
||||
// Failure
|
||||
$scope.errorMessage = 'Unable to process subscription change.';
|
||||
$scope.errorMessage = 'Unable to subscribe.';
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -501,4 +506,36 @@ function UserAdminCtrl($scope, Restangular) {
|
|||
token: submitToken
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeSubscription = function(planId) {
|
||||
$scope.planChanging = true;
|
||||
$scope.errorMessage = undefined;
|
||||
|
||||
var subscriptionDetails = {
|
||||
plan: planId,
|
||||
};
|
||||
|
||||
var changeSubscriptionRequest = Restangular.one('user/plan');
|
||||
changeSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
||||
// Failure
|
||||
$scope.errorMessage = 'Unable to change subscription.';
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
};
|
||||
|
||||
$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;
|
||||
});
|
||||
};
|
||||
}
|
Reference in a new issue