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 @@ -12,6 +12,7 @@
LinksManager,
PaymentIntentsManager,
RefreshIntentsManager,
RefundsManager,
SubscriptionIntentsManager,
SubscriptionsManager,
TaxReturnsManager,
Expand Down Expand Up @@ -49,6 +50,7 @@ def __init__(self, api_key, api_version=None, jws_private_key=None):
self.payment_intents = PaymentIntentsManager(
"/v1/payment_intents", self._client
)
self.refunds = RefundsManager("/v1/refunds", self._client)
self.subscriptions = SubscriptionsManager("/v1/subscriptions", self._client)
self.subscription_intents = SubscriptionIntentsManager(
"/v1/subscription_intents", self._client
Expand Down
1 change: 1 addition & 0 deletions fintoc/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .movements_manager import MovementsManager
from .payment_intents_manager import PaymentIntentsManager
from .refresh_intents_manager import RefreshIntentsManager
from .refunds_manager import RefundsManager
from .subscription_intents_manager import SubscriptionIntentsManager
from .subscriptions_manager import SubscriptionsManager
from .tax_returns_manager import TaxReturnsManager
Expand Down
16 changes: 16 additions & 0 deletions fintoc/managers/refunds_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Module to hold the refunds manager."""

from fintoc.mixins import ManagerMixin


class RefundsManager(ManagerMixin):

"""Represents a refunds manager."""

resource = "refund"
methods = ["list", "get", "create", "cancel"]

def _cancel(self, identifier, **kwargs):
"""Expire a refund."""
path = f"{self._build_path(**kwargs)}/{identifier}/cancel"
return self._create(path_=path, **kwargs)
7 changes: 7 additions & 0 deletions fintoc/resources/refund.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Module to hold the Refund resource."""

from fintoc.mixins import ResourceMixin


class Refund(ResourceMixin):
"""Represents a Fintoc Refund."""
43 changes: 43 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,49 @@ def test_payment_intent_expire(self):
assert result.method == "post"
assert result.url == f"v1/payment_intents/{payment_intent_id}/expire"

def test_refund_list(self):
"""Test getting all refunds."""
refunds = list(self.fintoc.refunds.list())

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

def test_refund_get(self):
"""Test getting a specific refund."""
refund_id = "test_refund_id"

refund = self.fintoc.refunds.get(refund_id)

assert refund.method == "get"
assert refund.url == f"v1/refunds/{refund_id}"

def test_refund_create(self):
"""Test creating a refund."""
refund_data = {
"resource_type": "payment_intent",
"resource_id": "pi_30yWq311fOLrAAKkSH1bvODVLGa",
"amount": 1000,
}

refund = self.fintoc.refunds.create(**refund_data)

assert refund.method == "post"
assert refund.url == "v1/refunds"
assert refund.json.resource_type == refund_data["resource_type"]
assert refund.json.resource_id == refund_data["resource_id"]
assert refund.json.amount == refund_data["amount"]

def test_refund_cancel(self):
"""Test canceling a refund."""
refund_id = "ref_QmbpWzP1HOngN3X7"

refund = self.fintoc.refunds.cancel(refund_id)

assert refund.method == "post"
assert refund.url == f"v1/refunds/{refund_id}/cancel"

def test_subscription_intents_list(self):
"""Test getting all subscription intents."""
subscription_intents = list(self.fintoc.subscription_intents.list())
Expand Down