diff --git a/README.md b/README.md index 522bbdb..761081e 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ from fintoc import Fintoc fintoc_client = Fintoc("your_api_key") ``` -This gives us access to a bunch of operations already. The object created using this _snippet_ contains two [managers](#managers): `links` and `webhook_endpoints`. +This gives us access to a bunch of operations already. The object created using this _snippet_ contains three [managers](#managers): `links`, `payment_intents` and `webhook_endpoints`. #### The `webhook_endpoints` manager @@ -232,6 +232,44 @@ webhook_endpoint = fintoc_client.webhook_endpoints.get("we_8anqVLlBC8ROodem") print(webhook_endpoint.id) # we_8anqVLlBC8ROodem ``` +#### The `payment_intents` manager + +Available methods: `all`, `get`, `create`. + +Payment intents allow you to start a payment using Fintoc! Start by creating a new payment intent: + +```python +payment_intent = fintoc_client.payment_intents.create( + currency="CLP", + amount=5990, + recipient_account={ + "holder_id": "111111111", + "number": "123123123", + "type": "checking_account", + "institution_id": "cl_banco_de_chile", + } +) + +print(payment_intent.id) # pi_BO381oEATXonG6bj +print(payment_intent.widget_token) # pi_BO381oEATXonG6bj_sec_a4xK32BanKWYn +``` + +Notice that the success of this payment intent will be notified through a Webhook. Now, let's list every payment intent we have: + +```python +for payment_intent in fintoc_client.payment_intents.all(): + print(payment_intent.id) +``` + +If you see a payment intent you want to use, just use the `get` method! + +```python +payment_intent = fintoc_client.payment_intents.get("pi_BO381oEATXonG6bj") + +print(payment_intent.id) # pi_BO381oEATXonG6bj +print(payment_intent.status) # succeeded +``` + #### The `links` manager Available methods: `all`, `get`, `update`, `delete`. @@ -320,7 +358,8 @@ If you see a refresh intent you want to use, just use the `get` method! ```python refresh_intent = link.refresh_intents.get("ri_5A94DVCJ7xNM3MEo") -print(refresh_intent.id) # ri_5A94DVCJ7xNM3MEo +print(refresh_intent.id) # ri_5A94DVCJ7xNM3MEo +print(refresh_intent.status) # succeeded ``` #### The `accounts` manager diff --git a/fintoc/core.py b/fintoc/core.py index 7f5ddf7..94e91d7 100644 --- a/fintoc/core.py +++ b/fintoc/core.py @@ -4,7 +4,7 @@ from fintoc.client import Client from fintoc.constants import API_BASE_URL, API_VERSION -from fintoc.managers import LinksManager, WebhookEndpointsManager +from fintoc.managers import LinksManager, PaymentIntentsManager, WebhookEndpointsManager from fintoc.version import __version__ @@ -19,6 +19,7 @@ def __init__(self, api_key): user_agent=f"fintoc-python/{__version__}", ) self.links = LinksManager("/links", self._client) + self.payment_intents = PaymentIntentsManager("/payment_intents", self._client) self.webhook_endpoints = WebhookEndpointsManager( "/webhook_endpoints", self._client ) diff --git a/fintoc/managers/__init__.py b/fintoc/managers/__init__.py index eb852f1..d20e276 100644 --- a/fintoc/managers/__init__.py +++ b/fintoc/managers/__init__.py @@ -4,6 +4,7 @@ from .invoices_manager import InvoicesManager from .links_manager import LinksManager from .movements_manager import MovementsManager +from .payment_intents_manager import PaymentIntentsManager from .refresh_intents_manager import RefreshIntentsManager from .subscriptions_manager import SubscriptionsManager from .tax_returns_manager import TaxRetunsManager diff --git a/fintoc/managers/payment_intents_manager.py b/fintoc/managers/payment_intents_manager.py new file mode 100644 index 0000000..e8ca92b --- /dev/null +++ b/fintoc/managers/payment_intents_manager.py @@ -0,0 +1,11 @@ +"""Module to hold the payment_intents manager.""" + +from fintoc.mixins import ManagerMixin + + +class PaymentIntentsManager(ManagerMixin): + + """Represents a payment_intents manager.""" + + resource = "payment_intent" + methods = ["all", "get", "create"] diff --git a/fintoc/resources/__init__.py b/fintoc/resources/__init__.py index 7ff12ff..9434d24 100644 --- a/fintoc/resources/__init__.py +++ b/fintoc/resources/__init__.py @@ -11,6 +11,7 @@ from .link import Link from .movement import Movement from .other_taxes import OtherTaxes +from .payment_intent import PaymentIntent from .refresh_intent import RefreshIntent from .services_invoice import ServicesInvoice from .subscription import Subscription diff --git a/fintoc/resources/payment_intent.py b/fintoc/resources/payment_intent.py new file mode 100644 index 0000000..c5148d0 --- /dev/null +++ b/fintoc/resources/payment_intent.py @@ -0,0 +1,13 @@ +"""Module to hold the PaymentIntent resource.""" + +from fintoc.mixins import ResourceMixin + + +class PaymentIntent(ResourceMixin): + + """Represents a Fintoc Payment Intent.""" + + mappings = { + "recipient_account": "transfer_account", + "sender_account": "transfer_account", + }