feat: prod ready
This commit is contained in:
@@ -7,7 +7,8 @@ from src.application.contracts import ICache,ILogger
|
|||||||
from src.application.contracts import IItPayService
|
from src.application.contracts import IItPayService
|
||||||
from src.application.domain.entities.order import OrderEntity
|
from src.application.domain.entities.order import OrderEntity
|
||||||
from src.application.domain.enums import OrderStatus
|
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.infrastructure.database.decorators import transactional
|
||||||
from src.presentation.schemas.order import CreateOrder
|
from src.presentation.schemas.order import CreateOrder
|
||||||
|
|
||||||
@@ -38,17 +39,15 @@ class CreateOrderCommand:
|
|||||||
|
|
||||||
if rate_raw is None:
|
if rate_raw is None:
|
||||||
self._logger.error('Exchange rate unavailable')
|
self._logger.error('Exchange rate unavailable')
|
||||||
|
raise ServiceUnavailableException(message='Exchange rate unavailable')
|
||||||
|
|
||||||
if gas_raw is None:
|
if gas_raw is None:
|
||||||
self._logger.error('Exchange gas unavailable')
|
self._logger.error('Exchange gas unavailable')
|
||||||
|
raise ServiceUnavailableException(message='Exchange gas unavailable')
|
||||||
rate_raw = '2.00'
|
|
||||||
gas_raw = '1.00'
|
|
||||||
self._logger.info(f'Mocked market values: rate={rate_raw}, gas={gas_raw}')
|
|
||||||
|
|
||||||
actual_gas_fee = Decimal(gas_raw).quantize(Decimal('0.00'), rounding=ROUND_UP)
|
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_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'))
|
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'):
|
if actual_total_price > payment_data.total_price * Decimal('1.01'):
|
||||||
self._logger.error('Price has changed, please refresh and try again')
|
self._logger.error('Price has changed, please refresh and try again')
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import List, Literal
|
from typing import List, Literal
|
||||||
import os
|
import os
|
||||||
@@ -94,6 +95,8 @@ class Settings(BaseSettings):
|
|||||||
ITPAY_PUBLIC_ID: str
|
ITPAY_PUBLIC_ID: str
|
||||||
ITPAY_API_SECRET: str
|
ITPAY_API_SECRET: str
|
||||||
|
|
||||||
|
PAYMENT_SERVICE_FEE_RATE: Decimal = Field(gt=0)
|
||||||
|
|
||||||
CLOUD_KASSIR_PUBLIC_ID: str = ''
|
CLOUD_KASSIR_PUBLIC_ID: str = ''
|
||||||
CLOUD_KASSIR_API_SECRET: str = ''
|
CLOUD_KASSIR_API_SECRET: str = ''
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,11 @@ order_router = APIRouter(prefix='/order', tags=['orders'])
|
|||||||
#@csrf_protect()
|
#@csrf_protect()
|
||||||
async def create_order(
|
async def create_order(
|
||||||
payment_data: CreateOrder,
|
payment_data: CreateOrder,
|
||||||
#auth: AuthContext = Depends(require_access_token),
|
auth: AuthContext = Depends(require_access_token),
|
||||||
command: CreateOrderCommand = Depends(get_create_order_command),
|
command: CreateOrderCommand = Depends(get_create_order_command),
|
||||||
logger: ILogger = Depends(get_logger),
|
logger: ILogger = Depends(get_logger),
|
||||||
) -> CreateOrderResponse:
|
) -> CreateOrderResponse:
|
||||||
#o = await command(payment_data, auth.user_id)
|
o = await command(payment_data, auth.user_id)
|
||||||
o = await command(payment_data, '01KPKAFN6J1NJBY15DX8JE2QYB')
|
|
||||||
itpay_error = o.status in (
|
itpay_error = o.status in (
|
||||||
OrderStatus.CANCELLED,
|
OrderStatus.CANCELLED,
|
||||||
OrderStatus.REJECTED,
|
OrderStatus.REJECTED,
|
||||||
|
|||||||
Reference in New Issue
Block a user