From 5201b9a443beb1a8d311ab08194ea623d562f48e Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 11:34:27 +0530 Subject: [PATCH] Rename duration -> period and remove recurring_duration_units --- ucloud_pay.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/ucloud_pay.py b/ucloud_pay.py index 95f7ddb..67d5ac8 100644 --- a/ucloud_pay.py +++ b/ucloud_pay.py @@ -53,19 +53,11 @@ def get_order_id(): client.put("/v1/last_order_id", str(order_id)) return "OR-{}".format(order_id) -def get_human_readable_period(recurring_period_secs): - if recurring_period_secs <= 24 * 60 * 60: - return "day" - elif recurring_period_secs <= 30 * 24 * 60 * 60: - return "month" - elif recurring_period_secs <= 365 * 30 * 24 * 60 * 60: - return "year" - -def get_pricing(price_in_chf_cents, product_type, recurring_period_secs): +def get_pricing(price_in_chf_cents, product_type, recurring_period): if product_type == "recurring": return "CHF {}/ {}".format( price_in_chf_cents/100, - get_human_readable_period(recurring_period_secs) + recurring_period ) elif product_type == "one-time": return "CHF {}".format(price_in_chf_cents/100) @@ -84,9 +76,9 @@ class ListProducts(Resource): "description": p_json["description"], "product_id": product_id, "pricing": get_pricing(p_json["price"], p_json["type"], - p_json["recurring_duration"]), - "minimum_subscription_duration": - p_json["minumum_subscription_duration"] + p_json["recurring_period"]), + "minimum_subscription_period": + p_json["minimum_subscription_period"] } prod_dict[product_id] = actual_product logging.debug("Products = {}".format(prod_dict)) @@ -118,11 +110,9 @@ class AddProduct(Resource): "description": data["product_description"], "type": data["product_type"], "price": data["product_price"], - "recurring_duration": data["product_recurring_duration"], - "recurring_duration_units": - data["product_recurring_duration_units"], - "minimum_subscription_duration": - data["product_minimum_subscription_duration"] if + "recurring_period": data["product_recurring_period"], + "minimum_subscription_period": + data["product_minimum_subscription_period"] if data["product_type"] == "recurring" else 0 } logging.debug("Adding product data: {}".format(str(product_value)))