From ca41a9bcab6888c717cdccbdb2d0d2b1506e77bb Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 15:19:53 +0530 Subject: [PATCH] Use the user's name instead of asking email --- ucloud_pay.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ucloud_pay.py b/ucloud_pay.py index 583fb81..2a5a907 100644 --- a/ucloud_pay.py +++ b/ucloud_pay.py @@ -170,12 +170,12 @@ class UserRegisterPayment(Resource): # Does customer already exist ? stripe_customer = stripe_utils.get_stripe_customer_from_email( - data["email"]) + data["name"]) # Does customer already exist ? if stripe_customer is not None: logging.debug( - "Customer {} exists already".format(data['email']) + "Customer {} exists already".format(data['name']) ) # Check if the card already exists ce_response = stripe_utils.card_exists( @@ -225,7 +225,7 @@ class UserRegisterPayment(Resource): # Stripe customer does not exist, create a new one logging.debug( "Customer {} does not exist, " - "creating new".format(data['email']) + "creating new".format(data['name']) ) token_response = stripe_utils.get_token_from_card( data["card_number"], data["cvc"], data["expiry_month"], @@ -240,7 +240,7 @@ class UserRegisterPayment(Resource): stripe_customer_resp = stripe_utils.create_customer( name=data["card_holder_name"], token=token_response["response_object"].id, - email=data["email"] + email=data["name"] ) if stripe_customer_resp["response_object"]: logging.debug( @@ -256,7 +256,7 @@ class UserRegisterPayment(Resource): }, 200 else: logging.error("Could not get/create stripe_customer " - "for {}".format(data["email"])) + "for {}".format(data["name"])) return {"message": "Error with card. Contact support"}, 400 else: @@ -294,12 +294,12 @@ class ProductOrder(Resource): # Check the user has a payment source added stripe_customer = stripe_utils.get_stripe_customer_from_email( - data["email"] + data["name"] ) if not stripe_customer or len(stripe_customer.sources) == 0: logging.error("{} does not exist in Stripe => no cards".format( - data["email"]) + data["name"]) ) return {"message": "Please register a payment source"}, 400 @@ -342,7 +342,7 @@ class ProductOrder(Resource): "product": product_obj, } client.put("/v1/user/{}/orders".format( - data['email']), json.dumps(order_obj), + data['name']), json.dumps(order_obj), value_in_json=True) return {"message": "Order successful", "order_details": order_obj}, 200 @@ -370,8 +370,8 @@ class OrderList(Resource): if otp_response != 200: return {"message": "Wrong Credentials"}, 403 - orders = client.get_prefix("/v1/user/{}/orders".format(data['email']), value_in_json=True) - order_dict = {} + orders = client.get_prefix("/v1/user/{}/orders".format(data['name']), value_in_json=True) + orders_dict = {} for p in orders: order_dict[p.key] = p.value logging.debug("Orders = {}".format(order_dict))