Update routes/subscription.py
Browse files- routes/subscription.py +11 -10
routes/subscription.py
CHANGED
@@ -57,23 +57,24 @@ def create_checkout_session(data: SubscriptionRequest):
|
|
57 |
if not stylist_price or not consultations or not stylist_stripe_id:
|
58 |
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
59 |
|
60 |
-
# 🔹 3. Buscar o
|
61 |
-
|
62 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.user_id}",
|
63 |
headers=SUPABASE_HEADERS
|
64 |
)
|
65 |
-
|
66 |
-
user_data =
|
67 |
if not user_data:
|
68 |
raise HTTPException(status_code=404, detail="User not found")
|
69 |
-
|
70 |
-
customer_id = user_data[0].get("customer_id")
|
71 |
-
if not customer_id:
|
72 |
-
raise HTTPException(status_code=400, detail="Customer ID not found for user")
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
session = stripe.checkout.Session.create(
|
76 |
-
customer=customer_id, # Passando o customer_id recuperado
|
77 |
success_url="https://yourdomain.com/success",
|
78 |
cancel_url="https://yourdomain.com/cancel",
|
79 |
payment_method_types=["card"],
|
|
|
57 |
if not stylist_price or not consultations or not stylist_stripe_id:
|
58 |
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
59 |
|
60 |
+
# 🔹 3. Buscar o stripe_id do usuário no banco de dados (Supabase)
|
61 |
+
response_user = requests.get(
|
62 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.user_id}",
|
63 |
headers=SUPABASE_HEADERS
|
64 |
)
|
65 |
+
|
66 |
+
user_data = response_user.json()
|
67 |
if not user_data:
|
68 |
raise HTTPException(status_code=404, detail="User not found")
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
user = user_data[0]
|
71 |
+
user_stripe_id = user.get("stripe_id") # Pega o stripe_id do usuário
|
72 |
+
|
73 |
+
if not user_stripe_id:
|
74 |
+
raise HTTPException(status_code=400, detail="User does not have a Stripe ID")
|
75 |
+
|
76 |
+
# 🔹 4. Criar Checkout Session no Stripe
|
77 |
session = stripe.checkout.Session.create(
|
|
|
78 |
success_url="https://yourdomain.com/success",
|
79 |
cancel_url="https://yourdomain.com/cancel",
|
80 |
payment_method_types=["card"],
|