Update routes/subscription.py
Browse files- routes/subscription.py +16 -34
routes/subscription.py
CHANGED
@@ -417,34 +417,14 @@ def create_checkout_session(
|
|
417 |
# 🔹 Buscar detalhes do preço no Stripe
|
418 |
price_details = stripe.Price.retrieve(price_id)
|
419 |
stylist_price = price_details.unit_amount # Obtém o valor do preço em centavos
|
420 |
-
|
421 |
-
# 🔹 Criar
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
line_items=[
|
429 |
-
{
|
430 |
-
"price": price_id,
|
431 |
-
"quantity": 1
|
432 |
-
}
|
433 |
-
],
|
434 |
-
subscription_data={ # 🔹 Aplicando divisão de receita via `application_fee_percent`
|
435 |
-
"application_fee_percent": 20, # 20% para a plataforma
|
436 |
-
"transfer_data": {
|
437 |
-
"destination": stylist_stripe_id # Conta do estilista no Stripe
|
438 |
-
},
|
439 |
-
"metadata": {
|
440 |
-
"stylist_id": stylist_id,
|
441 |
-
"stylist_stripe_id": stylist_stripe_id,
|
442 |
-
"user_id": user_id,
|
443 |
-
"user_stripe_id": user_stripe_id,
|
444 |
-
"price_id": price_id
|
445 |
-
}
|
446 |
-
},
|
447 |
-
metadata={ # 🔹 Adicionando metadados no checkout
|
448 |
"stylist_id": stylist_id,
|
449 |
"stylist_stripe_id": stylist_stripe_id,
|
450 |
"user_id": user_id,
|
@@ -452,14 +432,16 @@ def create_checkout_session(
|
|
452 |
"price_id": price_id
|
453 |
}
|
454 |
)
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
|
|
|
|
459 |
|
460 |
except Exception as e:
|
461 |
-
logger.error(f"
|
462 |
-
raise HTTPException(status_code=500, detail="
|
463 |
|
464 |
### **CANCELAMENTO DE ASSINATURA**
|
465 |
class CancelSubscriptionRequest(BaseModel):
|
|
|
417 |
# 🔹 Buscar detalhes do preço no Stripe
|
418 |
price_details = stripe.Price.retrieve(price_id)
|
419 |
stylist_price = price_details.unit_amount # Obtém o valor do preço em centavos
|
420 |
+
|
421 |
+
# 🔹 Criar o PaymentIntent no Stripe
|
422 |
+
payment_intent = stripe.PaymentIntent.create(
|
423 |
+
amount=stylist_price, # O valor em centavos
|
424 |
+
currency='usd', # Defina a moeda
|
425 |
+
customer=user_stripe_id, # ID do cliente no Stripe
|
426 |
+
description="Pagamento para o estilista", # Descrição do pagamento
|
427 |
+
metadata={ # Metadados para personalizar a transação
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
"stylist_id": stylist_id,
|
429 |
"stylist_stripe_id": stylist_stripe_id,
|
430 |
"user_id": user_id,
|
|
|
432 |
"price_id": price_id
|
433 |
}
|
434 |
)
|
435 |
+
|
436 |
+
# 🔹 Retornar o clientSecret do PaymentIntent para o frontend
|
437 |
+
return {
|
438 |
+
"message": "PaymentIntent criado com sucesso!",
|
439 |
+
"clientSecret": payment_intent.client_secret # Retornar o clientSecret
|
440 |
+
}
|
441 |
|
442 |
except Exception as e:
|
443 |
+
logger.error(f"Erro ao criar a sessão de checkout: {e}")
|
444 |
+
raise HTTPException(status_code=500, detail="Erro ao criar a sessão de checkout.")
|
445 |
|
446 |
### **CANCELAMENTO DE ASSINATURA**
|
447 |
class CancelSubscriptionRequest(BaseModel):
|