Update routes/subscription.py
Browse files- routes/subscription.py +21 -14
routes/subscription.py
CHANGED
@@ -343,31 +343,38 @@ async def subscription_details(data: SubscriptionRequest):
|
|
343 |
current_price = subscription["items"]["data"][0]["price"]["unit_amount"] / 100
|
344 |
currency = subscription["items"]["data"][0]["price"]["currency"].upper()
|
345 |
|
346 |
-
# Data da próxima cobrança -
|
347 |
-
logger.info(f"Tentando buscar
|
348 |
try:
|
349 |
-
logger.info("Chamando stripe.Invoice.
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
subscription=subscription_id
|
354 |
)
|
355 |
|
356 |
-
logger.info(f"
|
357 |
-
logger.info(f"
|
358 |
-
logger.info(f"Amount due: {
|
359 |
-
logger.info(f"Currency: {
|
360 |
-
logger.info(f"Status: {
|
361 |
|
362 |
-
next_invoice_amount =
|
363 |
logger.info(f"Calculated next_invoice_amount: {next_invoice_amount}")
|
364 |
|
365 |
except stripe.error.StripeError as e:
|
366 |
-
logger.error(f"Stripe error getting
|
367 |
logger.error(f"Stripe error type: {type(e)}")
|
368 |
next_invoice_amount = None
|
369 |
except Exception as e:
|
370 |
-
logger.error(f"General error getting
|
371 |
logger.error(f"Error type: {type(e)}")
|
372 |
next_invoice_amount = None
|
373 |
|
|
|
343 |
current_price = subscription["items"]["data"][0]["price"]["unit_amount"] / 100
|
344 |
currency = subscription["items"]["data"][0]["price"]["currency"].upper()
|
345 |
|
346 |
+
# Data da próxima cobrança - USANDO A NOVA API CREATE PREVIEW INVOICE
|
347 |
+
logger.info(f"Tentando buscar preview invoice para subscription: {subscription_id}")
|
348 |
try:
|
349 |
+
logger.info("Chamando stripe.Invoice.create_preview via async_stripe_request...")
|
350 |
+
|
351 |
+
# Obter customer_id da subscription
|
352 |
+
customer_id = subscription.get("customer")
|
353 |
+
if isinstance(customer_id, dict):
|
354 |
+
customer_id = customer_id.get("id")
|
355 |
+
|
356 |
+
# SOLUÇÃO: Usar a nova API create_preview com subscription parameter
|
357 |
+
preview_invoice = await async_stripe_request(
|
358 |
+
stripe.Invoice.create_preview,
|
359 |
+
customer=customer_id,
|
360 |
subscription=subscription_id
|
361 |
)
|
362 |
|
363 |
+
logger.info(f"Preview invoice object type: {type(preview_invoice)}")
|
364 |
+
logger.info(f"Preview invoice retrieved successfully")
|
365 |
+
logger.info(f"Amount due: {preview_invoice.get('amount_due') if preview_invoice else 'None'}")
|
366 |
+
logger.info(f"Currency: {preview_invoice.get('currency') if preview_invoice else 'None'}")
|
367 |
+
logger.info(f"Status: {preview_invoice.get('status', 'No status') if preview_invoice else 'None'}")
|
368 |
|
369 |
+
next_invoice_amount = preview_invoice.get('amount_due') / 100 if preview_invoice and preview_invoice.get('amount_due') else None
|
370 |
logger.info(f"Calculated next_invoice_amount: {next_invoice_amount}")
|
371 |
|
372 |
except stripe.error.StripeError as e:
|
373 |
+
logger.error(f"Stripe error getting preview invoice: {str(e)}")
|
374 |
logger.error(f"Stripe error type: {type(e)}")
|
375 |
next_invoice_amount = None
|
376 |
except Exception as e:
|
377 |
+
logger.error(f"General error getting preview invoice: {str(e)}")
|
378 |
logger.error(f"Error type: {type(e)}")
|
379 |
next_invoice_amount = None
|
380 |
|