Skip to content

Commit

Permalink
recurring groups
Browse files Browse the repository at this point in the history
  • Loading branch information
adgsantos committed Oct 21, 2024
1 parent 44392c0 commit 29dc02e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
25 changes: 21 additions & 4 deletions ntropy_sdk/account_holders.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import uuid
from datetime import datetime
from enum import Enum
from typing import Optional, TYPE_CHECKING, Literal
import uuid
from typing import Optional, TYPE_CHECKING

from pydantic import BaseModel, Field

from ntropy_sdk.utils import pydantic_json
from ntropy_sdk.paging import PagedResponse
from ntropy_sdk.transactions import RecurrenceGroup, RecurrenceGroups
from ntropy_sdk.utils import pydantic_json

if TYPE_CHECKING:
from ntropy_sdk import ExtraKwargs
Expand Down Expand Up @@ -107,4 +108,20 @@ def create(
)
return AccountHolder(**resp.json(), request_id=request_id)

# TODO: Recurring groups
def recurring_groups(
self,
id: str,
**extra_kwargs: "Unpack[ExtraKwargs]",
) -> RecurrenceGroups:
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
resp = self._sdk.retry_ratelimited_request(
method="POST",
url=f"/v3/account_holders/{id}/recurring_groups",
**extra_kwargs,
)
return RecurrenceGroups(
groups=[RecurrenceGroup(**r) for r in resp.json()], request_id=request_id
)
5 changes: 5 additions & 0 deletions ntropy_sdk/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class RecurrenceGroup(BaseModel):
)


class RecurrenceGroups(BaseModel):
groups: List[RecurrenceGroup]
request_id: Optional[str]


class Recurrence(BaseModel):
"""
The `Recurrence` object represents the recurrence pattern of a transaction. It provides information about
Expand Down
42 changes: 41 additions & 1 deletion tests/v3/test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
from itertools import islice
from ntropy_sdk import SDK

from ntropy_sdk import (
SDK,
TransactionInput,
AccountHolder,
NtropyValueError,
)


def test_pagination(sdk: SDK):
Expand All @@ -18,3 +24,37 @@ def test_readme(api_key):
readme_data = readme_file.split("```python")[1].split("```")[0]
readme_data = readme_data.replace("YOUR-API-KEY", api_key)
exec(readme_data, globals())


def test_recurrence_groups(sdk):
try:
sdk.account_holders.create(
AccountHolder(
id="Xksd9SWd",
type="consumer",
)
)
except NtropyValueError:
pass

txs = []
txs.extend(
[
TransactionInput(
id=f"netflix-{i}",
description=f"Recurring Debit Purchase Card 1350 #{i} netflix.com Netflix.com CA",
amount=17.99,
currency="USD",
entry_type="outgoing",
date=f"2021-0{i}-01",
account_holder_id="Xksd9SWd",
)
for i in range(1, 5)
]
)

sdk.transactions.create(txs)
recurring_groups = sdk.account_holders.recurring_groups("Xksd9SWd")

assert recurring_groups.groups[0].counterparty.website == "netflix.com"
assert recurring_groups.groups[0].periodicity == "monthly"

0 comments on commit 29dc02e

Please sign in to comment.