Skip to content

Commit 11ba4a7

Browse files
Merge pull request #356 from rubenhesselink/add-terminals
Add terminal object and resource
2 parents fd68efd + 7c6a8ca commit 11ba4a7

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

mollie/api/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Refunds,
2929
Settlements,
3030
Subscriptions,
31+
Terminals,
3132
)
3233
from .version import VERSION
3334

@@ -107,6 +108,7 @@ def __init__(self, api_endpoint: str = "", timeout: Union[int, Tuple[int, int]]
107108
self.settlements = Settlements(self)
108109
self.subscriptions = Subscriptions(self)
109110
self.balances = Balances(self)
111+
self.terminals = Terminals(self)
110112

111113
# compose base user agent string
112114
self.user_agent_components = OrderedDict()

mollie/api/objects/terminal.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from .base import ObjectBase
2+
3+
4+
class Terminal(ObjectBase):
5+
@property
6+
def id(self):
7+
return self._get_property("id")
8+
9+
@property
10+
def status(self):
11+
return self._get_property("status")
12+
13+
@property
14+
def brand(self):
15+
return self._get_property("brand")
16+
17+
@property
18+
def model(self):
19+
return self._get_property("model")
20+
21+
@property
22+
def serial_number(self):
23+
return self._get_property("serialNumber")
24+
25+
@property
26+
def currency(self):
27+
return self._get_property("currency")
28+
29+
@property
30+
def description(self):
31+
return self._get_property("description")
32+
33+
@property
34+
def profile_id(self):
35+
return self._get_property("profileId")
36+
37+
@property
38+
def created_at(self):
39+
return self._get_property("createdAt")

mollie/api/resources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
from .settlements import * # noqa: F401, F403
1919
from .shipments import * # noqa: F401, F403
2020
from .subscriptions import * # noqa: F401, F403
21+
from .terminals import * # noqa: F401, F403

mollie/api/resources/terminals.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import Any
2+
3+
from ..objects.terminal import Terminal
4+
from .base import ResourceGetMixin, ResourceListMixin
5+
6+
__all__ = [
7+
"Terminals",
8+
]
9+
10+
11+
class Terminals(ResourceGetMixin, ResourceListMixin):
12+
"""
13+
Resource handler for the `/terminals` endpoint.
14+
15+
Retrieve either a single or a list of terminals.
16+
"""
17+
18+
RESOURCE_ID_PREFIX: str = "term_"
19+
object_type = Terminal
20+
21+
def get(self, resource_id: str, **params: Any) -> Terminal:
22+
"""Retrieve a single terminal, by its ID."""
23+
self.validate_resource_id(resource_id, "terminal ID")
24+
return super().get(resource_id, **params)

tests/responses/terminal_single.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"resource": "terminal",
3+
"id": "term_7MgL4wea46qkRcoTZjWEH",
4+
"status": "active",
5+
"brand": "PAX",
6+
"model": "A920",
7+
"serialNumber": "1234567890",
8+
"currency": "EUR",
9+
"description": "Terminal #12345",
10+
"profileId": "pfl_QkEhN94Ba",
11+
"createdAt": "2022-02-12T11:58:35+00:00",
12+
"_links": {
13+
"self": {
14+
"href": "...",
15+
"type": "application/hal+json"
16+
},
17+
"documentation": {
18+
"href": "...",
19+
"type": "text/html"
20+
}
21+
}
22+
}

tests/responses/terminals_list.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"count": 3,
3+
"_embedded": {
4+
"terminals": [
5+
{
6+
"resource": "terminal",
7+
"id": "term_7MgL4wea46qkRcoTZjWEH",
8+
"status": "active",
9+
"brand": "PAX",
10+
"model": "A920",
11+
"serialNumber": "1234567890",
12+
"currency": "EUR",
13+
"description": "Terminal #12345",
14+
"profileId": "pfl_QkEhN94Ba",
15+
"createdAt": "2022-02-12T11:58:35+00:00",
16+
"_links": {
17+
"self": {
18+
"href": "...",
19+
"type": "application/hal+json"
20+
}
21+
}
22+
},
23+
{
24+
"resource": "terminal",
25+
"id": "term_8MgL4wea46qkRcoTZjWEH",
26+
"status": "active",
27+
"brand": "PAX",
28+
"model": "A920",
29+
"serialNumber": "1234567890",
30+
"currency": "EUR",
31+
"description": "Terminal #12345",
32+
"profileId": "pfl_QkEhN94Ba",
33+
"createdAt": "2022-02-12T11:58:35+00:00",
34+
"_links": {
35+
"self": {
36+
"href": "...",
37+
"type": "application/hal+json"
38+
}
39+
}
40+
},
41+
{
42+
"resource": "terminal",
43+
"id": "term_9MgL4wea46qkRcoTZjWEH",
44+
"status": "active",
45+
"brand": "PAX",
46+
"model": "A920",
47+
"serialNumber": "1234567890",
48+
"currency": "EUR",
49+
"description": "Terminal #12345",
50+
"profileId": "pfl_QkEhN94Ba",
51+
"createdAt": "2022-02-12T11:58:35+00:00",
52+
"_links": {
53+
"self": {
54+
"href": "...",
55+
"type": "application/hal+json"
56+
}
57+
}
58+
}
59+
]
60+
},
61+
"_links": {
62+
"self": {
63+
"href": "...",
64+
"type": "application/hal+json"
65+
},
66+
"previous": null,
67+
"next": null,
68+
"documentation": {
69+
"href": "...",
70+
"type": "text/html"
71+
}
72+
}
73+
}

tests/test_terminals.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from mollie.api.objects.terminal import Terminal
2+
3+
from .utils import assert_list_object
4+
5+
TERMINAL_ID = "term_7MgL4wea46qkRcoTZjWEH"
6+
7+
8+
def test_get_terminal(client, response):
9+
response.get(f"https://api.mollie.com/v2/terminals/{TERMINAL_ID}", "terminal_single")
10+
11+
terminal = client.terminals.get(TERMINAL_ID)
12+
13+
assert terminal.id == TERMINAL_ID
14+
15+
16+
def test_list_terminals(client, response):
17+
response.get("https://api.mollie.com/v2/terminals", "terminals_list")
18+
19+
terminals = client.terminals.list()
20+
assert_list_object(terminals, Terminal)

0 commit comments

Comments
 (0)