|
15 | 15 | from .users import UserManager |
16 | 16 | from .utils import is_bool, get_origin |
17 | 17 | from .models import ( |
| 18 | + AddonMinutesPricing, |
18 | 19 | CheckoutAddonMinutesRequest, |
19 | 20 | CheckoutAddonMinutesResponse, |
20 | 21 | SubscriptionCreate, |
@@ -380,6 +381,27 @@ async def get_billing_portal_url( |
380 | 381 |
|
381 | 382 | return SubscriptionPortalUrlResponse() |
382 | 383 |
|
| 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 | + |
383 | 405 | async def get_checkout_url(self, org: Organization, minutes: int | None): |
384 | 406 | if not org.subscription: |
385 | 407 | raise HTTPException( |
@@ -530,6 +552,16 @@ async def get_billing_portal_url( |
530 | 552 | ): |
531 | 553 | return await ops.get_billing_portal_url(org, dict(request.headers)) |
532 | 554 |
|
| 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 | + |
533 | 565 | @org_ops.router.get( |
534 | 566 | "/checkout/execution-minutes", |
535 | 567 | tags=["organizations"], |
|
0 commit comments