Skip to content

Commit 7c3847d

Browse files
author
pierre-pg
authored
Merge pull request #13 from payplug/add-oney-payment-simulation
add OneyPaymentSimulation
2 parents e5afa44 + e6bbafa commit 7c3847d

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.4.0
2+
-----
3+
- Add OneyPaymentSimulation class to handle the /oney_payment_simulations API endpoint
4+
15
1.3.1
26
-----
37
- Add missing `Billing` and `Shipping` entities to payment resource

payplug/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,22 @@ def create(**data):
397397
http_client = HttpClient()
398398
response, _ = http_client.post(routes.url(routes.ACCOUNTING_REPORT_RESOURCE), data)
399399
return resources.AccountingReport(**response)
400+
401+
402+
class OneyPaymentSimulation:
403+
"""
404+
A DAO for resources.OneyPaymentSimulation which provides a way to query oney payment simulations.
405+
"""
406+
@staticmethod
407+
def get_simulation(**data):
408+
"""
409+
Get an oney payment simulation.
410+
411+
:param data: data required to get a simulation
412+
413+
:return: The oney payment simulation
414+
:rtype resources.OneyPaymentSimulation
415+
"""
416+
http_client = HttpClient()
417+
response, _ = http_client.post(routes.url(routes.ONEY_PAYMENT_SIMULATION), data)
418+
return resources.OneyPaymentSimulation(**response)

payplug/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '1.3.1'
2+
__version__ = '1.4.0'

payplug/resources.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,26 @@ def get_consistent_resource(self):
368368
routes.url(routes.ACCOUNTING_REPORT_RESOURCE, resource_id=self.id)
369369
)
370370
return AccountingReport(**response)
371+
372+
373+
class OneyPaymentSimulation(APIResource):
374+
"""
375+
An OneyPaymentSimulation Resource.
376+
"""
377+
@property
378+
def _mapper(self):
379+
"""
380+
Maps each oney payment simuation item to an operation.
381+
382+
:see :func:`~APIResource._mapper`
383+
"""
384+
return {
385+
'x3_with_fees': OneyPaymentSimulation.Operation,
386+
'x4_with_fees': OneyPaymentSimulation.Operation,
387+
}
388+
389+
class Operation(APIResource):
390+
"""
391+
An operation.
392+
"""
393+
pass

payplug/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
CUSTOMER_RESOURCE = '/customers'
88
CARD_RESOURCE = CUSTOMER_RESOURCE + '/{customer_id}/cards'
99
ACCOUNTING_REPORT_RESOURCE = '/accounting_reports'
10+
ONEY_PAYMENT_SIMULATION = '/oney_payment_simulations'
1011

1112
# API base url
1213
API_BASE_URL = 'https://api.payplug.com'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
from mock import patch
3+
import payplug
4+
from payplug import resources
5+
from payplug.test import TestBase
6+
7+
8+
@patch('payplug.config.secret_key', 'a_secret_key')
9+
@patch.object(payplug.HttpClient, 'post', lambda *args, **kwargs: ({'id': 'simulation_id'}, 201))
10+
class TestAccountingReportCreateRetrieve(TestBase):
11+
def test_retrieve(self):
12+
simulation = payplug.OneyPaymentSimulation.get_simulation(key='val')
13+
14+
assert isinstance(simulation, resources.OneyPaymentSimulation)
15+
assert simulation.id == 'simulation_id'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
from payplug.resources import OneyPaymentSimulation
3+
from payplug.test import TestBase
4+
5+
6+
class TestOneyPaymentSimulationResource(TestBase):
7+
def test_initializer_oney_payment_simulation(self):
8+
simulation_attributes = {
9+
"x3_with_fees": {
10+
"down_payment_amount": 67667,
11+
"nominal_annual_percentage_rate": 6.04,
12+
"effective_annual_percentage_rate": 6.21,
13+
"installments": [
14+
{
15+
"date": "2019-12-29T01:00:00.000Z",
16+
"amount": 66667
17+
},
18+
{
19+
"date": "2020-01-29T01:00:00.000Z",
20+
"amount": 66666
21+
}
22+
],
23+
"total_cost": 1000
24+
},
25+
}
26+
27+
simulation_object = OneyPaymentSimulation(**simulation_attributes)
28+
operation = simulation_object.x3_with_fees
29+
30+
assert isinstance(operation, OneyPaymentSimulation.Operation)
31+
assert operation.down_payment_amount == 67667
32+
assert operation.nominal_annual_percentage_rate == 6.04
33+
assert operation.effective_annual_percentage_rate == 6.21
34+
assert operation.installments == [
35+
{
36+
"date": "2019-12-29T01:00:00.000Z",
37+
"amount": 66667
38+
},
39+
{
40+
"date": "2020-01-29T01:00:00.000Z",
41+
"amount": 66666
42+
}
43+
]
44+
assert operation.total_cost == 1000

0 commit comments

Comments
 (0)