Repository: mollie/mollie-api-python

Issue:
Prepare for Capture on card payments
We want to add support for delayed capturing of card payments.
For the API client to support this, we need to add:
- Add support for creating a new Payment Capture
- Reading responses from the [Get payment endpoint](https://docs.mollie.com/reference/v2/payments-api/get-payment):
   - add parameter `captureMode` (check with Mollie)
   - add parameter `captureDelay` (check with Mollie)
   - add parameter `captureBefore`
   - add support for new statuses: `authorized` 

A note for avid readers: this feature is not available in the Mollie API (yet).

Discussion:
whyscream: LGTM :+1: 

Patch:
diff --git a/mollie/api/objects/payment.py b/mollie/api/objects/payment.py
index b42b832..23bf95e 100644
--- a/mollie/api/objects/payment.py
+++ b/mollie/api/objects/payment.py
@@ -202,6 +202,18 @@ class Payment(ObjectBase):
 
         return PaymentCaptures(self.client, self)
 
+    @property
+    def capture_before(self):
+        return self._get_property("captureBefore")
+
+    @property
+    def capture_mode(self):
+        return self._get_property("captureMode")
+
+    @property
+    def capture_delay(self):
+        return self._get_property("captureDelay")
+
     def get_settlement(self):
         """Return the settlement for this payment."""
         if self.settlement_id:
diff --git a/mollie/api/resources/captures.py b/mollie/api/resources/captures.py
index cd1c741..4a3af95 100644
--- a/mollie/api/resources/captures.py
+++ b/mollie/api/resources/captures.py
@@ -1,7 +1,7 @@
 from typing import TYPE_CHECKING, Any
 
 from ..objects.capture import Capture
-from .base import ResourceBase, ResourceGetMixin, ResourceListMixin
+from .base import ResourceBase, ResourceCreateMixin, ResourceGetMixin, ResourceListMixin
 
 if TYPE_CHECKING:
     from ..client import Client
@@ -21,7 +21,7 @@ class CapturesBase(ResourceBase):
         return Capture(result, self.client)
 
 
-class PaymentCaptures(CapturesBase, ResourceGetMixin, ResourceListMixin):
+class PaymentCaptures(CapturesBase, ResourceGetMixin, ResourceListMixin, ResourceCreateMixin):
     """Resource handler for the `/payments/:payment_id:/captures` endpoint."""
 
     _payment: "Payment"


Test patch:
diff --git a/tests/responses/payment_single.json b/tests/responses/payment_single.json
index b98f860..717695b 100644
--- a/tests/responses/payment_single.json
+++ b/tests/responses/payment_single.json
@@ -3,6 +3,9 @@
   "id": "tr_7UhSN1zuXS",
   "mode": "test",
   "createdAt": "2018-03-20T09:13:37+00:00",
+  "captureDelay": "20 hours",
+  "captureMode": "automatic",
+  "captureBefore": "2023-01-20T09:13:37+00+00",
   "amount": {
     "value": "10.00",
     "currency": "EUR"
diff --git a/tests/responses/payment_single_no_links.json b/tests/responses/payment_single_no_links.json
index de4e542..c53d20a 100644
--- a/tests/responses/payment_single_no_links.json
+++ b/tests/responses/payment_single_no_links.json
@@ -3,6 +3,9 @@
   "id": "tr_7UhSN1zuXS",
   "mode": "test",
   "createdAt": "2018-03-20T09:13:37+00:00",
+  "captureDelay": "20 hours",
+  "captureMode": "automatic",
+  "captureBefore": "2023-01-20T09:13:37+00+00",
   "amount": {
     "value": "10.00",
     "currency": "EUR"
diff --git a/tests/test_payment_captures.py b/tests/test_payment_captures.py
index f28f317..fc12596 100644
--- a/tests/test_payment_captures.py
+++ b/tests/test_payment_captures.py
@@ -86,3 +86,14 @@ def test_capture_get_related_settlement(client, response):
     capture = payment.captures.get(CAPTURE_ID)
     settlement = capture.get_settlement()
     assert isinstance(settlement, Settlement)
+
+
+def test_create_capture_for_payment(client, response):
+    response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single")
+    response.post(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/captures", "capture_single")
+    payment = client.payments.get(PAYMENT_ID)
+
+    data = {"amount": {"currency": "EUR", "value": "10.00"}, "description": "Capture for order #12345"}
+
+    capture = payment.captures.create(data)
+    assert capture.id == CAPTURE_ID
diff --git a/tests/test_payments.py b/tests/test_payments.py
index 16f9b3f..9a26276 100644
--- a/tests/test_payments.py
+++ b/tests/test_payments.py
@@ -107,6 +107,9 @@ def test_get_single_payment(client, response):
     assert payment.routing is not None
     assert payment.subscription_id is None
     assert payment.settlement_id is None
+    assert payment.capture_mode == "automatic"
+    assert payment.capture_before == "2023-01-20T09:13:37+00+00"
+    assert payment.capture_delay == "20 hours"
     # properties from _links
     assert payment.checkout_url == "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS"
     assert payment.changepaymentstate_url is None