Use the user's name instead of asking email

This commit is contained in:
PCoder 2019-09-19 15:19:53 +05:30
parent 497c535de1
commit ca41a9bcab
1 changed files with 10 additions and 10 deletions

View File

@ -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))