Skip to content

Commit 15ce257

Browse files
author
Tom Hendrikx
committed
Correct the PaymentCaptures resource
1 parent c0162a0 commit 15ce257

File tree

5 files changed

+73
-15
lines changed

5 files changed

+73
-15
lines changed

mollie/api/objects/payment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def captures(self):
200200
"""Return the captures related to this payment"""
201201
from ..resources import PaymentCaptures
202202

203-
return PaymentCaptures(self.client, self)
203+
return PaymentCaptures(self.client, resource_path=f"payments/{self.id}/captures")
204204

205205
def get_settlement(self):
206206
"""Return the settlement for this payment."""

mollie/api/resources/captures.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
if TYPE_CHECKING:
77
from ..client import Client
8-
from ..objects.payment import Payment
98
from ..objects.settlement import Settlement
109

1110
__all__ = [
@@ -24,15 +23,6 @@ def get_resource_object(self, result: dict) -> Capture:
2423
class PaymentCaptures(CapturesBase, ResourceGetMixin, ResourceListMixin):
2524
"""Resource handler for the `/payments/:payment_id:/captures` endpoint."""
2625

27-
_payment: "Payment"
28-
29-
def __init__(self, client: "Client", payment: "Payment") -> None:
30-
self._payment = payment
31-
super().__init__(client)
32-
33-
def get_resource_path(self) -> str:
34-
return f"payments/{self._payment.id}/captures"
35-
3626
def get(self, resource_id: str, **params: Any) -> Capture:
3727
self.validate_resource_id(resource_id, "capture ID")
3828
return super().get(resource_id, **params)

tests/responses/captures_list.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"createdAt": "2018-08-02T09:29:56+00:00",
2020
"_links": {
2121
"self": {
22-
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT",
22+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures/cpt_4qqhO89gsT",
2323
"type": "application/hal+json"
2424
},
2525
"payment": {
26-
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
26+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS",
2727
"type": "application/hal+json"
2828
},
2929
"shipment": {
@@ -49,10 +49,13 @@
4949
"type": "text/html"
5050
},
5151
"self": {
52-
"href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures?limit=50",
52+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1",
5353
"type": "application/hal+json"
5454
},
5555
"previous": null,
56-
"next": null
56+
"next": {
57+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1&from=cpt_4qqhO89gsU",
58+
"type": "application/hal+json"
59+
}
5760
}
5861
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"_embedded": {
3+
"captures": [
4+
{
5+
"resource": "capture",
6+
"id": "cpt_4qqhO89gsU",
7+
"mode": "live",
8+
"amount": {
9+
"value": "1027.99",
10+
"currency": "EUR"
11+
},
12+
"settlementAmount": {
13+
"value": "399.00",
14+
"currency": "EUR"
15+
},
16+
"paymentId": "tr_7UhSN1zuXS",
17+
"shipmentId": "shp_3wmsgCJN4U",
18+
"settlementId": "stl_jDk30akdN",
19+
"createdAt": "2018-08-02T09:29:56+00:00",
20+
"_links": {
21+
"self": {
22+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures/cpt_4qqhO89gsU",
23+
"type": "application/hal+json"
24+
},
25+
"payment": {
26+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS",
27+
"type": "application/hal+json"
28+
},
29+
"shipment": {
30+
"href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U",
31+
"type": "application/hal+json"
32+
},
33+
"settlement": {
34+
"href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN",
35+
"type": "application/hal+json"
36+
},
37+
"documentation": {
38+
"href": "https://docs.mollie.com/reference/v2/captures-api/get-capture",
39+
"type": "text/html"
40+
}
41+
}
42+
}
43+
]
44+
},
45+
"count": 1,
46+
"_links": {
47+
"documentation": {
48+
"href": "https://docs.mollie.com/reference/v2/captures-api/list-captures",
49+
"type": "text/html"
50+
},
51+
"self": {
52+
"href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1&from=cpt_4qqhO89gsU",
53+
"type": "application/hal+json"
54+
},
55+
"previous": null,
56+
"next": null
57+
}
58+
}

tests/test_payment_captures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ def test_list_payment_captures(client, response):
1818
"""Get capture relevant to payment by payment id."""
1919
response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single")
2020
response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures", "captures_list")
21+
response.get(
22+
f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures?limit=1&from=cpt_4qqhO89gsU", "captures_list_more"
23+
)
2124

2225
payment = client.payments.get(PAYMENT_ID)
2326
captures = payment.captures.list()
2427
assert_list_object(captures, Capture)
2528

29+
assert captures.has_next() is True
30+
more_captures = captures.get_next()
31+
assert_list_object(more_captures, Capture)
32+
2633

2734
def test_get_payment_capture_invalid_id(client, response):
2835
response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single")

0 commit comments

Comments
 (0)