From 0c374a54e578925c456fa59438eded3cc566d096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=9D=2E=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5=D0=B2?= Date: Fri, 10 Sep 2021 14:25:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20metadata=20=D0=B2=20transfers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 9 +++--- CHANGELOG.md | 3 ++ src/yookassa/__init__.py | 2 +- src/yookassa/domain/models/transfer.py | 11 ++++++++ .../domain/response/transfer_response.py | 11 ++++++++ test/unit/test_any_list_response.py | 6 +++- test/unit/test_payment_request.py | 28 ++++++++++++++++++- test/unit/test_payment_request_builder.py | 8 ++++++ test/unit/test_payment_response.py | 12 ++++++-- test/unit/test_transfer.py | 9 ++++++ test/unit/test_transfer_response.py | 24 ++++++++++++++-- 11 files changed, 111 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1aaf5a3..c92aeea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: python python: - - "3.4" - - "3.5" - - "3.6" - - "3.7" + - "3.9" - "3.8" + - "3.7" + - "3.6" + - "3.5" + - "3.4" matrix: include: - python: 2.7 diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a3fea..20fe945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.1.3 от 10.09.2021 +* Добавлена обработка metadata в transfers + ### v2.1.2 от 04.06.2021 * Поправлена валидация чека diff --git a/src/yookassa/__init__.py b/src/yookassa/__init__.py index 4dd00b0..ac23db4 100644 --- a/src/yookassa/__init__.py +++ b/src/yookassa/__init__.py @@ -10,4 +10,4 @@ __author__ = "YooMoney" __email__ = 'cms@yoomoney.ru' -__version__ = '2.1.2' +__version__ = '2.1.3' diff --git a/src/yookassa/domain/models/transfer.py b/src/yookassa/domain/models/transfer.py index d53cfd5..50d5ce5 100644 --- a/src/yookassa/domain/models/transfer.py +++ b/src/yookassa/domain/models/transfer.py @@ -15,6 +15,8 @@ class Transfer(BaseObject): __platform_fee_amount = None + __metadata = None + @property def account_id(self): return self.__account_id @@ -48,3 +50,12 @@ def platform_fee_amount(self, value): self.__platform_fee_amount = value else: raise TypeError('Invalid transfer.platform_fee_amount value type') + + @property + def metadata(self): + return self.__metadata + + @metadata.setter + def metadata(self, value): + if type(value) is dict: + self.__metadata = value diff --git a/src/yookassa/domain/response/transfer_response.py b/src/yookassa/domain/response/transfer_response.py index cf9e9f6..983f817 100644 --- a/src/yookassa/domain/response/transfer_response.py +++ b/src/yookassa/domain/response/transfer_response.py @@ -17,6 +17,8 @@ class TransferResponse(BaseObject): __status = None + __metadata = None + @property def account_id(self): return self.__account_id @@ -59,6 +61,15 @@ def status(self): def status(self, value): self.__status = str(value) + @property + def metadata(self): + return self.__metadata + + @metadata.setter + def metadata(self, value): + if type(value) is dict: + self.__metadata = value + class TransferStatus(object): """ diff --git a/test/unit/test_any_list_response.py b/test/unit/test_any_list_response.py index fab7b26..b6bae49 100644 --- a/test/unit/test_any_list_response.py +++ b/test/unit/test_any_list_response.py @@ -135,7 +135,11 @@ def test_response_cast_payment(self): "value": 100.01, "currency": "RUB" }, - "status": "succeeded" + "status": "succeeded", + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } } ], "income_amount": { diff --git a/test/unit/test_payment_request.py b/test/unit/test_payment_request.py index 4521de1..540c98a 100644 --- a/test/unit/test_payment_request.py +++ b/test/unit/test_payment_request.py @@ -83,6 +83,10 @@ def test_request_cast(self): "platform_fee_amount": { "value": 10.01, "currency": Currency.RUB + }, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' } })) @@ -152,6 +156,10 @@ def test_request_cast(self): "platform_fee_amount": { "value": 10.01, "currency": Currency.RUB + }, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' } } ] @@ -211,6 +219,23 @@ def test_request_setters(self): } ] }, + 'transfers': [ + { + 'account_id': '79990000000', + "amount": { + "value": 100.01, + "currency": Currency.RUB + }, + "platform_fee_amount": Amount({ + "value": 10.01, + "currency": Currency.RUB + }), + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } + } + ], 'metadata': {'key': 'value'} }) @@ -220,6 +245,7 @@ def test_request_setters(self): self.assertIsInstance(request.recipient, Recipient) self.assertIsInstance(request.payment_method_data, PaymentData) self.assertIsInstance(request.airline, Airline) + self.assertIsInstance(request.transfers, list) with self.assertRaises(TypeError): request.receipt = 'invalid receipt' @@ -247,7 +273,7 @@ def test_request_setters(self): request.airline = 'Invalid airline' with self.assertRaises(TypeError): - request.transfers = 'Invalid airline' + request.transfers = 'Invalid transfers' def test_request_validate(self): request = PaymentRequest() diff --git a/test/unit/test_payment_request_builder.py b/test/unit/test_payment_request_builder.py index 31dc0e2..c9004b2 100644 --- a/test/unit/test_payment_request_builder.py +++ b/test/unit/test_payment_request_builder.py @@ -55,6 +55,10 @@ def test_build_object(self): "platform_fee_amount": { "value": 10.01, "currency": Currency.RUB + }, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' } } ]) @@ -109,6 +113,10 @@ def test_build_object(self): "platform_fee_amount": { "value": 10.01, "currency": Currency.RUB + }, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' } }] }, dict(request)) diff --git a/test/unit/test_payment_response.py b/test/unit/test_payment_response.py index 77d7d96..8806934 100644 --- a/test/unit/test_payment_response.py +++ b/test/unit/test_payment_response.py @@ -79,7 +79,11 @@ def test_response_cast(self): "value": 10.01, "currency": Currency.RUB }, - "status": "succeeded" + "status": "succeeded", + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } } ], "income_amount": { @@ -140,7 +144,11 @@ def test_response_cast(self): "value": 10.01, "currency": Currency.RUB }, - "status": TransferStatus.SUCCEEDED + "status": TransferStatus.SUCCEEDED, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } })) response.transfers = None diff --git a/test/unit/test_transfer.py b/test/unit/test_transfer.py index 065d895..b9def4b 100644 --- a/test/unit/test_transfer.py +++ b/test/unit/test_transfer.py @@ -16,12 +16,20 @@ def test_receipt_cast(self): "value": '100.01', "currency": Currency.RUB }) + transfer.metadata = { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } self.assertEqual({ 'account_id': '79990000000', "amount": { "value": 100.01, "currency": Currency.RUB + }, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' } }, dict(transfer)) @@ -29,6 +37,7 @@ def test_receipt_cast(self): self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount)) self.assertEqual(float(transfer.amount.value), 100.01) + self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata)) with self.assertRaises(TypeError): transfer.amount = 'invalid type' diff --git a/test/unit/test_transfer_response.py b/test/unit/test_transfer_response.py index d495baf..27c5352 100644 --- a/test/unit/test_transfer_response.py +++ b/test/unit/test_transfer_response.py @@ -16,6 +16,10 @@ def test_transfer_cast(self): "value": '100.01', "currency": Currency.RUB }) + transfer.metadata = { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } self.assertEqual({ "account_id": "79990000000", @@ -23,7 +27,11 @@ def test_transfer_cast(self): "value": 100.01, "currency": Currency.RUB }, - "status": TransferStatus.SUCCEEDED + "status": TransferStatus.SUCCEEDED, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } }, dict(transfer)) self.assertEqual('79990000000', transfer.account_id) @@ -31,6 +39,7 @@ def test_transfer_cast(self): self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount)) self.assertEqual(float(transfer.amount.value), 100.01) + self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata)) with self.assertRaises(TypeError): transfer.amount = 'invalid type' @@ -43,7 +52,11 @@ def test_transfer_value(self): "value": 100.01, "currency": Currency.RUB }, - "status": TransferStatus.SUCCEEDED + "status": TransferStatus.SUCCEEDED, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } }) self.assertEqual({ @@ -52,7 +65,11 @@ def test_transfer_value(self): "value": 100.01, "currency": Currency.RUB }, - "status": TransferStatus.SUCCEEDED + "status": TransferStatus.SUCCEEDED, + "metadata": { + "meta1": 'metatest 1', + "meta2": 'metatest 2' + } }, dict(transfer)) self.assertEqual('79990000000', transfer.account_id) @@ -60,3 +77,4 @@ def test_transfer_value(self): self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount)) self.assertEqual(float(transfer.amount.value), 100.01) + self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata))