Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fintoc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
AccountsManager,
ChargesManager,
CheckoutSessionsManager,
DisputesManager,
InvoicesManager,
LinksManager,
PaymentIntentsManager,
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self, api_key, api_version=None, jws_private_key=None):
)
self.tax_returns = TaxReturnsManager("/v1/tax_returns", self._client)
self.invoices = InvoicesManager("/v1/invoices", self._client)
self.disputes = DisputesManager("/v1/disputes", self._client)

self.v2 = _FintocV2(self._client)

Expand Down
2 changes: 2 additions & 0 deletions fintoc/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .accounts_manager import AccountsManager
from .charges_manager import ChargesManager
from .checkout_sessions_manager import CheckoutSessionsManager
from .dispute_documents_manager import DisputeDocumentsManager
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Porque necesita su propio Manager los Documents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo separé por dos razones:

  1. Sigue el patrón de accounts.movements: recursos anidados en la API (/v1/disputes/:id/documents) tienen su propio manager en el SDK.
  2. _create del ManagerMixin usa self.__class__.resource para decidir qué clase instanciar. Si pongo create_document en DisputesManager (donde resource = "dispute"), tendría que bypassear _create y llamar a resource_create a mano con klass=DisputeDocument.

Además deja la puerta abierta a agregar list/get/delete de documentos sin tener que refactorizar.

from .disputes_manager import DisputesManager
from .invoices_manager import InvoicesManager
from .links_manager import LinksManager
from .movements_manager import MovementsManager
Expand Down
10 changes: 10 additions & 0 deletions fintoc/managers/dispute_documents_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Module to hold the dispute documents manager."""

from fintoc.mixins import ManagerMixin


class DisputeDocumentsManager(ManagerMixin):
"""Represents a dispute documents manager."""

resource = "dispute_document"
methods = ["create"]
35 changes: 35 additions & 0 deletions fintoc/managers/disputes_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Module to hold the disputes manager."""

from fintoc.managers.dispute_documents_manager import DisputeDocumentsManager
from fintoc.mixins import ManagerMixin


# pylint: disable=duplicate-code
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Porque esto?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es porque el pylint puede detectar bloques de código muy parecidos entre diferentes archivos. Es algo que usamos en todos los managers

class DisputesManager(ManagerMixin):
"""Represents a disputes manager."""

resource = "dispute"
methods = ["list", "get", "submit_for_review"]

def __init__(self, path, client):
super().__init__(path, client)
self.__documents_manager = None

def _submit_for_review(self, identifier, **kwargs):
"""Submit a dispute for review."""
path = f"{self._build_path(**kwargs)}/{identifier}/submit_for_review"
return self._create(path_=path, **kwargs)

@property
def documents(self):
"""Proxies the dispute documents manager."""
if self.__documents_manager is None:
self.__documents_manager = DisputeDocumentsManager(
"/v1/disputes/{dispute_id}/documents",
self._client,
)
return self.__documents_manager

@documents.setter
def documents(self, new_value): # pylint: disable=no-self-use
raise NameError("Attribute name corresponds to a manager")
2 changes: 2 additions & 0 deletions fintoc/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .balance import Balance
from .charge import Charge
from .checkout_session import CheckoutSession
from .dispute import Dispute
from .dispute_document import DisputeDocument
from .generic_fintoc_resource import GenericFintocResource
from .income import Income
from .institution import Institution
Expand Down
11 changes: 11 additions & 0 deletions fintoc/resources/dispute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Module to hold the Dispute resource."""

from fintoc.mixins import ResourceMixin


class Dispute(ResourceMixin):
"""Represents a Fintoc Dispute."""

mappings = {
"documents": "dispute_document",
}
7 changes: 7 additions & 0 deletions fintoc/resources/dispute_document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Module to hold the DisputeDocument resource."""

from fintoc.mixins import ResourceMixin


class DisputeDocument(ResourceMixin):
"""Represents a Fintoc Dispute Document."""
36 changes: 36 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,42 @@ def test_checkout_session_expire(self):
assert result.method == "post"
assert result.url == f"v1/checkout_sessions/{checkout_session_id}/expire"

def test_disputes_list(self):
"""Test getting all disputes."""
disputes = list(self.fintoc.disputes.list())

assert len(disputes) > 0
for dispute in disputes:
assert dispute.method == "get"
assert dispute.url == "v1/disputes"

def test_dispute_get(self):
"""Test getting a specific dispute."""
dispute_id = "test_dispute_id"

dispute = self.fintoc.disputes.get(dispute_id)

assert dispute.method == "get"
assert dispute.url == f"v1/disputes/{dispute_id}"

def test_dispute_submit_for_review(self):
"""Test submitting a dispute for review."""
dispute_id = "test_dispute_id"

result = self.fintoc.disputes.submit_for_review(dispute_id)

assert result.method == "post"
assert result.url == f"v1/disputes/{dispute_id}/submit_for_review"

def test_dispute_document_create(self):
"""Test creating a document for a dispute."""
dispute_id = "test_dispute_id"

document = self.fintoc.disputes.documents.create(dispute_id=dispute_id)

assert document.method == "post"
assert document.url == f"v1/disputes/{dispute_id}/documents"

def test_v2_transfer_return(self):
"""Test returning a transfer using v2 API."""
transfer_id = "test_transfer_id"
Expand Down
Loading