Skip to content

Commit

Permalink
Merge pull request #39 from fintoc-com/feat/integrate-payment-intents
Browse files Browse the repository at this point in the history
Integrate Payment Intents
  • Loading branch information
daleal authored Dec 14, 2021
2 parents 9bb1408 + 44895d9 commit 8be023b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fintoc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand All @@ -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
)
1 change: 1 addition & 0 deletions fintoc/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions fintoc/managers/payment_intents_manager.py
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions fintoc/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions fintoc/resources/payment_intent.py
Original file line number Diff line number Diff line change
@@ -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",
}

0 comments on commit 8be023b

Please sign in to comment.