Update routes/subscription.py
Browse files- routes/subscription.py +16 -2
routes/subscription.py
CHANGED
@@ -77,7 +77,7 @@ async def subscription_details(data: SubscriptionRequest):
|
|
77 |
subscription = await async_stripe_request(
|
78 |
stripe.Subscription.retrieve,
|
79 |
id=subscription_id,
|
80 |
-
expand=["items.data.price"]
|
81 |
)
|
82 |
|
83 |
if not subscription:
|
@@ -97,12 +97,26 @@ async def subscription_details(data: SubscriptionRequest):
|
|
97 |
)
|
98 |
next_invoice_amount = upcoming_invoice["amount_due"] / 100 if upcoming_invoice else None
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
return {
|
101 |
"status": "success",
|
102 |
"subscription_id": subscription_id,
|
103 |
"current_price": f"{current_price} {currency}",
|
104 |
"next_invoice_amount": f"{next_invoice_amount} {currency}" if next_invoice_amount else "N/A",
|
105 |
-
"next_billing_date": next_billing_date
|
|
|
106 |
}
|
107 |
|
108 |
except stripe.error.StripeError as e:
|
|
|
77 |
subscription = await async_stripe_request(
|
78 |
stripe.Subscription.retrieve,
|
79 |
id=subscription_id,
|
80 |
+
expand=["items.data.price", "default_payment_method"]
|
81 |
)
|
82 |
|
83 |
if not subscription:
|
|
|
97 |
)
|
98 |
next_invoice_amount = upcoming_invoice["amount_due"] / 100 if upcoming_invoice else None
|
99 |
|
100 |
+
# Método de pagamento utilizado
|
101 |
+
payment_method = subscription.get("default_payment_method")
|
102 |
+
if payment_method:
|
103 |
+
payment_method_details = await async_stripe_request(
|
104 |
+
stripe.PaymentMethod.retrieve,
|
105 |
+
id=payment_method
|
106 |
+
)
|
107 |
+
payment_type = payment_method_details["type"]
|
108 |
+
last4 = payment_method_details[payment_type].get("last4", "N/A")
|
109 |
+
payment_info = f"{payment_type.upper()} ending in {last4}"
|
110 |
+
else:
|
111 |
+
payment_info = "No default payment method found"
|
112 |
+
|
113 |
return {
|
114 |
"status": "success",
|
115 |
"subscription_id": subscription_id,
|
116 |
"current_price": f"{current_price} {currency}",
|
117 |
"next_invoice_amount": f"{next_invoice_amount} {currency}" if next_invoice_amount else "N/A",
|
118 |
+
"next_billing_date": next_billing_date,
|
119 |
+
"payment_method": payment_info
|
120 |
}
|
121 |
|
122 |
except stripe.error.StripeError as e:
|