From 943609b46293b90f3ff1533366e78ec61ed710bf Mon Sep 17 00:00:00 2001 From: antonia Date: Mon, 16 Nov 2026 11:44:45 -0300 Subject: [PATCH] feat: agrega cuotas disponibles de un payment method v2 --- README.md | 10 ++++++++++ fintoc/managers/v2/payment_methods_manager.py | 9 ++++++++- fintoc/resources/__init__.py | 1 + fintoc/resources/v2/__init__.py | 1 + .../resources/v2/payment_method_installments.py | 7 +++++++ tests/test_integration.py | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 fintoc/resources/v2/payment_method_installments.py diff --git a/README.md b/README.md index b456813..e2b004e 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,16 @@ payment_method = client.v2.payment_methods.create( ) ``` +The installments available to pay an amount with a saved card are returned as a list of +numbers of installments, empty when the card doesn't take installments: + +```python +installments = client.v2.payment_methods.installments( + "pm_31yYL7h9LVPg121AgFtCyJPDsgM", amount=100000, currency="CLP" +) +print(installments.available_installments) # [3, 6, 12] +``` + #### Account certificates Mexican accounts and account numbers have a certificate (constancia de cuenta) with a diff --git a/fintoc/managers/v2/payment_methods_manager.py b/fintoc/managers/v2/payment_methods_manager.py index 767c627..a85f364 100644 --- a/fintoc/managers/v2/payment_methods_manager.py +++ b/fintoc/managers/v2/payment_methods_manager.py @@ -8,7 +8,7 @@ class PaymentMethodsManager(ManagerMixin): """Represents a payment methods manager.""" resource = "payment_method" - methods = ["list", "get", "create", "cancel", "mandate_document"] + methods = ["list", "get", "create", "cancel", "mandate_document", "installments"] file_parameters = ("consent_documents",) @@ -42,6 +42,13 @@ def _mandate_document(self, identifier, **kwargs): "get", path, resource="mandate_document", **kwargs ) + def _installments(self, identifier, **kwargs): + """Get the installments available to pay an amount with a card.""" + path = f"{self._build_path(**kwargs)}/{identifier}/installments" + return self._request_resource( + "get", path, resource="payment_method_installments", **kwargs + ) + def _flatten(self, key, value, data, files, is_file=False): """Flatten a nested parameter into multipart form fields and files.""" if value is None: diff --git a/fintoc/resources/__init__.py b/fintoc/resources/__init__.py index 51832ca..3c4a0e5 100644 --- a/fintoc/resources/__init__.py +++ b/fintoc/resources/__init__.py @@ -49,6 +49,7 @@ from .v2.onboarding_shareholder import OnboardingShareholder from .v2.payment_eligibility import PaymentEligibility from .v2.payment_method import PaymentMethod +from .v2.payment_method_installments import PaymentMethodInstallments from .v2.product import Product from .v2.recipient import Recipient from .v2.settlement_account import SettlementAccount diff --git a/fintoc/resources/v2/__init__.py b/fintoc/resources/v2/__init__.py index 2fa8968..fcefe3c 100644 --- a/fintoc/resources/v2/__init__.py +++ b/fintoc/resources/v2/__init__.py @@ -20,6 +20,7 @@ from .onboarding_shareholder import OnboardingShareholder from .payment_eligibility import PaymentEligibility from .payment_method import PaymentMethod +from .payment_method_installments import PaymentMethodInstallments from .product import Product from .recipient import Recipient from .settlement_account import SettlementAccount diff --git a/fintoc/resources/v2/payment_method_installments.py b/fintoc/resources/v2/payment_method_installments.py new file mode 100644 index 0000000..0a0c2e2 --- /dev/null +++ b/fintoc/resources/v2/payment_method_installments.py @@ -0,0 +1,7 @@ +"""Module to hold the Payment Method Installments resource.""" + +from fintoc.mixins import ResourceMixin + + +class PaymentMethodInstallments(ResourceMixin): + """Represents the available installments of a Fintoc Payment Method.""" diff --git a/tests/test_integration.py b/tests/test_integration.py index b26ca2b..4cd3125 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -24,6 +24,7 @@ PaymentEligibility, PaymentIntent, PaymentMethod, + PaymentMethodInstallments, Payout, Product, Refund, @@ -2355,6 +2356,22 @@ def test_v2_payment_method_create_multipart_fields(self): assert isinstance(payment_method, PaymentMethod) assert payment_method.id == "pm_12345" + def test_v2_payment_method_installments(self): + """Test getting the installments of a payment method using v2 API.""" + self.response = {"available_installments": [3, 6, 12]} + + installments = self.fintoc.v2.payment_methods.installments( + "pm_12345", amount=100000, currency="CLP" + ) + + request = self.requests[-1] + assert request.method == "GET" + assert request.url.path == "/v2/payment_methods/pm_12345/installments" + assert request.url.params["amount"] == "100000" + assert request.url.params["currency"] == "CLP" + assert isinstance(installments, PaymentMethodInstallments) + assert installments.available_installments == [3, 6, 12] + @pytest.mark.parametrize( "method,args", [