feat: prod ready

This commit is contained in:
2026-05-11 14:53:28 +03:00
parent 10ff2a510d
commit 3f13032be1
3 changed files with 10 additions and 9 deletions

View File

@@ -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')

View File

@@ -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 = ''

View File

@@ -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,