From a7ba9669f8c6db72fa883f75f468c21471b57d8f Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 13:39:30 +0530 Subject: [PATCH] Implement validate product --- ucloud-pay.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ucloud-pay.py b/ucloud-pay.py index 33faee6..2b8e33d 100644 --- a/ucloud-pay.py +++ b/ucloud-pay.py @@ -226,6 +226,15 @@ class ProductOrder(Resource): return {"message": "Wrong Credentials"}, 403 # Validate the given product is ok + product_id = data["product_id"] + product = client.get_prefix( + "/v1/products/{}/".format(product_id), value_in_json=True + ) + if not product: + logging.debug("User chose invalid product {}".format(product)) + return {"message": "Invalid product"}, 400 + + logging.debug("Got product {}".format(str(product))) # Check the user has a payment source added