""" Banks API - получение списка банков СБП """ from fastapi import APIRouter, HTTPException import httpx import logging from ..config import settings logger = logging.getLogger(__name__) router = APIRouter(prefix="/api/v1/banks", tags=["Banks"]) @router.get("/nspk") async def get_nspk_banks(): """ Получить список банков СБП из внешнего API Проксирует запрос для избежания Mixed Content ошибок (HTTPS -> HTTP) """ try: # URL внешнего API external_api_url = "http://212.193.27.93/api/payouts/dictionaries/nspk-banks" async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get(external_api_url) if response.status_code != 200: logger.error(f"Failed to fetch banks: HTTP {response.status_code}") raise HTTPException( status_code=response.status_code, detail=f"Failed to fetch banks list: {response.status_code}" ) banks_data = response.json() logger.info(f"✅ Loaded {len(banks_data)} banks from external API") return banks_data except httpx.TimeoutException: logger.error("Timeout while fetching banks") raise HTTPException( status_code=504, detail="Timeout while fetching banks list" ) except httpx.RequestError as e: logger.error(f"Request error while fetching banks: {e}") raise HTTPException( status_code=502, detail=f"Failed to connect to banks API: {str(e)}" ) except Exception as e: logger.error(f"Unexpected error while fetching banks: {e}") raise HTTPException( status_code=500, detail=f"Internal error: {str(e)}" )