Update routes/hello.py
Browse files- routes/hello.py +6 -6
routes/hello.py
CHANGED
@@ -62,7 +62,7 @@ def create_customer(
|
|
62 |
):
|
63 |
try:
|
64 |
if not user_token:
|
65 |
-
raise HTTPException(status_code=401, detail=
|
66 |
|
67 |
# 🔹 Validar o token e obter user_id
|
68 |
user_id = verify_token(user_token)
|
@@ -74,7 +74,7 @@ def create_customer(
|
|
74 |
if existing_customers.data:
|
75 |
error_message = f"Customer with email {data.email} already exists."
|
76 |
logger.warning(f"⚠️ {error_message}")
|
77 |
-
raise HTTPException(status_code=400, detail=
|
78 |
|
79 |
# 🔹 Verificar se já existe um cliente com o mesmo telefone
|
80 |
existing_customers_by_phone = stripe.Customer.list(phone=data.phone, limit=1)
|
@@ -82,7 +82,7 @@ def create_customer(
|
|
82 |
if existing_customers_by_phone.data:
|
83 |
error_message = f"Customer with phone {data.phone} already exists."
|
84 |
logger.warning(f"⚠️ {error_message}")
|
85 |
-
raise HTTPException(status_code=400, detail=
|
86 |
|
87 |
# 🔹 Criar o cliente no Stripe
|
88 |
try:
|
@@ -94,7 +94,7 @@ def create_customer(
|
|
94 |
except stripe.error.StripeError as e:
|
95 |
error_message = str(e) if str(e) else "An unknown error occurred. Please try again."
|
96 |
logger.error(f"❌ Stripe error: {error_message}")
|
97 |
-
raise HTTPException(status_code=500, detail=
|
98 |
|
99 |
stripe_id = customer.id
|
100 |
logger.info(f"✅ New Stripe customer created: {stripe_id}")
|
@@ -121,7 +121,7 @@ def create_customer(
|
|
121 |
logger.warning(f"⚠️ Rolling back: Deleting Stripe customer {stripe_id} due to Supabase failure.")
|
122 |
stripe.Customer.delete(stripe_id)
|
123 |
error_message = f"Error updating Supabase: {response.text}"
|
124 |
-
raise HTTPException(status_code=500, detail=
|
125 |
|
126 |
logger.info(f"✅ Successfully updated user {user_id} with stripe_id {stripe_id}")
|
127 |
return {"customer_id": stripe_id}
|
@@ -132,7 +132,7 @@ def create_customer(
|
|
132 |
except Exception as e:
|
133 |
error_message = str(e) if str(e) else "An unknown error occurred. Please try again."
|
134 |
logger.error(f"❌ Error creating customer: {error_message}")
|
135 |
-
raise HTTPException(status_code=500, detail=
|
136 |
|
137 |
@router.post("/create_account")
|
138 |
def create_account(account_data: AccountRequest):
|
|
|
62 |
):
|
63 |
try:
|
64 |
if not user_token:
|
65 |
+
raise HTTPException(status_code=401, detail="Missing User-key header")
|
66 |
|
67 |
# 🔹 Validar o token e obter user_id
|
68 |
user_id = verify_token(user_token)
|
|
|
74 |
if existing_customers.data:
|
75 |
error_message = f"Customer with email {data.email} already exists."
|
76 |
logger.warning(f"⚠️ {error_message}")
|
77 |
+
raise HTTPException(status_code=400, detail=error_message)
|
78 |
|
79 |
# 🔹 Verificar se já existe um cliente com o mesmo telefone
|
80 |
existing_customers_by_phone = stripe.Customer.list(phone=data.phone, limit=1)
|
|
|
82 |
if existing_customers_by_phone.data:
|
83 |
error_message = f"Customer with phone {data.phone} already exists."
|
84 |
logger.warning(f"⚠️ {error_message}")
|
85 |
+
raise HTTPException(status_code=400, detail=error_message)
|
86 |
|
87 |
# 🔹 Criar o cliente no Stripe
|
88 |
try:
|
|
|
94 |
except stripe.error.StripeError as e:
|
95 |
error_message = str(e) if str(e) else "An unknown error occurred. Please try again."
|
96 |
logger.error(f"❌ Stripe error: {error_message}")
|
97 |
+
raise HTTPException(status_code=500, detail=error_message)
|
98 |
|
99 |
stripe_id = customer.id
|
100 |
logger.info(f"✅ New Stripe customer created: {stripe_id}")
|
|
|
121 |
logger.warning(f"⚠️ Rolling back: Deleting Stripe customer {stripe_id} due to Supabase failure.")
|
122 |
stripe.Customer.delete(stripe_id)
|
123 |
error_message = f"Error updating Supabase: {response.text}"
|
124 |
+
raise HTTPException(status_code=500, detail=error_message)
|
125 |
|
126 |
logger.info(f"✅ Successfully updated user {user_id} with stripe_id {stripe_id}")
|
127 |
return {"customer_id": stripe_id}
|
|
|
132 |
except Exception as e:
|
133 |
error_message = str(e) if str(e) else "An unknown error occurred. Please try again."
|
134 |
logger.error(f"❌ Error creating customer: {error_message}")
|
135 |
+
raise HTTPException(status_code=500, detail=error_message)
|
136 |
|
137 |
@router.post("/create_account")
|
138 |
def create_account(account_data: AccountRequest):
|