From b6e4f8165fa8f5548a97fc521eaeff6c32eaa3c4 Mon Sep 17 00:00:00 2001 From: Noloquideus Date: Sat, 9 May 2026 10:30:27 +0300 Subject: [PATCH] feat: update recipit --- .../create_payment_cloudkassir_command.py | 17 ++-------- src/infrastructure/cloud_kassir/client.py | 31 +++++++++---------- src/infrastructure/config/settings.py | 26 +++++++--------- src/infrastructure/itpay/client.py | 2 ++ src/presentation/routing/order.py | 1 + 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/application/commands/create_payment_cloudkassir_command.py b/src/application/commands/create_payment_cloudkassir_command.py index e47a731..83b30f6 100644 --- a/src/application/commands/create_payment_cloudkassir_command.py +++ b/src/application/commands/create_payment_cloudkassir_command.py @@ -46,24 +46,15 @@ class CreatePaymentCloudkassirCommand: user = await self._unit_of_work.user_repository.get(user_id) if user is None: raise ApplicationException(status_code=404, message='User not found') - email_meta = metadata.get('customer_email') - if email_meta is None: - email_meta = metadata.get('email') - email = str(email_meta or user.email or '').strip() + email = str(user.email or '').strip() if not email: raise ApplicationException(status_code=400, message='User email missing') - phone_raw = str(metadata.get('phone') or '').strip() - if not phone_raw: - phone_raw = str(user.phone or '').strip() - phone = phone_raw if phone_raw else None - customer_inn_meta = metadata.get('customer_inn') - if customer_inn_meta is None: - customer_inn_meta = metadata.get('customerInn') - customer_inn = str(customer_inn_meta or user.inn or '').strip() paid_total = _parse_money(payment.amount) if paid_total is None: paid_total = _parse_money(metadata.get('amount')) + if paid_total is None: + paid_total = _parse_money(metadata.get('total_amount')) meta_principal = _parse_money(metadata.get('principal_amount')) meta_agent = _parse_money(metadata.get('agent_fee')) @@ -109,7 +100,5 @@ class CreatePaymentCloudkassirCommand: total_amount=total_amount, principal_amount=principal_amount, service_fee=service_fee, - phone=phone, - customer_inn=customer_inn, request_id=str(ULID()), ) diff --git a/src/infrastructure/cloud_kassir/client.py b/src/infrastructure/cloud_kassir/client.py index 90f7e34..a24bd4d 100644 --- a/src/infrastructure/cloud_kassir/client.py +++ b/src/infrastructure/cloud_kassir/client.py @@ -49,8 +49,9 @@ class ClaudeKassirClient(IReceipt): total = total_amount.quantize(Decimal('0.01')) principal = principal_amount.quantize(Decimal('0.01')) fee = service_fee.quantize(Decimal('0.01')) - description = f'Исполнение поручения принципала по заявке №{order_id}' - fee_description = f'Агентское вознаграждение за исполнение поручения по заявке №{order_id}' + description = f'Оплата по заявке №{order_id}' + principal_description = f'Исполнение поручения принципала по заявке №{order_id}' + fee_description = f'Агентское вознаграждение по заявке №{order_id}' payload: dict[str, Any] = { 'Inn': self._inn, 'Type': 'Income', @@ -58,29 +59,30 @@ class ClaudeKassirClient(IReceipt): 'AccountId': user_id, 'Description': description, 'CustomerReceipt': { + 'TaxationSystem': 2, 'Items': [ { - 'label': description, + 'label': principal_description, 'price': float(principal), - 'quantity': 1.00, + 'quantity': 1, 'amount': float(principal), 'vat': 0, 'method': 4, 'object': 4, 'measurement_unit': 'шт', 'agent_info': { - 'type': 2, + 'type': 4, }, 'supplier_info': { - 'name': 'Принципал (физическое лицо)', - 'inn': '', + 'name': 'Принципал', 'phones': [], + 'inn': self._inn, }, }, { 'label': fee_description, 'price': float(fee), - 'quantity': 1.00, + 'quantity': 1, 'amount': float(fee), 'vat': 0, 'method': 4, @@ -88,17 +90,14 @@ class ClaudeKassirClient(IReceipt): 'measurement_unit': 'шт', }, ], - 'taxationSystem': 2, - 'email': email, - 'phone': phone, - 'customerInn': customer_inn, - 'agentSign': 2, 'amounts': { 'electronic': float(total), - 'advancePayment': 0.00, - 'credit': 0.00, - 'provision': 0.00, + 'advancePayment': 0, + 'credit': 0, + 'provision': 0, }, + 'email': email, + 'phone': phone, }, 'Email': email, 'SuccessUrl': success_url or self._success_url, diff --git a/src/infrastructure/config/settings.py b/src/infrastructure/config/settings.py index 5ea186f..92f0316 100644 --- a/src/infrastructure/config/settings.py +++ b/src/infrastructure/config/settings.py @@ -272,21 +272,17 @@ class Settings(BaseSettings): data['CLOUD_KASSIR_PUBLIC_ID'] = str(ck_public).strip() data['CLOUD_KASSIR_API_SECRET'] = str(ck_secret).strip() else: - cloudkassir = read_secret('cloudkassir') - ck_ci = {str(k).lower(): v for k, v in cloudkassir.items()} - public_id_ck = ck_ci.get('public_id') - api_secret_ck = ck_ci.get('api_secret') - if api_secret_ck is None: - api_secret_ck = ck_ci.get('secret') - missing_ck = [] - if public_id_ck is None or not str(public_id_ck).strip(): - missing_ck.append('public_id') - if api_secret_ck is None or not str(api_secret_ck).strip(): - missing_ck.append('api_secret') - if missing_ck: - raise RuntimeError(f'Vault secret cloudkassir missing non-empty keys: {missing_ck} (mount={mount},path=cloudkassir)') - data['CLOUD_KASSIR_PUBLIC_ID'] = str(public_id_ck).strip() - data['CLOUD_KASSIR_API_SECRET'] = str(api_secret_ck).strip() + cloudkassir = read_secret_optional('cloudkassir') + if cloudkassir: + ck_ci = {str(k).lower(): v for k, v in cloudkassir.items()} + public_id_ck = ck_ci.get('public_id') + api_secret_ck = ck_ci.get('api_secret') + if api_secret_ck is None: + api_secret_ck = ck_ci.get('secret') + if public_id_ck is not None and str(public_id_ck).strip(): + data['CLOUD_KASSIR_PUBLIC_ID'] = str(public_id_ck).strip() + if api_secret_ck is not None and str(api_secret_ck).strip(): + data['CLOUD_KASSIR_API_SECRET'] = str(api_secret_ck).strip() return data diff --git a/src/infrastructure/itpay/client.py b/src/infrastructure/itpay/client.py index 293daf9..12b4747 100644 --- a/src/infrastructure/itpay/client.py +++ b/src/infrastructure/itpay/client.py @@ -37,7 +37,9 @@ class ItPayClient(IItPayService): 'usdt_exchange_rate': str(order.usdt_exchange_rate) if order.usdt_exchange_rate is not None else None, 'gas_fee': str(order.gas_fee) if order.gas_fee is not None else None, 'service_fee': str(order.service_fee) if order.service_fee is not None else None, + 'agent_fee': str(order.service_fee) if order.service_fee is not None else None, 'amount': amount_str, + 'total_amount': amount_str, } if order.total_price is not None and order.service_fee is not None: principal = (Decimal(str(order.total_price)) - Decimal(str(order.service_fee))).quantize(Decimal('0.01')) diff --git a/src/presentation/routing/order.py b/src/presentation/routing/order.py index c5efd21..9ead8c1 100644 --- a/src/presentation/routing/order.py +++ b/src/presentation/routing/order.py @@ -95,6 +95,7 @@ async def itpay_webhook( 'payment_id': data.get('id'), 'client_payment_id': data.get('client_payment_id'), 'payment_status': status, + 'itpay_metadata': data.get('metadata'), } logger.info(orjson.dumps(log_payload, default=str).decode()) if status == 'completed':