feat: updating order status
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
from decimal import Decimal
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import ILogger,IReceipt
|
||||
from src.application.domain.enums import PaymentStatus
|
||||
from src.application.domain.enums import OrderStatus,PaymentStatus
|
||||
from src.application.domain.exceptions import ApplicationException,NotFoundException,PaymentMetadataException,ReceiptDataException
|
||||
from src.infrastructure.database.decorators import transactional
|
||||
|
||||
@@ -91,3 +91,13 @@ class CreateCryptoTransferCompletedCommand:
|
||||
receipt_cloudekassir_id=str(receipt_model.get('Id') or '') or None,
|
||||
receipt_cloudekassir_link=str(receipt_model.get('ReceiptLocalUrl') or '') or None,
|
||||
)
|
||||
await self._unit_of_work.order_repository.update_status(
|
||||
order_id=order_id,
|
||||
status=OrderStatus.COMPLETED,
|
||||
)
|
||||
self._logger.info({
|
||||
'event': 'order_status_changed',
|
||||
'order_id': order_id,
|
||||
'user_id': user_id,
|
||||
'status': OrderStatus.COMPLETED.value,
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
from ulid import ULID
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import ILogger,IQueueMessanger
|
||||
from src.application.domain.enums import PaymentStatus
|
||||
from src.application.domain.enums import OrderStatus
|
||||
from src.application.domain.exceptions import PaymentMetadataException
|
||||
from src.infrastructure.config import settings
|
||||
from src.infrastructure.database.decorators import transactional
|
||||
@@ -15,6 +15,20 @@ class CreatePaymentCommand:
|
||||
self._logger = logger
|
||||
self._queue_messanger = queue_messanger
|
||||
|
||||
|
||||
async def _mark_order_completed(self, order_id: str, user_id: str) -> None:
|
||||
await self._unit_of_work.order_repository.update_status(
|
||||
order_id=order_id,
|
||||
status=OrderStatus.COMPLETED,
|
||||
)
|
||||
self._logger.info({
|
||||
'event': 'order_status_changed',
|
||||
'order_id': order_id,
|
||||
'user_id': user_id,
|
||||
'status': OrderStatus.COMPLETED.value,
|
||||
})
|
||||
|
||||
|
||||
@transactional
|
||||
async def __call__(self, payment: ItpayPaymentData) -> None:
|
||||
if str(payment.status).strip().lower() != 'completed':
|
||||
@@ -38,7 +52,14 @@ class CreatePaymentCommand:
|
||||
expired_date=str(payment.expired_date) if payment.expired_date is not None else None,
|
||||
)
|
||||
if not payment_created:
|
||||
await self._mark_order_completed(order_id, user_id)
|
||||
return
|
||||
await self._mark_order_completed(order_id, user_id)
|
||||
self._logger.info({
|
||||
'event': 'payment_money_accepted',
|
||||
'order_id': order_id,
|
||||
'user_id': user_id,
|
||||
})
|
||||
message_id = str(ULID())
|
||||
message: dict[str,str] = {
|
||||
'order_id': order_id,
|
||||
@@ -71,13 +92,3 @@ class CreatePaymentCommand:
|
||||
'user_id': user_id,
|
||||
'message_id': message_id,
|
||||
})
|
||||
await self._unit_of_work.payment_repository.update_status(
|
||||
order_id=order_id,
|
||||
status=PaymentStatus.WEB3_PROCESSING,
|
||||
)
|
||||
self._logger.info({
|
||||
'event': 'payment_status_changed',
|
||||
'order_id': order_id,
|
||||
'user_id': user_id,
|
||||
'status': PaymentStatus.WEB3_PROCESSING.value,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user