From 3f13032be1a88dbc95face397de44adfbb0bfe22 Mon Sep 17 00:00:00 2001 From: Noloquideus Date: Mon, 11 May 2026 14:53:28 +0300 Subject: [PATCH] feat: prod ready --- src/application/commands/create_order_command.py | 11 +++++------ src/infrastructure/config/settings.py | 3 +++ src/presentation/routing/order.py | 5 ++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/application/commands/create_order_command.py b/src/application/commands/create_order_command.py index f4aba3b..6a0d4c6 100644 --- a/src/application/commands/create_order_command.py +++ b/src/application/commands/create_order_command.py @@ -7,7 +7,8 @@ from src.application.contracts import ICache,ILogger from src.application.contracts import IItPayService from src.application.domain.entities.order import OrderEntity from src.application.domain.enums import OrderStatus -from src.application.domain.exceptions import ApplicationException +from src.application.domain.exceptions import ApplicationException,ServiceUnavailableException +from src.infrastructure.config import settings from src.infrastructure.database.decorators import transactional from src.presentation.schemas.order import CreateOrder @@ -38,17 +39,15 @@ class CreateOrderCommand: if rate_raw is None: self._logger.error('Exchange rate unavailable') + raise ServiceUnavailableException(message='Exchange rate unavailable') if gas_raw is None: self._logger.error('Exchange gas unavailable') - - rate_raw = '2.00' - gas_raw = '1.00' - self._logger.info(f'Mocked market values: rate={rate_raw}, gas={gas_raw}') + raise ServiceUnavailableException(message='Exchange gas unavailable') actual_gas_fee = Decimal(gas_raw).quantize(Decimal('0.00'), rounding=ROUND_UP) actual_usdt_exchange_rate = Decimal(rate_raw).quantize(Decimal('0.00'), rounding=ROUND_UP) - actual_service_fee = (payment_data.usdt_amount * actual_usdt_exchange_rate * Decimal('0.04')).quantize(Decimal('0.01')) + actual_service_fee = (payment_data.usdt_amount * actual_usdt_exchange_rate * settings.PAYMENT_SERVICE_FEE_RATE).quantize(Decimal('0.01')) actual_total_price = (payment_data.usdt_amount * actual_usdt_exchange_rate + actual_service_fee + actual_gas_fee).quantize(Decimal('0.01')) if actual_total_price > payment_data.total_price * Decimal('1.01'): self._logger.error('Price has changed, please refresh and try again') diff --git a/src/infrastructure/config/settings.py b/src/infrastructure/config/settings.py index 92f0316..affc5c5 100644 --- a/src/infrastructure/config/settings.py +++ b/src/infrastructure/config/settings.py @@ -1,5 +1,6 @@ from __future__ import annotations +from decimal import Decimal from functools import lru_cache from typing import List, Literal import os @@ -94,6 +95,8 @@ class Settings(BaseSettings): ITPAY_PUBLIC_ID: str ITPAY_API_SECRET: str + PAYMENT_SERVICE_FEE_RATE: Decimal = Field(gt=0) + CLOUD_KASSIR_PUBLIC_ID: str = '' CLOUD_KASSIR_API_SECRET: str = '' diff --git a/src/presentation/routing/order.py b/src/presentation/routing/order.py index 5d38710..bdb0a9f 100644 --- a/src/presentation/routing/order.py +++ b/src/presentation/routing/order.py @@ -35,12 +35,11 @@ order_router = APIRouter(prefix='/order', tags=['orders']) #@csrf_protect() async def create_order( payment_data: CreateOrder, - #auth: AuthContext = Depends(require_access_token), + auth: AuthContext = Depends(require_access_token), command: CreateOrderCommand = Depends(get_create_order_command), logger: ILogger = Depends(get_logger), ) -> CreateOrderResponse: - #o = await command(payment_data, auth.user_id) - o = await command(payment_data, '01KPKAFN6J1NJBY15DX8JE2QYB') + o = await command(payment_data, auth.user_id) itpay_error = o.status in ( OrderStatus.CANCELLED, OrderStatus.REJECTED,