From 0ea2a681428994451c2f21b9aab71a9320ab28b7 Mon Sep 17 00:00:00 2001 From: meow Date: Tue, 3 Dec 2019 18:45:45 +0500 Subject: [PATCH] Fixed order in which AUTH Token is generated --- ucloud_pay.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ucloud_pay.py b/ucloud_pay.py index f7a1c73..1269c0d 100644 --- a/ucloud_pay.py +++ b/ucloud_pay.py @@ -17,9 +17,6 @@ app = Flask(__name__) api = Api(app) # load configs -AUTH_NAME = config("AUTH_NAME", "") -AUTH_TOKEN = TOTP(config("AUTH_SEED", "")).now() -AUTH_REALM = config("AUTH_REALM", "") OTP_SERVER = config("OTP_SERVER", "") OTP_VERIFY_ENDPOINT = config("OTP_VERIFY_ENDPOINT", "verify/") @@ -33,9 +30,9 @@ except UndefinedValueError as uve: def check_otp(name, realm, token): try: data = { - "auth_name": AUTH_NAME, - "auth_token": AUTH_TOKEN, - "auth_realm": AUTH_REALM, + "auth_name": config("AUTH_NAME", ""), + "auth_token": TOTP(config("AUTH_SEED", "")).now(), + "auth_realm": config("AUTH_REALM", ""), "name": name, "realm": realm, "token": token, @@ -48,16 +45,18 @@ def check_otp(name, realm, token): OTP_SERVER=OTP_SERVER, OTP_VERIFY_ENDPOINT=OTP_VERIFY_ENDPOINT, ), - data=data, + json=data, ) return response.status_code + def get_plan_id_from_product(product): plan_id = "ucloud-v1-" plan_id += product["name"].strip().replace(' ', '-') + "-" plan_id += product["type"] return plan_id + def get_order_id(): order_id_kv = client.get("/v1/last_order_id") if order_id_kv is not None: @@ -67,6 +66,7 @@ def get_order_id(): client.put("/v1/last_order_id", str(order_id)) return "OR-{}".format(order_id) + def get_pricing(price_in_chf_cents, product_type, recurring_period): if product_type == "recurring": return "CHF {}/{}".format( @@ -76,6 +76,7 @@ def get_pricing(price_in_chf_cents, product_type, recurring_period): elif product_type == "one-time": return "CHF {} (One time charge)".format(price_in_chf_cents/100) + def get_user_friendly_product(product_dict): uf_product = { "name": product_dict["name"], @@ -91,7 +92,6 @@ def get_user_friendly_product(product_dict): return uf_product - class ListProducts(Resource): @staticmethod def get():