diff --git a/.env.example b/.env.example index 1668f49..d97cac4 100644 --- a/.env.example +++ b/.env.example @@ -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 \ No newline at end of file diff --git a/config/env.py b/config/env.py index d9236a1..6a62631 100644 --- a/config/env.py +++ b/config/env.py @@ -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), ) diff --git a/config/settings/common.py b/config/settings/common.py index e15cd00..e0d244b 100644 --- a/config/settings/common.py +++ b/config/settings/common.py @@ -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 = [ diff --git a/core/apps/evaluation/urls.py b/core/apps/evaluation/urls.py index 014fc69..7e1446f 100644 --- a/core/apps/evaluation/urls.py +++ b/core/apps/evaluation/urls.py @@ -26,6 +26,7 @@ from .views import ( AutoEvaluationListAppraisersView, AutoEvaluationSetAppraisersView, AutoEvaluationRemoveAppraisersView, + DidoxCompanyInfoAPIView, ) @@ -60,4 +61,9 @@ urlpatterns = [ path("/remove/", AutoEvaluationRemoveAppraisersView.as_view(), name="auto-evaluation-remove-appraisers"), ] )), + path( + "didox/info//", + DidoxCompanyInfoAPIView.as_view(), + name="didox-info" + ), ] diff --git a/core/apps/evaluation/views/__init__.py b/core/apps/evaluation/views/__init__.py index a625148..db1c0e4 100644 --- a/core/apps/evaluation/views/__init__.py +++ b/core/apps/evaluation/views/__init__.py @@ -11,3 +11,4 @@ from .report import * # noqa from .request import * # noqa from .valuation import * # noqa from .vehicle import * # noqa +from .didox import * # noqa diff --git a/core/apps/evaluation/views/didox.py b/core/apps/evaluation/views/didox.py new file mode 100644 index 0000000..f327e6d --- /dev/null +++ b/core/apps/evaluation/views/didox.py @@ -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) \ No newline at end of file diff --git a/core/services/__init__.py b/core/services/__init__.py index fdaf3ce..3ed12bd 100644 --- a/core/services/__init__.py +++ b/core/services/__init__.py @@ -1,3 +1,4 @@ from .otp import * # noqa from .sms import * # noqa from .user import * # noqa +from .didox import * # noqa \ No newline at end of file diff --git a/core/services/didox.py b/core/services/didox.py new file mode 100644 index 0000000..9096460 --- /dev/null +++ b/core/services/didox.py @@ -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 {}