Rename duration -> period and remove recurring_duration_units

This commit is contained in:
PCoder 2019-09-19 11:34:27 +05:30
parent d45c953eae
commit 5201b9a443

View file

@ -53,19 +53,11 @@ def get_order_id():
client.put("/v1/last_order_id", str(order_id)) client.put("/v1/last_order_id", str(order_id))
return "OR-{}".format(order_id) return "OR-{}".format(order_id)
def get_human_readable_period(recurring_period_secs): def get_pricing(price_in_chf_cents, product_type, recurring_period):
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):
if product_type == "recurring": if product_type == "recurring":
return "CHF {}/ {}".format( return "CHF {}/ {}".format(
price_in_chf_cents/100, price_in_chf_cents/100,
get_human_readable_period(recurring_period_secs) recurring_period
) )
elif product_type == "one-time": elif product_type == "one-time":
return "CHF {}".format(price_in_chf_cents/100) return "CHF {}".format(price_in_chf_cents/100)
@ -84,9 +76,9 @@ class ListProducts(Resource):
"description": p_json["description"], "description": p_json["description"],
"product_id": product_id, "product_id": product_id,
"pricing": get_pricing(p_json["price"], p_json["type"], "pricing": get_pricing(p_json["price"], p_json["type"],
p_json["recurring_duration"]), p_json["recurring_period"]),
"minimum_subscription_duration": "minimum_subscription_period":
p_json["minumum_subscription_duration"] p_json["minimum_subscription_period"]
} }
prod_dict[product_id] = actual_product prod_dict[product_id] = actual_product
logging.debug("Products = {}".format(prod_dict)) logging.debug("Products = {}".format(prod_dict))
@ -118,11 +110,9 @@ class AddProduct(Resource):
"description": data["product_description"], "description": data["product_description"],
"type": data["product_type"], "type": data["product_type"],
"price": data["product_price"], "price": data["product_price"],
"recurring_duration": data["product_recurring_duration"], "recurring_period": data["product_recurring_period"],
"recurring_duration_units": "minimum_subscription_period":
data["product_recurring_duration_units"], data["product_minimum_subscription_period"] if
"minimum_subscription_duration":
data["product_minimum_subscription_duration"] if
data["product_type"] == "recurring" else 0 data["product_type"] == "recurring" else 0
} }
logging.debug("Adding product data: {}".format(str(product_value))) logging.debug("Adding product data: {}".format(str(product_value)))