Update routes/hello.py
Browse files- routes/hello.py +13 -5
routes/hello.py
CHANGED
@@ -69,11 +69,16 @@ def create_customer(
|
|
69 |
logger.info(f"🔹 User verified. user_id: {user_id}")
|
70 |
|
71 |
# 🔹 Criar o cliente no Stripe
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
stripe_id = customer.id
|
78 |
logger.info(f"✅ New Stripe customer created: {stripe_id}")
|
79 |
|
@@ -95,6 +100,9 @@ def create_customer(
|
|
95 |
logger.info(f"🔹 Supabase PATCH response: {response.status_code} - {response.text}")
|
96 |
|
97 |
if response.status_code not in [200, 204]:
|
|
|
|
|
|
|
98 |
raise HTTPException(status_code=500, detail=f"Erro ao atualizar o Supabase: {response.text}")
|
99 |
|
100 |
logger.info(f"✅ Successfully updated user {user_id} with stripe_id {stripe_id}")
|
|
|
69 |
logger.info(f"🔹 User verified. user_id: {user_id}")
|
70 |
|
71 |
# 🔹 Criar o cliente no Stripe
|
72 |
+
try:
|
73 |
+
customer = stripe.Customer.create(
|
74 |
+
email=data.email,
|
75 |
+
phone=data.phone,
|
76 |
+
name=data.name
|
77 |
+
)
|
78 |
+
except stripe.error.StripeError as e:
|
79 |
+
logger.error(f"❌ Stripe error: {e}")
|
80 |
+
raise HTTPException(status_code=500, detail="Error creating customer in Stripe")
|
81 |
+
|
82 |
stripe_id = customer.id
|
83 |
logger.info(f"✅ New Stripe customer created: {stripe_id}")
|
84 |
|
|
|
100 |
logger.info(f"🔹 Supabase PATCH response: {response.status_code} - {response.text}")
|
101 |
|
102 |
if response.status_code not in [200, 204]:
|
103 |
+
# 🚨 Se a atualização falhar, deletamos o cliente do Stripe!
|
104 |
+
logger.warning(f"⚠️ Rolling back: Deleting Stripe customer {stripe_id} due to Supabase failure.")
|
105 |
+
stripe.Customer.delete(stripe_id)
|
106 |
raise HTTPException(status_code=500, detail=f"Erro ao atualizar o Supabase: {response.text}")
|
107 |
|
108 |
logger.info(f"✅ Successfully updated user {user_id} with stripe_id {stripe_id}")
|