def get(self, orgname): """ Fetch any existing subscription for the org. """ cus = None permission = AdministerOrganizationPermission(orgname) if permission.can(): private_repos = model.user.get_private_repo_count(orgname) organization = model.organization.get_organization(orgname) if organization.stripe_id: try: cus = billing.Customer.retrieve(organization.stripe_id) except stripe.error.APIConnectionError as e: abort(503, message="Cannot contact Stripe") if cus.subscription: return subscription_view(cus.subscription, private_repos) return { "hasSubscription": False, "isExistingCustomer": cus is not None, "plan": "free", "usedPrivateRepos": private_repos, } raise Unauthorized()
def get(self): """ Fetch any existing subscription for the user. """ cus = None user = get_authenticated_user() private_repos = model.user.get_private_repo_count(user.username) if user.stripe_id: try: cus = billing.Customer.retrieve(user.stripe_id) except stripe.error.APIConnectionError as e: abort(503, message='Cannot contact Stripe') if cus.subscription: return subscription_view(cus.subscription, private_repos) return { 'hasSubscription': False, 'isExistingCustomer': cus is not None, 'plan': 'free', 'usedPrivateRepos': private_repos, }