From 195c0a8e53a05cd7be93a1d5e6373e9401d5a9b8 Mon Sep 17 00:00:00 2001 From: Noloquideus Date: Sat, 9 May 2026 10:42:25 +0300 Subject: [PATCH] fix: agent 4 to 6 --- .../repositories/i_payment_repository.py | 5 +++++ .../commands/create_payment_cloudkassir_command.py | 10 +++++++++- src/application/domain/entities/payment.py | 1 + src/infrastructure/cloud_kassir/client.py | 8 ++++---- src/infrastructure/database/models/payment.py | 3 ++- .../database/repositories/payment_repository.py | 12 ++++++++++++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/application/abstractions/repositories/i_payment_repository.py b/src/application/abstractions/repositories/i_payment_repository.py index 887c429..acbc99b 100644 --- a/src/application/abstractions/repositories/i_payment_repository.py +++ b/src/application/abstractions/repositories/i_payment_repository.py @@ -6,3 +6,8 @@ class IPaymentRepository(ABC): async def create_completed(self,*,user_id:str,order_id:str,itpay_payment_id:str,itpay_paid_amount:str|None,transaction_id:str|None,paid_at:str|None,expired_date:str|None) -> None: raise NotImplementedError + + @abstractmethod + async def update_receipt(self,*,order_id:str,receipt_cloudekassir_id:str|None,receipt_cloudekassir_link:str|None) -> None: + raise NotImplementedError + diff --git a/src/application/commands/create_payment_cloudkassir_command.py b/src/application/commands/create_payment_cloudkassir_command.py index 83b30f6..fa46376 100644 --- a/src/application/commands/create_payment_cloudkassir_command.py +++ b/src/application/commands/create_payment_cloudkassir_command.py @@ -93,7 +93,7 @@ class CreatePaymentCloudkassirCommand: if paid_total is not None and abs(total_amount - paid_total) > Decimal('0.02'): raise ApplicationException(status_code=400, message='Receipt total does not match paid amount') - await self._receipt.create_receipt( + receipt_response = await self._receipt.create_receipt( order_id=order_id, user_id=user_id, email=email, @@ -102,3 +102,11 @@ class CreatePaymentCloudkassirCommand: service_fee=service_fee, request_id=str(ULID()), ) + receipt_model = receipt_response.get('Model') + if not isinstance(receipt_model, dict): + receipt_model = {} + await self._unit_of_work.payment_repository.update_receipt( + order_id=order_id, + receipt_cloudekassir_id=str(receipt_model.get('Id') or '') or None, + receipt_cloudekassir_link=str(receipt_model.get('ReceiptLocalUrl') or '') or None, + ) diff --git a/src/application/domain/entities/payment.py b/src/application/domain/entities/payment.py index 6c9461b..61d83fc 100644 --- a/src/application/domain/entities/payment.py +++ b/src/application/domain/entities/payment.py @@ -12,6 +12,7 @@ class PaymentEntity: order_id: str | None = None status: PaymentStatus | None = None + receipt_cloudekassir_id: str | None = None receipt_cloudekassir_link: str | None = None itpay_payment_id: str | None = None diff --git a/src/infrastructure/cloud_kassir/client.py b/src/infrastructure/cloud_kassir/client.py index a24bd4d..78d24aa 100644 --- a/src/infrastructure/cloud_kassir/client.py +++ b/src/infrastructure/cloud_kassir/client.py @@ -68,10 +68,10 @@ class ClaudeKassirClient(IReceipt): 'amount': float(principal), 'vat': 0, 'method': 4, - 'object': 4, + 'object': 1, 'measurement_unit': 'шт', 'agent_info': { - 'type': 4, + 'type': 6, }, 'supplier_info': { 'name': 'Принципал', @@ -86,7 +86,7 @@ class ClaudeKassirClient(IReceipt): 'amount': float(fee), 'vat': 0, 'method': 4, - 'object': 1, + 'object': 4, 'measurement_unit': 'шт', }, ], @@ -99,7 +99,7 @@ class ClaudeKassirClient(IReceipt): 'email': email, 'phone': phone, }, - 'Email': email, + 'Email': 'company@elcsa.ru', 'SuccessUrl': success_url or self._success_url, 'FailUrl': fail_url or self._fail_url, } diff --git a/src/infrastructure/database/models/payment.py b/src/infrastructure/database/models/payment.py index 5db92b5..3552521 100644 --- a/src/infrastructure/database/models/payment.py +++ b/src/infrastructure/database/models/payment.py @@ -35,7 +35,8 @@ class Payment(Base, UlidPrimaryKeyMixin, AuditTimestampsMixin): default=PaymentStatus.PENDING, ) - receipt_cloudekassir_link: Mapped[str] = mapped_column(nullable=True) + receipt_cloudekassir_id: Mapped[str | None] = mapped_column(String(64), nullable=True) + receipt_cloudekassir_link: Mapped[str | None] = mapped_column(nullable=True) itpay_payment_id: Mapped[str | None] = mapped_column(String(64), nullable=True) itpay_paid_amount: Mapped[Decimal | None] = mapped_column(Numeric(38, 2), nullable=True) diff --git a/src/infrastructure/database/repositories/payment_repository.py b/src/infrastructure/database/repositories/payment_repository.py index b208e0b..1ed03e1 100644 --- a/src/infrastructure/database/repositories/payment_repository.py +++ b/src/infrastructure/database/repositories/payment_repository.py @@ -28,6 +28,7 @@ class PaymentRepository(IPaymentRepository): user_id=user_id, order_id=order_id, status=PaymentStatus.PENDING, + receipt_cloudekassir_id=None, receipt_cloudekassir_link=None, itpay_payment_id=itpay_payment_id, itpay_paid_amount=paid_amount_dec, @@ -39,3 +40,14 @@ class PaymentRepository(IPaymentRepository): await self._session.flush() return + + async def update_receipt(self,*,order_id:str,receipt_cloudekassir_id:str|None,receipt_cloudekassir_link:str|None) -> None: + stmt=select(Payment).where(Payment.order_id==order_id) + model=await self._session.scalar(stmt) + if model is None: + return + model.receipt_cloudekassir_id=receipt_cloudekassir_id + model.receipt_cloudekassir_link=receipt_cloudekassir_link + await self._session.flush() + return +