diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e4d08..5723baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +1.4.0 +----- +- Add OneyPaymentSimulation class to handle the /oney_payment_simulations API endpoint + 1.3.1 ----- - Add missing `Billing` and `Shipping` entities to payment resource diff --git a/payplug/__init__.py b/payplug/__init__.py index 143abd7..d2b64b9 100644 --- a/payplug/__init__.py +++ b/payplug/__init__.py @@ -397,3 +397,22 @@ def create(**data): http_client = HttpClient() response, _ = http_client.post(routes.url(routes.ACCOUNTING_REPORT_RESOURCE), data) return resources.AccountingReport(**response) + + +class OneyPaymentSimulation: + """ + A DAO for resources.OneyPaymentSimulation which provides a way to query oney payment simulations. + """ + @staticmethod + def get_simulation(**data): + """ + Get an oney payment simulation. + + :param data: data required to get a simulation + + :return: The oney payment simulation + :rtype resources.OneyPaymentSimulation + """ + http_client = HttpClient() + response, _ = http_client.post(routes.url(routes.ONEY_PAYMENT_SIMULATION), data) + return resources.OneyPaymentSimulation(**response) diff --git a/payplug/__version__.py b/payplug/__version__.py index d14fa05..cf0bccd 100644 --- a/payplug/__version__.py +++ b/payplug/__version__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__version__ = '1.3.1' +__version__ = '1.4.0' diff --git a/payplug/resources.py b/payplug/resources.py index 0d0dd9d..81706a2 100644 --- a/payplug/resources.py +++ b/payplug/resources.py @@ -368,3 +368,26 @@ def get_consistent_resource(self): routes.url(routes.ACCOUNTING_REPORT_RESOURCE, resource_id=self.id) ) return AccountingReport(**response) + + +class OneyPaymentSimulation(APIResource): + """ + An OneyPaymentSimulation Resource. + """ + @property + def _mapper(self): + """ + Maps each oney payment simuation item to an operation. + + :see :func:`~APIResource._mapper` + """ + return { + 'x3_with_fees': OneyPaymentSimulation.Operation, + 'x4_with_fees': OneyPaymentSimulation.Operation, + } + + class Operation(APIResource): + """ + An operation. + """ + pass diff --git a/payplug/routes.py b/payplug/routes.py index 8f3b522..60fe7e1 100644 --- a/payplug/routes.py +++ b/payplug/routes.py @@ -7,6 +7,7 @@ CUSTOMER_RESOURCE = '/customers' CARD_RESOURCE = CUSTOMER_RESOURCE + '/{customer_id}/cards' ACCOUNTING_REPORT_RESOURCE = '/accounting_reports' +ONEY_PAYMENT_SIMULATION = '/oney_payment_simulations' # API base url API_BASE_URL = 'https://api.payplug.com' diff --git a/payplug/test/test_init/test_dao_oney_payment_simulation.py b/payplug/test/test_init/test_dao_oney_payment_simulation.py new file mode 100644 index 0000000..b14546f --- /dev/null +++ b/payplug/test/test_init/test_dao_oney_payment_simulation.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from mock import patch +import payplug +from payplug import resources +from payplug.test import TestBase + + +@patch('payplug.config.secret_key', 'a_secret_key') +@patch.object(payplug.HttpClient, 'post', lambda *args, **kwargs: ({'id': 'simulation_id'}, 201)) +class TestAccountingReportCreateRetrieve(TestBase): + def test_retrieve(self): + simulation = payplug.OneyPaymentSimulation.get_simulation(key='val') + + assert isinstance(simulation, resources.OneyPaymentSimulation) + assert simulation.id == 'simulation_id' diff --git a/payplug/test/test_resources/test_oney_payment_simulation.py b/payplug/test/test_resources/test_oney_payment_simulation.py new file mode 100644 index 0000000..b40a2b7 --- /dev/null +++ b/payplug/test/test_resources/test_oney_payment_simulation.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +from payplug.resources import OneyPaymentSimulation +from payplug.test import TestBase + + +class TestOneyPaymentSimulationResource(TestBase): + def test_initializer_oney_payment_simulation(self): + simulation_attributes = { + "x3_with_fees": { + "down_payment_amount": 67667, + "nominal_annual_percentage_rate": 6.04, + "effective_annual_percentage_rate": 6.21, + "installments": [ + { + "date": "2019-12-29T01:00:00.000Z", + "amount": 66667 + }, + { + "date": "2020-01-29T01:00:00.000Z", + "amount": 66666 + } + ], + "total_cost": 1000 + }, + } + + simulation_object = OneyPaymentSimulation(**simulation_attributes) + operation = simulation_object.x3_with_fees + + assert isinstance(operation, OneyPaymentSimulation.Operation) + assert operation.down_payment_amount == 67667 + assert operation.nominal_annual_percentage_rate == 6.04 + assert operation.effective_annual_percentage_rate == 6.21 + assert operation.installments == [ + { + "date": "2019-12-29T01:00:00.000Z", + "amount": 66667 + }, + { + "date": "2020-01-29T01:00:00.000Z", + "amount": 66666 + } + ] + assert operation.total_cost == 1000