Merge branch 'orgs' of ssh://bitbucket.org/yackob03/quay into orgs

This commit is contained in:
yackob03 2013-11-06 14:55:51 -05:00
commit 7dc4c2b250

View file

@ -1081,9 +1081,17 @@ def subscribe_api():
plan = request_data['plan']
token = request_data['token'] if 'token' in request_data else None
user = current_user.db_user()
return subscribe(user, plan, token)
return subscribe(user, plan, token, USER_PLANS)
def subscribe(user, plan, token = None):
def subscribe(user, plan, token, accepted_plans):
plan_found = None
for plan_obj in accepted_plans:
if plan_obj['stripeId'] == plan:
plan_found = plan_obj
if not plan_found:
abort(404)
private_repos = model.get_private_repo_count(user.username)
if not user.stripe_id:
@ -1101,12 +1109,12 @@ def subscribe(user, plan, token = None):
# Change the plan
cus = stripe.Customer.retrieve(user.stripe_id)
if plan == 'free':
if plan_found['price'] == 0:
cus.cancel_subscription()
cus.save()
response_json = {
'plan': 'free',
'plan': plan,
'usedPrivateRepos': private_repos,
}
@ -1131,7 +1139,7 @@ def subscribe_org_api(orgname):
plan = request_data['plan']
token = request_data['token'] if 'token' in request_data else None
organization = model.get_organization(orgname)
return subscribe(organization, plan, token)
return subscribe(organization, plan, token, BUSINESS_PLANS)
abort(403)