From fefc1947e2930c2bf88abde8ec82b5515da21e31 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 13:33:23 +0530 Subject: [PATCH] Add basic flow for ProductOrder --- ucloud-pay.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ucloud-pay.py b/ucloud-pay.py index bb2a617..e2dbf3e 100644 --- a/ucloud-pay.py +++ b/ucloud-pay.py @@ -215,9 +215,36 @@ class UserRegisterPayment(Resource): return {"message": "Missing or wrong parameters"}, 400 +class ProductOrder(Resource): + @staticmethod + def post(): + data = request.json + try: + otp_response = check_otp(data["name"], data["realm"], + data["token"]) + if otp_response != 200: + return {"message": "Wrong Credentials"}, 403 + + # Validate the given product is ok + + # Check the user has a payment source added + + # Initiate a one-time/subscription based on product type + + # If charge successful, create an order object + + # Else handle unsuccessful cases with grace + + except KeyError as key_error: + logging.error("Key error occurred") + logging.error(str(key_error)) + return {"message": "Missing or wrong parameters"}, 400 + api.add_resource(ListProducts, "/product/list") api.add_resource(AddProduct, "/product/add") +api.add_resource(ProductOrder, "/product/order") api.add_resource(UserRegisterPayment, "/user/register_payment") + if __name__ == '__main__': app.run(host="::", port=APP_PORT, debug=True)