Update routes/subscription.py
Browse files- routes/subscription.py +17 -2
routes/subscription.py
CHANGED
@@ -57,8 +57,23 @@ 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
session = stripe.checkout.Session.create(
|
|
|
62 |
success_url="https://yourdomain.com/success",
|
63 |
cancel_url="https://yourdomain.com/cancel",
|
64 |
payment_method_types=["card"],
|
@@ -98,7 +113,7 @@ def create_checkout_session(data: SubscriptionRequest):
|
|
98 |
except Exception as e:
|
99 |
logger.error(f"Error creating checkout session: {e}")
|
100 |
raise HTTPException(status_code=500, detail="Error creating checkout session.")
|
101 |
-
|
102 |
### **WEBHOOK PARA PROCESSAR PAGAMENTOS**
|
103 |
@router.post("/webhook")
|
104 |
async def stripe_webhook(request: Request):
|
|
|
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 customer_id do usuário no banco de dados (Supabase)
|
61 |
+
user_response = requests.get(
|
62 |
+
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.user_id}",
|
63 |
+
headers=SUPABASE_HEADERS
|
64 |
+
)
|
65 |
+
|
66 |
+
user_data = user_response.json()
|
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 |
+
# 🔹 4. Criar Checkout Session no Stripe com o customer_id
|
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"],
|
|
|
113 |
except Exception as e:
|
114 |
logger.error(f"Error creating checkout session: {e}")
|
115 |
raise HTTPException(status_code=500, detail="Error creating checkout session.")
|
116 |
+
|
117 |
### **WEBHOOK PARA PROCESSAR PAGAMENTOS**
|
118 |
@router.post("/webhook")
|
119 |
async def stripe_webhook(request: Request):
|