diff --git a/mollie/api/objects/payment.py b/mollie/api/objects/payment.py index 2c38d12f..ea1f2d5b 100644 --- a/mollie/api/objects/payment.py +++ b/mollie/api/objects/payment.py @@ -200,7 +200,7 @@ def captures(self): """Return the captures related to this payment""" from ..resources import PaymentCaptures - return PaymentCaptures(self.client, self) + return PaymentCaptures(self.client, resource_path=f"payments/{self.id}/captures") def get_settlement(self): """Return the settlement for this payment.""" diff --git a/mollie/api/resources/captures.py b/mollie/api/resources/captures.py index cd1c7417..db4341c9 100644 --- a/mollie/api/resources/captures.py +++ b/mollie/api/resources/captures.py @@ -5,7 +5,6 @@ if TYPE_CHECKING: from ..client import Client - from ..objects.payment import Payment from ..objects.settlement import Settlement __all__ = [ @@ -24,15 +23,6 @@ def get_resource_object(self, result: dict) -> Capture: class PaymentCaptures(CapturesBase, ResourceGetMixin, ResourceListMixin): """Resource handler for the `/payments/:payment_id:/captures` endpoint.""" - _payment: "Payment" - - def __init__(self, client: "Client", payment: "Payment") -> None: - self._payment = payment - super().__init__(client) - - def get_resource_path(self) -> str: - return f"payments/{self._payment.id}/captures" - def get(self, resource_id: str, **params: Any) -> Capture: self.validate_resource_id(resource_id, "capture ID") return super().get(resource_id, **params) diff --git a/tests/responses/captures_list.json b/tests/responses/captures_list.json index 755a8b17..35b7c590 100644 --- a/tests/responses/captures_list.json +++ b/tests/responses/captures_list.json @@ -19,11 +19,11 @@ "createdAt": "2018-08-02T09:29:56+00:00", "_links": { "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT", + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures/cpt_4qqhO89gsT", "type": "application/hal+json" }, "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", "type": "application/hal+json" }, "shipment": { @@ -49,10 +49,13 @@ "type": "text/html" }, "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures?limit=50", + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1", "type": "application/hal+json" }, "previous": null, - "next": null + "next": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1&from=cpt_4qqhO89gsU", + "type": "application/hal+json" + } } } diff --git a/tests/responses/captures_list_more.json b/tests/responses/captures_list_more.json new file mode 100644 index 00000000..13ad229a --- /dev/null +++ b/tests/responses/captures_list_more.json @@ -0,0 +1,58 @@ +{ + "_embedded": { + "captures": [ + { + "resource": "capture", + "id": "cpt_4qqhO89gsU", + "mode": "live", + "amount": { + "value": "1027.99", + "currency": "EUR" + }, + "settlementAmount": { + "value": "399.00", + "currency": "EUR" + }, + "paymentId": "tr_7UhSN1zuXS", + "shipmentId": "shp_3wmsgCJN4U", + "settlementId": "stl_jDk30akdN", + "createdAt": "2018-08-02T09:29:56+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures/cpt_4qqhO89gsU", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + }, + "shipment": { + "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U", + "type": "application/hal+json" + }, + "settlement": { + "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture", + "type": "text/html" + } + } + } + ] + }, + "count": 1, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/captures-api/list-captures", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?limit=1&from=cpt_4qqhO89gsU", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } +} diff --git a/tests/test_payment_captures.py b/tests/test_payment_captures.py index f28f3177..07a53b12 100644 --- a/tests/test_payment_captures.py +++ b/tests/test_payment_captures.py @@ -18,11 +18,18 @@ def test_list_payment_captures(client, response): """Get capture relevant to payment by payment id.""" response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single") response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures", "captures_list") + response.get( + f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures?limit=1&from=cpt_4qqhO89gsU", "captures_list_more" + ) payment = client.payments.get(PAYMENT_ID) captures = payment.captures.list() assert_list_object(captures, Capture) + assert captures.has_next() is True + more_captures = captures.get_next() + assert_list_object(more_captures, Capture) + def test_get_payment_capture_invalid_id(client, response): response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single")