Update routes/subscription.py
Browse files- routes/subscription.py +34 -13
routes/subscription.py
CHANGED
@@ -120,19 +120,40 @@ async def stripe_webhook(request: Request):
|
|
120 |
logger.info(f"💰 Stylist will receive: {stylist_share / 100:.2f} BRL")
|
121 |
logger.info(f"🏢 Platform will receive: {platform_share / 100:.2f} BRL")
|
122 |
|
123 |
-
#
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
return {
|
137 |
"status": "Payment processed successfully and transfer initiated!",
|
138 |
"user_id": user_id,
|
|
|
120 |
logger.info(f"💰 Stylist will receive: {stylist_share / 100:.2f} BRL")
|
121 |
logger.info(f"🏢 Platform will receive: {platform_share / 100:.2f} BRL")
|
122 |
|
123 |
+
# Verifique se o payment_intent está presente
|
124 |
+
payment_intent = invoice.get("payment_intent")
|
125 |
+
if payment_intent:
|
126 |
+
logger.info(f"Payment Intent: {payment_intent}")
|
127 |
+
try:
|
128 |
+
transfer = stripe.Transfer.create(
|
129 |
+
amount=stylist_share, # Amount in cents
|
130 |
+
currency="brl",
|
131 |
+
destination=stylist_id, # The stylist's connected Stripe account ID
|
132 |
+
description="Subscription payment",
|
133 |
+
source_transaction=payment_intent # Use the payment_intent as source_transaction
|
134 |
+
)
|
135 |
+
logger.info(f"✅ Transfer successful! Transfer ID: {transfer.id}")
|
136 |
+
except Exception as e:
|
137 |
+
logger.error(f"⚠️ Error transferring funds to stylist using payment_intent: {e}")
|
138 |
+
else:
|
139 |
+
# Tente usar charge ID, caso payment_intent não esteja disponível
|
140 |
+
charge_id = invoice.get("charge")
|
141 |
+
if charge_id:
|
142 |
+
logger.info(f"Charge ID: {charge_id}")
|
143 |
+
try:
|
144 |
+
transfer = stripe.Transfer.create(
|
145 |
+
amount=stylist_share, # Amount in cents
|
146 |
+
currency="brl",
|
147 |
+
destination=stylist_id, # The stylist's connected Stripe account ID
|
148 |
+
description="Subscription payment",
|
149 |
+
source_transaction=charge_id # Use the charge ID if payment_intent is missing
|
150 |
+
)
|
151 |
+
logger.info(f"✅ Transfer successful! Transfer ID: {transfer.id}")
|
152 |
+
except Exception as e:
|
153 |
+
logger.error(f"⚠️ Error transferring funds to stylist using charge: {e}")
|
154 |
+
else:
|
155 |
+
logger.error("⚠️ No payment intent or charge found, unable to transfer funds.")
|
156 |
+
|
157 |
return {
|
158 |
"status": "Payment processed successfully and transfer initiated!",
|
159 |
"user_id": user_id,
|