Skip to content

Commit

Permalink
Correct the PaymentCaptures resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Hendrikx committed Jun 22, 2023
1 parent 7ee73ff commit 0848749
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mollie/api/objects/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
10 changes: 0 additions & 10 deletions mollie/api/resources/captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

if TYPE_CHECKING:
from ..client import Client
from ..objects.payment import Payment
from ..objects.settlement import Settlement

__all__ = [
Expand 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)
Expand Down
11 changes: 7 additions & 4 deletions tests/responses/captures_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
}
58 changes: 58 additions & 0 deletions tests/responses/captures_list_more.json
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions tests/test_payment_captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0848749

Please sign in to comment.