habulaj commited on
Commit
d276a8d
·
verified ·
1 Parent(s): 5202b03

Update routes/subscription.py

Browse files
Files changed (1) hide show
  1. routes/subscription.py +3 -20
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", "default_payment_method", "latest_invoice"]
81
  )
82
 
83
  if not subscription:
@@ -99,25 +99,6 @@ async def subscription_details(data: SubscriptionRequest):
99
 
100
  # Método de pagamento utilizado
101
  payment_method = subscription.get("default_payment_method")
102
- payment_info = "No default payment method found"
103
-
104
- if not payment_method:
105
- latest_invoice_id = subscription.get("latest_invoice")
106
- if latest_invoice_id:
107
- latest_invoice = await async_stripe_request(
108
- stripe.Invoice.retrieve,
109
- id=latest_invoice_id,
110
- expand=["payment_intent"]
111
- )
112
- payment_intent_id = latest_invoice.get("payment_intent")
113
- if payment_intent_id:
114
- payment_intent = await async_stripe_request(
115
- stripe.PaymentIntent.retrieve,
116
- id=payment_intent_id,
117
- expand=["payment_method"]
118
- )
119
- payment_method = payment_intent.get("payment_method")
120
-
121
  if payment_method:
122
  payment_method_details = await async_stripe_request(
123
  stripe.PaymentMethod.retrieve,
@@ -126,6 +107,8 @@ async def subscription_details(data: SubscriptionRequest):
126
  payment_type = payment_method_details["type"]
127
  last4 = payment_method_details[payment_type].get("last4", "N/A")
128
  payment_info = f"{payment_type.upper()} ending in {last4}"
 
 
129
 
130
  return {
131
  "status": "success",
 
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:
 
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,
 
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",