Skip to content

Commit a3a4bf7

Browse files
Add support for release_authorization endpoint on payment
1 parent 4c31b4b commit a3a4bf7

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

mollie/api/resources/payments.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def update(
5959
self.validate_resource_id(resource_id, "payment ID")
6060
return super().update(resource_id, data, idempotency_key, **params)
6161

62+
def release_authorization(self, resource_id: str, idempotency_key: str = "") -> dict:
63+
"""Release the authorization for the given payment."""
64+
65+
self.validate_resource_id(resource_id, "payment ID")
66+
return self.perform_api_call(
67+
self.REST_CREATE,
68+
f"{self.get_resource_path()}/{resource_id}/release-authorization",
69+
idempotency_key=idempotency_key,
70+
)
71+
6272

6373
class OrderPayments(PaymentsBase, ResourceCreateMixin):
6474
"""Resource handler for the `/orders/:order_id:/payments` endpoint."""

tests/responses/accepted.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"_links": {
3+
"documentation": {
4+
"href": "https://docs.mollie.com/overview/api-idempotency",
5+
"type": "text/html"
6+
}
7+
},
8+
"detail": "Request has been accepted, but the processing has not been completed yet.",
9+
"status": 202,
10+
"title": "Accepted"
11+
}

tests/test_payments.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,14 @@ def test_update_payment_invalid_id(client):
288288
with pytest.raises(IdentifierError) as excinfo:
289289
client.payments.update("invalid", data)
290290
assert str(excinfo.value) == "Invalid payment ID 'invalid', it should start with 'tr_'."
291+
292+
293+
def test_release_authorization_for_payment(client, response):
294+
"""Release the authorization for the given payment."""
295+
response.post(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/release-authorization", "accepted", 202)
296+
297+
client.payments.release_authorization(PAYMENT_ID)
298+
# Inspect the request that was sent
299+
request = response.calls[-1].request
300+
assert request.url == f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/release-authorization"
301+
assert response.calls[-1].response.status_code == 202

0 commit comments

Comments
 (0)