Update routes/hello.py
Browse files- routes/hello.py +13 -0
routes/hello.py
CHANGED
@@ -68,6 +68,19 @@ def create_customer(
|
|
68 |
user_id = verify_token(user_token)
|
69 |
logger.info(f"🔹 User verified. user_id: {user_id}")
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
# 🔹 Criar o cliente no Stripe
|
72 |
try:
|
73 |
customer = stripe.Customer.create(
|
|
|
68 |
user_id = verify_token(user_token)
|
69 |
logger.info(f"🔹 User verified. user_id: {user_id}")
|
70 |
|
71 |
+
# 🔹 Verificar se já existe um cliente com o mesmo e-mail ou telefone no Stripe
|
72 |
+
existing_customers = stripe.Customer.list(email=data.email, limit=1)
|
73 |
+
|
74 |
+
if existing_customers.data:
|
75 |
+
logger.warning(f"⚠️ Customer with email {data.email} already exists.")
|
76 |
+
raise HTTPException(status_code=400, detail="A customer with this email already exists in Stripe.")
|
77 |
+
|
78 |
+
existing_customers_by_phone = stripe.Customer.list(phone=data.phone, limit=1)
|
79 |
+
|
80 |
+
if existing_customers_by_phone.data:
|
81 |
+
logger.warning(f"⚠️ Customer with phone {data.phone} already exists.")
|
82 |
+
raise HTTPException(status_code=400, detail="A customer with this phone number already exists in Stripe.")
|
83 |
+
|
84 |
# 🔹 Criar o cliente no Stripe
|
85 |
try:
|
86 |
customer = stripe.Customer.create(
|