From 1a2f37e7c7e745f2a021dbe1608253a32e1b6e91 Mon Sep 17 00:00:00 2001 From: hj24 Date: Thu, 18 Dec 2025 10:33:25 +0800 Subject: [PATCH] feat: add billing subscription plan api --- api/services/billing_service.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/services/billing_service.py b/api/services/billing_service.py index 8bd4e7814e..0eb661a610 100644 --- a/api/services/billing_service.py +++ b/api/services/billing_service.py @@ -4,6 +4,7 @@ from collections.abc import Sequence from typing import Literal, TypedDict import httpx +from pydantic import TypeAdapter from tenacity import retry, retry_if_exception_type, stop_before_delay, wait_fixed from werkzeug.exceptions import InternalServerError @@ -287,6 +288,7 @@ class BillingService: Mapping of tenant_id -> {plan: str, expiration_date: int} """ results: dict[str, SubscriptionPlan] = {} + subscription_adapter = TypeAdapter(SubscriptionPlan) chunk_size = 200 for i in range(0, len(tenant_ids), chunk_size): @@ -294,13 +296,10 @@ class BillingService: try: resp = cls._send_request("POST", "/subscription/plan/batch", json={"tenant_ids": chunk}) data = resp.get("data", {}) + for tenant_id, plan in data.items(): - if isinstance(plan, dict) and "plan" in plan and "expiration_date" in plan: - subscription_plan: SubscriptionPlan = { - "plan": str(plan["plan"]), - "expiration_date": int(plan["expiration_date"]), - } - results[tenant_id] = subscription_plan + subscription_plan = subscription_adapter.validate_python(plan) + results[tenant_id] = subscription_plan except Exception: logger.exception("Failed to fetch billing info batch for tenants: %s", chunk) continue