Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(billing): handle string usage limits TASK-1232 #5227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion kobo/apps/stripe/tests/test_organization_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,24 @@ def test_get_plan_community_limit(self):
def test_get_suscription_limit(self, usage_type):
stripe_key = f'{USAGE_LIMIT_MAP[usage_type]}_limit'
product_metadata = {
stripe_key: 1234,
stripe_key: '1234',
'product_type': 'plan',
'plan_type': 'enterprise',
}
generate_plan_subscription(self.organization, metadata=product_metadata)
limit = get_organization_plan_limit(self.organization, usage_type)
assert limit == 1234

# Currently submissions and storage are the only usage types that can be
# 'unlimited'
@data('submission', 'storage')
def test_get_suscription_limit_unlimited(self, usage_type):
stripe_key = f'{USAGE_LIMIT_MAP[usage_type]}_limit'
product_metadata = {
stripe_key: 'unlimited',
'product_type': 'plan',
'plan_type': 'enterprise',
}
generate_plan_subscription(self.organization, metadata=product_metadata)
limit = get_organization_plan_limit(self.organization, usage_type)
assert limit == float('inf')
9 changes: 6 additions & 3 deletions kobo/apps/stripe/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from math import ceil, floor
from math import ceil, floor, inf

from django.conf import settings
from django.db.models import F
Expand Down Expand Up @@ -44,7 +44,7 @@ def generate_return_url(product_metadata):

def get_organization_plan_limit(
organization: Organization, usage_type: UsageType
) -> int:
) -> int | float:
"""
Get organization plan limit for a given usage type
"""
Expand Down Expand Up @@ -90,5 +90,8 @@ def get_organization_plan_limit(
if relevant_limit is None:
# TODO: get the limits from the community plan, overrides
relevant_limit = 2000
# Limits in Stripe metadata are strings. They may be numbers or 'unlimited'
if relevant_limit == 'unlimited':
return inf

return relevant_limit
return int(relevant_limit)
4 changes: 2 additions & 2 deletions kobo/apps/trackers/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _make_payment(
def test_organization_usage_utils(self, usage_type):
usage_key = f'{USAGE_LIMIT_MAP[usage_type]}_limit'
sub_metadata = {
usage_key: 1000,
usage_key: '1000',
'product_type': 'plan',
'plan_type': 'enterprise',
}
Expand All @@ -97,7 +97,7 @@ def test_organization_usage_utils(self, usage_type):
)
addon_metadata = {
'product_type': 'addon_onetime',
usage_key: 2000,
usage_key: '2000',
'valid_tags': 'all',
}
product, price = self._create_product(addon_metadata)
Expand Down
Loading