Skip to content

Commit

Permalink
Correct SettlementCaptures
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Hendrikx committed Jun 22, 2023
1 parent 77da937 commit 7e7c126
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mollie/api/objects/settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def captures(self):
"""Return the captures related to this settlement."""
from ..resources import SettlementCaptures

return SettlementCaptures(self.client, self)
return SettlementCaptures(self.client, resource_path=f"settlements/{self.id}/captures")

def get_invoice(self):
"""Return the invoice related to this settlement."""
Expand Down
15 changes: 2 additions & 13 deletions mollie/api/resources/captures.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from typing import TYPE_CHECKING, Any
from typing import Any

from ..objects.capture import Capture
from .base import ResourceBase, ResourceGetMixin, ResourceListMixin

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

__all__ = [
"PaymentCaptures",
"SettlementCaptures",
Expand All @@ -31,11 +27,4 @@ def get(self, resource_id: str, **params: Any) -> Capture:
class SettlementCaptures(CapturesBase, ResourceListMixin):
"""Resource handler for the `/settlements/:settlement_id:/captures` endpoint."""

_settlement: "Settlement"

def __init__(self, client: "Client", settlement: "Settlement") -> None:
self._settlement = settlement
super().__init__(client)

def get_resource_path(self) -> str:
return f"settlements/{self._settlement.id}/captures"
pass
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions tests/responses/settlement_captures_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"_embedded": {
"captures": [
{
"resource": "capture",
"id": "cpt_4qqhO89gsT",
"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_4qqhO89gsT",
"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/settlements/stl_jDk30akdN/captures?limit=1",
"type": "application/hal+json"
},
"previous": null,
"next": {
"href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/captures?limit=1&from=cpt_4qqhO89gsU",
"type": "application/hal+json"
}
}
}
58 changes: 58 additions & 0 deletions tests/responses/settlement_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_4qqhO89gsT",
"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/settlements/stl_jDk30akdN/captures?limit=1&from=cpt_4qqhO89gsU",
"type": "application/hal+json"
},
"previous": null,
"next": null
}
}
5 changes: 3 additions & 2 deletions tests/test_payment_captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
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", "payment_captures_list")
response.get(
f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures?limit=1&from=cpt_4qqhO89gsU", "captures_list_more"
f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures?limit=1&from=cpt_4qqhO89gsU",
"payment_captures_list_more",
)

payment = client.payments.get(PAYMENT_ID)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_payment_get_related_chargebacks(client, response):
def test_payment_get_related_captures(client, response):
"""Get captures related to payment."""
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", "payment_captures_list")

payment = client.payments.get(PAYMENT_ID)
captures = payment.captures.list()
Expand Down
12 changes: 10 additions & 2 deletions tests/test_settlement_captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
def test_list_settlement_captures(oauth_client, response):
"""Get a list of captures relevant to settlement object."""
response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single")
response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/captures", "captures_list")
response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/captures", "settlement_captures_list")
response.get(
f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/captures?limit=1&from=cpt_4qqhO89gsU",
"settlement_captures_list_more",
)

settlement = oauth_client.settlements.get(SETTLEMENT_ID)
captures = settlement.captures.list()
assert_list_object(captures, Capture)
assert_list_object(captures, Capture, 1)

assert captures.has_next() is True
more_captures = captures.get_next()
assert_list_object(more_captures, Capture)

0 comments on commit 7e7c126

Please sign in to comment.