- Backend: N8N_AUTH_WEBHOOK из env (fallback), банки из BANK_IP, эндпоинт /api/v1/profile/dadata/address для подсказок адресов (FORMA_DADATA_*). - Config: bank_ip, bank_api_url, forma_dadata_api_key, forma_dadata_secret. - Frontend Profile: DatePicker для даты рождения, ИНН 12 цифр + ссылка на ФНС, валидация email, чекбокс «Совпадает с адресом регистрации», AutoComplete адресов через DaData, Select банков из /api/v1/banks/nspk (bankId/bankName). Подробности в CHANGELOG_PROFILE_VALIDATION.md.
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""
|
|
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 (BANK_IP в .env или nspk_banks_api_url).
|
|
"""
|
|
external_api_url = (getattr(settings, "bank_ip", None) or getattr(settings, "bank_api_url", None) or "").strip() or "http://212.193.27.93/api/payouts/dictionaries/nspk-banks"
|
|
try:
|
|
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)}"
|
|
)
|
|
|
|
|
|
|
|
|