Use the customer information, not an existing subscription, to determine whether the button should say "Start Free Trial" or "Subscribe"
This commit is contained in:
parent
a5c2fc7185
commit
8f66c39ff5
4 changed files with 13 additions and 10 deletions
|
@ -221,6 +221,7 @@ class UserPlan(ApiResource):
|
|||
@nickname('getUserSubscription')
|
||||
def get(self):
|
||||
""" Fetch any existing subscription for the user. """
|
||||
cus = None
|
||||
user = get_authenticated_user()
|
||||
private_repos = model.get_private_repo_count(user.username)
|
||||
|
||||
|
@ -231,6 +232,8 @@ class UserPlan(ApiResource):
|
|||
return subscription_view(cus.subscription, private_repos)
|
||||
|
||||
return {
|
||||
'hasSubscription': False,
|
||||
'isExistingCustomer': cus is not None,
|
||||
'plan': 'free',
|
||||
'usedPrivateRepos': private_repos,
|
||||
}
|
||||
|
@ -280,6 +283,7 @@ class OrganizationPlan(ApiResource):
|
|||
@nickname('getOrgSubscription')
|
||||
def get(self, orgname):
|
||||
""" Fetch any existing subscription for the org. """
|
||||
cus = None
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
private_repos = model.get_private_repo_count(orgname)
|
||||
|
@ -291,6 +295,8 @@ class OrganizationPlan(ApiResource):
|
|||
return subscription_view(cus.subscription, private_repos)
|
||||
|
||||
return {
|
||||
'hasSubscription': False,
|
||||
'isExistingCustomer': cus is not None,
|
||||
'plan': 'free',
|
||||
'usedPrivateRepos': private_repos,
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ def carderror_response(exc):
|
|||
|
||||
def subscription_view(stripe_subscription, used_repos):
|
||||
view = {
|
||||
'hasSubscription': True,
|
||||
'isExistingCustomer': True,
|
||||
'currentPeriodStart': stripe_subscription.current_period_start,
|
||||
'currentPeriodEnd': stripe_subscription.current_period_end,
|
||||
'plan': stripe_subscription.plan.id,
|
||||
|
|
|
@ -29,11 +29,6 @@
|
|||
<span class="usage-caption" ng-show="chart">Repository Usage</span>
|
||||
</div>
|
||||
|
||||
<!-- Next billing info -->
|
||||
<div class="alert alert-info" ng-show="subscription.trialEnd == null && subscription.currentPeriodEnd != null">
|
||||
Next billing period: <strong>{{ parseDate(subscription.currentPeriodEnd) | date }}</strong>
|
||||
</div>
|
||||
|
||||
<!-- Plans Table -->
|
||||
<table class="table table-hover plans-list-table" ng-show="!planLoading">
|
||||
<thead>
|
||||
|
@ -67,8 +62,8 @@
|
|||
ng-click="changeSubscription(plan.stripeId)">
|
||||
<span class="quay-spinner" ng-show="planChanging"></span>
|
||||
<span ng-show="!planChanging && subscribedPlan.price != 0">Change</span>
|
||||
<span ng-show="!planChanging && subscribedPlan.price == 0 && !hasSubscription">Start Trial</span>
|
||||
<span ng-show="!planChanging && subscribedPlan.price == 0 && hasSubscription">Subscribe</span>
|
||||
<span ng-show="!planChanging && subscribedPlan.price == 0 && !isExistingCustomer">Start Free Trial</span>
|
||||
<span ng-show="!planChanging && subscribedPlan.price == 0 && isExistingCustomer">Subscribe</span>
|
||||
</button>
|
||||
<button class="btn btn-danger" ng-show="subscription.plan === plan.stripeId && plan.price > 0"
|
||||
ng-click="cancelSubscription()">
|
||||
|
|
|
@ -3331,7 +3331,7 @@ quayApp.directive('planManager', function () {
|
|||
'planChanged': '&planChanged'
|
||||
},
|
||||
controller: function($scope, $element, PlanService, ApiService) {
|
||||
$scope.hasSubscription = false;
|
||||
$scope.isExistingCustomer = false;
|
||||
|
||||
$scope.parseDate = function(timestamp) {
|
||||
return new Date(timestamp * 1000);
|
||||
|
@ -3372,7 +3372,7 @@ quayApp.directive('planManager', function () {
|
|||
|
||||
var subscribedToPlan = function(sub) {
|
||||
$scope.subscription = sub;
|
||||
$scope.hasSubscription = true;
|
||||
$scope.isExistingCustomer = !!sub['isExistingCustomer'];
|
||||
|
||||
PlanService.getPlanIncludingDeprecated(sub.plan, function(subscribedPlan) {
|
||||
$scope.subscribedPlan = subscribedPlan;
|
||||
|
@ -3409,7 +3409,7 @@ quayApp.directive('planManager', function () {
|
|||
if (!$scope.plans) { return; }
|
||||
|
||||
PlanService.getSubscription($scope.organization, subscribedToPlan, function() {
|
||||
// User/Organization has no subscription.
|
||||
$scope.isExistingCustomer = false;
|
||||
subscribedToPlan({ 'plan': PlanService.getFreePlan() });
|
||||
});
|
||||
};
|
||||
|
|
Reference in a new issue