def advantage_payment_methods_view(**kwargs): is_test_backend = kwargs.get("test_backend") stripe_publishable_key = kwargs["stripe_publishable_key"] api_url = kwargs.get("api_url") token = kwargs.get("token") advantage = UAContractsAPI(session, token, api_url=api_url, is_for_view=True) try: account = advantage.get_purchase_account() except UAContractsUserHasNoAccount as error: raise UAContractsAPIErrorView(error) account_info = advantage.get_customer_info(account["id"]) customer_info = account_info["customerInfo"] default_payment_method = customer_info.get("defaultPaymentMethod") return flask.render_template( "advantage/payment-methods/index.html", stripe_publishable_key=stripe_publishable_key, is_test_backend=is_test_backend, default_payment_method=default_payment_method, account_id=account["id"], )
def get_customer_info(account_id, **kwargs): api_url = kwargs.get("api_url") token = kwargs.get("token") response = {"success": False, "data": {}} try: advantage = UAContractsAPI(session, token, api_url=api_url) response["data"] = advantage.get_customer_info(account_id) response["success"] = True except HTTPError as error: if error.response.status_code == 404: response["data"] = error.response.json() response["success"] = False else: flask.current_app.extensions["sentry"].captureException() raise error return response
def advantage_payment_methods_view(**kwargs): is_test_backend = kwargs.get("test_backend") stripe_publishable_key = kwargs["stripe_publishable_key"] api_url = kwargs.get("api_url") token = kwargs.get("token") advantage = UAContractsAPI(session, token, api_url=api_url, is_for_view=True) try: account = advantage.get_purchase_account() except UAContractsUserHasNoAccount as error: raise UAContractsAPIErrorView(error) subscriptions = advantage.get_account_subscriptions( account_id=account["id"], marketplace="canonical-ua", filters={"status": "locked"}, ) pending_purchase_id = "" for subscription in subscriptions: if subscription.get("pendingPurchases"): pending_purchase_id = subscription.get("pendingPurchases")[0] break account_info = advantage.get_customer_info(account["id"]) customer_info = account_info["customerInfo"] default_payment_method = customer_info.get("defaultPaymentMethod") return flask.render_template( "advantage/payment-methods/index.html", stripe_publishable_key=stripe_publishable_key, is_test_backend=is_test_backend, default_payment_method=default_payment_method, pending_purchase_id=pending_purchase_id, account_id=account["id"], )