feat: add Didox service integration for company info retrieval
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 2m9s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 2m9s
This commit is contained in:
@@ -73,6 +73,9 @@ STORAGE_BUCKET_STATIC=name
|
||||
STORAGE_PATH=127.0.0.1:8081/bucket/
|
||||
STORAGE_PROTOCOL=http:
|
||||
|
||||
# Didox configs
|
||||
DIDOX_PARTNER_TOKEN=...
|
||||
|
||||
|
||||
|
||||
# Celery configs
|
||||
@@ -9,7 +9,7 @@ import environ
|
||||
environ.Env.read_env(os.path.join(".env"))
|
||||
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False),
|
||||
DEBUG=(bool, True),
|
||||
CACHE_TIME=(int, 180),
|
||||
OTP_EXPIRE_TIME=(int, 2),
|
||||
VITE_LIVE=(bool, False),
|
||||
@@ -26,4 +26,5 @@ env = environ.Env(
|
||||
OTP_SERVICE="EskizService",
|
||||
PROJECT_ENV=(str, "prod"),
|
||||
SILK_ENABLED=(bool, False),
|
||||
DIDOX_PARTNER_TOKEN=(str),
|
||||
)
|
||||
|
||||
@@ -49,6 +49,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django.contrib.postgres",
|
||||
] + APPS
|
||||
|
||||
MODULES = [app for app in MODULES if isinstance(app, str)]
|
||||
@@ -165,6 +166,8 @@ SITE_URL = env.str("SITE_URL", default="http://localhost:8055")
|
||||
MODELTRANSLATION_LANGUAGES = ("uz", "ru", "en")
|
||||
MODELTRANSLATION_DEFAULT_LANGUAGE = "uz"
|
||||
|
||||
DIDOX_PARTNER_TOKEN = env.str("DIDOX_PARTNER_TOKEN")
|
||||
|
||||
|
||||
|
||||
JST_LANGUAGES = [
|
||||
|
||||
@@ -26,6 +26,7 @@ from .views import (
|
||||
AutoEvaluationListAppraisersView,
|
||||
AutoEvaluationSetAppraisersView,
|
||||
AutoEvaluationRemoveAppraisersView,
|
||||
DidoxCompanyInfoAPIView,
|
||||
|
||||
)
|
||||
|
||||
@@ -60,4 +61,9 @@ urlpatterns = [
|
||||
path("<int:id>/remove/", AutoEvaluationRemoveAppraisersView.as_view(), name="auto-evaluation-remove-appraisers"),
|
||||
]
|
||||
)),
|
||||
path(
|
||||
"didox/info/<int:tin>/",
|
||||
DidoxCompanyInfoAPIView.as_view(),
|
||||
name="didox-info"
|
||||
),
|
||||
]
|
||||
|
||||
@@ -11,3 +11,4 @@ from .report import * # noqa
|
||||
from .request import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .didox import * # noqa
|
||||
|
||||
51
core/apps/evaluation/views/didox.py
Normal file
51
core/apps/evaluation/views/didox.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.generics import GenericAPIView
|
||||
|
||||
|
||||
from drf_spectacular.utils import extend_schema, OpenApiParameter
|
||||
|
||||
from core.services.didox import DidoxService
|
||||
|
||||
|
||||
class DidoxCompanyInfoAPIView(GenericAPIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
@extend_schema(
|
||||
tags=["Didox"],
|
||||
summary="Get company info by TIN",
|
||||
description="TIN/JSHSHIR orqali Didoxdan ma'lumot olish",
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
name="tin",
|
||||
type=int,
|
||||
location=OpenApiParameter.PATH,
|
||||
required=True,
|
||||
description="TIN / STIR / INN / JSHSHIR"
|
||||
)
|
||||
],
|
||||
responses={200: dict},
|
||||
)
|
||||
def get(self, request, *args, **kwargs):
|
||||
tin = kwargs.get("tin")
|
||||
|
||||
# 🔥 TYPE CHECK
|
||||
try:
|
||||
tin = int(tin)
|
||||
except (TypeError, ValueError):
|
||||
return Response(
|
||||
{"detail": "TIN must be a valid integer"},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
data = DidoxService.get_company_info(tin)
|
||||
|
||||
if not data:
|
||||
return Response(
|
||||
{"detail": "Didox service unavailable"},
|
||||
status=status.HTTP_502_BAD_GATEWAY
|
||||
)
|
||||
|
||||
return Response(data, status=status.HTTP_200_OK)
|
||||
@@ -1,3 +1,4 @@
|
||||
from .otp import * # noqa
|
||||
from .sms import * # noqa
|
||||
from .user import * # noqa
|
||||
from .didox import * # noqa
|
||||
27
core/services/didox.py
Normal file
27
core/services/didox.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import requests
|
||||
from django.conf import settings
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DidoxService:
|
||||
BASE_URL = "https://testapi3.didox.uz/v1"
|
||||
|
||||
@classmethod
|
||||
def get_company_info(cls, tin: int) -> dict:
|
||||
url = f"{cls.BASE_URL}/utils/info/{tin}"
|
||||
|
||||
headers = {"Partner-Authorization": settings.DIDOX_PARTNER_TOKEN}
|
||||
|
||||
try:
|
||||
response = requests.get(url=url, headers=headers, timeout=15,verify=False)
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
return response.json()
|
||||
|
||||
except requests.RequestException as e:
|
||||
logger.exception(f"Didox API error: {str(e)}")
|
||||
return {}
|
||||
Reference in New Issue
Block a user