Skip to content

Commit

Permalink
feat: use new fioapi interface instead of reimplementing it
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jan 6, 2025
1 parent 1776c20 commit e9102a4
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions weblate_web/payments/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
from .utils import send_notification

if TYPE_CHECKING:
from collections.abc import Generator
from datetime import date, datetime

from django.http import HttpRequest, HttpResponseRedirect
from django_stubs_ext import StrOrPromise

Expand Down Expand Up @@ -494,41 +491,6 @@ def collect(self, request: HttpRequest | None) -> bool:
return True


class FioBankAPI(fiobank.FioBank):
"""
Fio API wrapper.
Backported API from
https://github.com/honzajavorek/fiobank/pull/38.
TODO: Remove this wrapper once it is released.
"""

def _fetch_last(
self, from_id: str | None = None, from_date: str | date | datetime | None = None
) -> dict:
if from_id and from_date:
raise ValueError("Only one constraint is allowed.")

if from_id:
self._request("set-last-id", from_id=from_id)
elif from_date:
self._request("set-last-date", from_date=fiobank.coerce_date(from_date))

return self._request("last")

def last(
self, from_id: str | None = None, from_date: str | date | datetime | None = None
) -> Generator[dict]:
return self._parse_transactions(self._fetch_last(from_id, from_date))

def last_transactions(
self, from_id: str | None = None, from_date: str | date | datetime | None = None
) -> tuple[dict, Generator[dict]]:
data = self._fetch_last(from_id, from_date)
return (self._parse_info(data), self._parse_transactions(data))


@register_backend
class FioBank(Backend):
name = "fio-bank"
Expand Down Expand Up @@ -567,8 +529,7 @@ def fetch_payments(cls, from_date: str | None = None) -> None: # noqa: PLR0915,
else:
tokens = settings.FIO_TOKEN
for token in tokens:
# TODO: change to fiobank.FioBank(token=token, decimal=True) with fiobank 4.0
client = FioBankAPI(token=token)
client = fiobank.FioBank(token=token, decimal=True)
try:
info, transactions = client.last_transactions(from_date=from_date)
except requests.RequestException as error:
Expand Down

0 comments on commit e9102a4

Please sign in to comment.