Skip to content

Commit

Permalink
Make sure get_subscription() to return only one subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshinishio committed Jan 23, 2025
1 parent ee3f18c commit 19ba47e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 19 additions & 3 deletions services/stripe/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,25 @@ def create_stripe_customer(


@handle_exceptions(raise_on_error=True)
def get_subscription(customer_id: str) -> stripe.ListObject[stripe.Subscription]:
subscriptions = stripe.Subscription.list(customer=customer_id, status="active")
return subscriptions
def get_subscription(customer_id: str):
response = stripe.Subscription.list(customer=customer_id, status="active")
subscriptions = response.data

# Get all subscriptions if there are more pages
while response.has_more:
response = stripe.Subscription.list(
customer=customer_id,
status="active",
starting_after=subscriptions[-1].id,
)
subscriptions.extend(response.data)

# If multiple subscriptions exist, return only the highest priced one
if len(subscriptions) > 1:
highest_subscription = max(subscriptions, key=lambda x: x.plan.amount)
response.data = [highest_subscription]

return response


@handle_exceptions(default_return_value=FREE_TIER_REQUEST_AMOUNT, raise_on_error=False)
Expand Down
1 change: 0 additions & 1 deletion services/supabase/users_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def get_how_many_requests_left_and_cycle(
request_limit = (
base_request_limit * 12 if interval == "year" else base_request_limit
)

start_date = datetime.fromtimestamp(timestamp=start_date_seconds, tz=TZ)
end_date = datetime.fromtimestamp(timestamp=end_date_seconds, tz=TZ)

Expand Down

0 comments on commit 19ba47e

Please sign in to comment.