Skip to content

Commit a47170e

Browse files
committed
add endpoint for additional minute pricing
1 parent fc34ef6 commit a47170e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

backend/btrixcloud/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,14 @@ class SubscriptionPortalUrlResponse(BaseModel):
19781978
portalUrl: str = ""
19791979

19801980

1981+
# ============================================================================
1982+
class AddonMinutesPricing(BaseModel):
1983+
"""Addon minutes pricing"""
1984+
1985+
price: float
1986+
currency: str
1987+
1988+
19811989
# ============================================================================
19821990
class CheckoutAddonMinutesRequest(BaseModel):
19831991
"""Request for additional minutes checkout session"""

backend/btrixcloud/subs.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .users import UserManager
1616
from .utils import is_bool, get_origin
1717
from .models import (
18+
AddonMinutesPricing,
1819
CheckoutAddonMinutesRequest,
1920
CheckoutAddonMinutesResponse,
2021
SubscriptionCreate,
@@ -380,6 +381,27 @@ async def get_billing_portal_url(
380381

381382
return SubscriptionPortalUrlResponse()
382383

384+
async def get_execution_minutes_price(self, org: Organization):
385+
if not org.subscription:
386+
raise HTTPException(
387+
status_code=404, detail="Organization has no subscription"
388+
)
389+
if external_subs_app_api_url:
390+
try:
391+
async with aiohttp.ClientSession() as session:
392+
async with session.request(
393+
"GET",
394+
f"{external_subs_app_api_url}/prices/additionalMinutes",
395+
headers={
396+
"Authorization": "bearer " + external_subs_app_api_key
397+
},
398+
raise_for_status=True,
399+
) as resp:
400+
text = await resp.text()
401+
return AddonMinutesPricing.model_validate_json(text)
402+
except Exception as exc:
403+
print("Error fetching checkout url", exc)
404+
383405
async def get_checkout_url(self, org: Organization, minutes: int | None):
384406
if not org.subscription:
385407
raise HTTPException(
@@ -530,6 +552,16 @@ async def get_billing_portal_url(
530552
):
531553
return await ops.get_billing_portal_url(org, dict(request.headers))
532554

555+
@org_ops.router.get(
556+
"/price/execution-minutes",
557+
tags=["organizations"],
558+
response_model=PriceResponse,
559+
)
560+
async def get_execution_minutes_price(
561+
org: Organization = Depends(org_ops.org_owner_dep),
562+
):
563+
return await ops.get_execution_minutes_price(org)
564+
533565
@org_ops.router.get(
534566
"/checkout/execution-minutes",
535567
tags=["organizations"],

0 commit comments

Comments
 (0)