Add some feedback about the number of private repositories used.
This commit is contained in:
parent
c7e83c4d41
commit
c044893ff9
4 changed files with 52 additions and 20 deletions
|
@ -348,11 +348,12 @@ def delete_permissions(namespace, repository, username):
|
|||
abort(403) # Permission denied
|
||||
|
||||
|
||||
def subscription_view(stripe_subscription):
|
||||
def subscription_view(stripe_subscription, used_repos):
|
||||
return {
|
||||
'current_period_start': stripe_subscription.current_period_start,
|
||||
'current_period_end': stripe_subscription.current_period_end,
|
||||
'currentPeriodStart': stripe_subscription.current_period_start,
|
||||
'currentPeriodEnd': stripe_subscription.current_period_end,
|
||||
'plan': stripe_subscription.plan.id,
|
||||
'usedPrivateRepos': used_repos,
|
||||
}
|
||||
|
||||
|
||||
|
@ -367,6 +368,7 @@ def subscribe():
|
|||
card = request_data['token']
|
||||
|
||||
user = current_user.db_user
|
||||
private_repos = model.get_private_repo_count(user.username)
|
||||
|
||||
if not user.stripe_id:
|
||||
# Create the customer and plan simultaneously
|
||||
|
@ -374,7 +376,7 @@ def subscribe():
|
|||
user.stripe_id = cus.id
|
||||
user.save()
|
||||
|
||||
resp = jsonify(subscription_view(cus.subscription))
|
||||
resp = jsonify(subscription_view(cus.subscription, private_repos))
|
||||
resp.status_code = 201
|
||||
return resp
|
||||
|
||||
|
@ -383,7 +385,7 @@ def subscribe():
|
|||
cus = stripe.Customer.retrieve(user.stripe_id)
|
||||
cus.plan = plan
|
||||
cus.save()
|
||||
return jsonify(subscription_view(cus.subscription))
|
||||
return jsonify(subscription_view(cus.subscription, private_repos))
|
||||
|
||||
|
||||
@app.route('/api/user/plan', methods=['GET'])
|
||||
|
@ -392,7 +394,8 @@ def get_subscription():
|
|||
user = current_user.db_user
|
||||
|
||||
if user.stripe_id:
|
||||
private_repos = model.get_private_repo_count(user.username)
|
||||
cus = stripe.Customer.retrieve(user.stripe_id)
|
||||
return jsonify(subscription_view(cus.subscription))
|
||||
return jsonify(subscription_view(cus.subscription, private_repos))
|
||||
|
||||
abort(404)
|
||||
|
|
Reference in a new issue