Repository: aipotheosis-labs/aci
File: backend/aci/server/routes/billing.py (Python)

Code before:
async def get_subscription(
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    user: Annotated[User, Depends(auth.require_user)],
) -> SubscriptionPublic:
    acl.require_org_member(user, org_id)

    subscription = billing.get_subscription_by_org_id(db_session, org_id)
    return SubscriptionPublic(
        plan=subscription.plan.name,
        status=subscription.status,
    )


@router.get("/quota-usage", response_model=QuotaUsageResponse)
async def get_quota_usage(
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    user: Annotated[User, Depends(auth.require_user)],
) -> QuotaUsageResponse:
    """
    get quota usage for an org

    Returns:
        QuotaUsageResponse: include all quota usage information
    """
    acl.require_org_member(user, org_id)

    return quota_manager.get_quota_usage(db_session, org_id)


@router.post("/create-checkout-session")
async def create_checkout_session(
    user: Annotated[User, Depends(auth.require_user)],
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    body: Annotated[StripeCheckoutSessionCreate, Body()],
) -> str:
    acl.require_org_member_with_minimum_role(user, org_id, OrganizationRole.ADMIN)

    plan = crud.plans.get_by_name(db_session, body.plan_name)
    if not plan:
        logger.error(
            "plan not found",
            extra={"plan_name": body.plan_name},
        )
        raise SubscriptionPlanNotFound(f"plan={body.plan_name} not found")

    price_id = (
        plan.stripe_monthly_price_id
        if body.interval == StripeSubscriptionInterval.MONTH

Review comment (suggestion):
The type hints and function name is clear enough, this comment doesn't offer any new info.
```suggestion
```

Code after:
@router.get("/get-subscription", response_model=SubscriptionPublic)
async def get_subscription(
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    user: Annotated[User, Depends(auth.require_user)],
) -> SubscriptionPublic:
    acl.require_org_member(user, org_id)

    subscription = billing.get_subscription_by_org_id(db_session, org_id)
    return SubscriptionPublic(
        plan=subscription.plan.name,
        status=subscription.status,
    )


@router.get("/quota-usage", response_model=QuotaUsageResponse)
async def get_quota_usage(
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    user: Annotated[User, Depends(auth.require_user)],
) -> QuotaUsageResponse:
    acl.require_org_member(user, org_id)

    subscription = billing.get_subscription_by_org_id(db_session, org_id)
    plan = subscription.plan
    logger.info("getting quota usage", extra={"org_id": org_id, "plan": plan.name})

    projects_used = len(crud.projects.get_projects_by_org(db_session, org_id))
    agent_credentials_used = crud.secret.get_total_number_of_agent_secrets_for_org(
        db_session, org_id
    )
    linked_accounts_used = crud.linked_accounts.get_total_number_of_unique_linked_account_owner_ids(
        db_session, org_id
    )

    return QuotaUsageResponse(
        projects_used=projects_used,
        linked_accounts_used=linked_accounts_used,
        agent_credentials_used=agent_credentials_used,
        plan=PlanInfo(name=plan.name, features=PlanFeatures(**plan.features)),
    )


@router.post("/create-checkout-session")
async def create_checkout_session(
    user: Annotated[User, Depends(auth.require_user)],
    db_session: Annotated[Session, Depends(deps.yield_db_session)],
    org_id: Annotated[UUID, Header(alias="X-ACI-ORG-ID")],
    body: Annotated[StripeCheckoutSessionCreate, Body()],
) -> str:
    acl.require_org_member_with_minimum_role(user, org_id, OrganizationRole.ADMIN)