Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions payplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion payplug/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '1.3.1'
__version__ = '1.4.0'
23 changes: 23 additions & 0 deletions payplug/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions payplug/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions payplug/test/test_init/test_dao_oney_payment_simulation.py
Original file line number Diff line number Diff line change
@@ -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'
44 changes: 44 additions & 0 deletions payplug/test/test_resources/test_oney_payment_simulation.py
Original file line number Diff line number Diff line change
@@ -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