Add otp validation + handle key error for add product
This commit is contained in:
parent
e1f9db5479
commit
8cc568f736
1 changed files with 23 additions and 15 deletions
|
@ -53,22 +53,30 @@ class AddProduct(Resource):
|
|||
def post():
|
||||
data = request.json
|
||||
logging.debug("Got data: {}".format(str(data)))
|
||||
# TODO: Add validation
|
||||
otp_response = check_otp(data["name"], data["realm"],
|
||||
data["token"])
|
||||
if otp_response != 200:
|
||||
return {"message": "Wrong Credentials"}, 403
|
||||
|
||||
product_key = "/v1/products/"
|
||||
product_value = {
|
||||
"name": data["product_name"],
|
||||
"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"]
|
||||
}
|
||||
logging.debug("Adding product data: {}".format(str(product_value)))
|
||||
client.put(product_key, product_value, value_in_json=True)
|
||||
return {"message":
|
||||
"Product {} created".format(data['product_name'])}, 200
|
||||
try:
|
||||
product_key = "/v1/products/"
|
||||
product_value = {
|
||||
"name": data["product_name"],
|
||||
"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"]
|
||||
}
|
||||
logging.debug("Adding product data: {}".format(str(product_value)))
|
||||
client.put(product_key, product_value, value_in_json=True)
|
||||
return {"message":
|
||||
"Product {} created".format(data['product_name'])}, 200
|
||||
except KeyError as ke:
|
||||
logging.error("KeyError occurred. details = {}".format(str(ke)))
|
||||
return {"message":
|
||||
"Missing or wrong parameters"}, 400
|
||||
|
||||
|
||||
class UserRegisterPayment(Resource):
|
||||
|
|
Loading…
Reference in a new issue