diff --git a/CHANGELOG.md b/CHANGELOG.md index 014033c..d9554e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.3.0 от 08.04.2021 +* Для DepositionRequest paymentParams.pof_offerAccepted обязателен + ### v2.2.0 от 01.04.2021 * Добавлен параметр -noverify для расшифровки ответа кассы * Генерация CSR со старым закрытым ключом diff --git a/src/yookassa_payout/__init__.py b/src/yookassa_payout/__init__.py index 85c84ec..7826f37 100644 --- a/src/yookassa_payout/__init__.py +++ b/src/yookassa_payout/__init__.py @@ -2,4 +2,4 @@ __author__ = "YooMoney" __email__ = 'cms@yoomoney.ru' -__version__ = '2.2.0' +__version__ = '2.3.0' diff --git a/src/yookassa_payout/domain/models/recipients/recipient.py b/src/yookassa_payout/domain/models/recipients/recipient.py index 11d0933..c22b3e5 100644 --- a/src/yookassa_payout/domain/models/recipients/recipient.py +++ b/src/yookassa_payout/domain/models/recipients/recipient.py @@ -25,6 +25,7 @@ def set_validation_error(self, message): raise ValueError(message) def map(self): + self.validate() return { "pof_offerAccepted": [str(int(self.pof_offer_accepted))] } diff --git a/src/yookassa_payout/domain/request/deposition_request.py b/src/yookassa_payout/domain/request/deposition_request.py index 9a2cef5..893ff2d 100644 --- a/src/yookassa_payout/domain/request/deposition_request.py +++ b/src/yookassa_payout/domain/request/deposition_request.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from yookassa_payout.domain.models.recipients.recipient import Recipient +from yookassa_payout.domain.models.recipients.recipient_factory import RecipientFactory from yookassa_payout.domain.request.request_object import RequestObject @@ -10,6 +12,7 @@ class DepositionRequest(RequestObject): __amount = None __currency = None __contract = None + __payment_params = None def __init__(self, *args, **kwargs): super(DepositionRequest, self).__init__(*args, **kwargs) @@ -63,14 +66,30 @@ def contract(self): def contract(self, value): self.__contract = str(value) + @property + def payment_params(self): + return self.__payment_params + + @payment_params.setter + def payment_params(self, value): + if isinstance(value, Recipient): + self.__payment_params = value + elif isinstance(value, dict): + self.__payment_params = RecipientFactory.factory(value) + else: + raise TypeError('Invalid payment_params value type') + def validate(self): super(DepositionRequest, self).validate() if not self.agent_id: self.set_validation_error('Deposition agent_id not specified') if not self.client_order_id: self.set_validation_error('Deposition client_order_id not specified') + if not self.payment_params: + self.set_validation_error('Deposition payment_params not specified') def map(self): + self.validate() _map = super(DepositionRequest, self).map() _map.update({ "agentId": self.agent_id, @@ -79,6 +98,6 @@ def map(self): "amount": format(self.amount, ".2f"), "currency": self.currency, "contract": self.contract, + "paymentParams": self.payment_params.map() }) return _map - diff --git a/src/yookassa_payout/domain/request/make_deposition_request.py b/src/yookassa_payout/domain/request/make_deposition_request.py index 539187f..485deee 100644 --- a/src/yookassa_payout/domain/request/make_deposition_request.py +++ b/src/yookassa_payout/domain/request/make_deposition_request.py @@ -1,39 +1,14 @@ # -*- coding: utf-8 -*- -from yookassa_payout.domain.models.recipients.recipient import Recipient -from yookassa_payout.domain.models.recipients.recipient_factory import RecipientFactory from yookassa_payout.domain.request.deposition_request import DepositionRequest class MakeDepositionRequest(DepositionRequest): - __payment_params = None - def __init__(self, *args, **kwargs): super(MakeDepositionRequest, self).__init__(*args, **kwargs) self.request_name = 'makeDeposition' - @property - def payment_params(self): - return self.__payment_params - - @payment_params.setter - def payment_params(self, value): - if isinstance(value, Recipient): - self.__payment_params = value - elif isinstance(value, dict): - self.__payment_params = RecipientFactory.factory(value) - else: - raise TypeError('Invalid payment_params value type') - - def validate(self): - super(MakeDepositionRequest, self).validate() - if not self.payment_params: - self.set_validation_error('Deposition payment_params not specified') - def map(self): + self.validate() _map = super(MakeDepositionRequest, self).map() - if self.payment_params: - _map.update({ - "paymentParams": self.payment_params.map() - }) return {self.request_name + 'Request': _map} diff --git a/src/yookassa_payout/domain/request/test_deposition_request.py b/src/yookassa_payout/domain/request/test_deposition_request.py index 18a9c8c..ac212b5 100644 --- a/src/yookassa_payout/domain/request/test_deposition_request.py +++ b/src/yookassa_payout/domain/request/test_deposition_request.py @@ -9,5 +9,6 @@ def __init__(self, *args, **kwargs): self.request_name = 'testDeposition' def map(self): + self.validate() _map = super(TestDepositionRequest, self).map() return {self.request_name + 'Request': _map} diff --git a/tests/unit/test_test_deposition_request.py b/tests/unit/test_test_deposition_request.py index 90a1d0a..975f2ca 100644 --- a/tests/unit/test_test_deposition_request.py +++ b/tests/unit/test_test_deposition_request.py @@ -71,6 +71,9 @@ def test_request_map(self): "amount": format(10.0, ".2f"), "currency": Currency.RUB, "contract": "Зачисление на кошелек", + "paymentParams": { + "pof_offerAccepted": ['1'], + } } }) @@ -83,4 +86,7 @@ def create_test_params(): "amount": 10.00, "currency": Currency.RUB, "contract": "Зачисление на кошелек", + "payment_params": { + "pof_offer_accepted": True, + } }