Skip to content

Commit

Permalink
payment transfer request
Browse files Browse the repository at this point in the history
  • Loading branch information
jaddek committed Feb 15, 2025
1 parent fc3f0c2 commit 54e5058
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 37 deletions.
36 changes: 33 additions & 3 deletions src/jpy_tillo_sdk/domain/float/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from typing import Optional

from ...endpoint import Endpoint, QP
from ...endpoint import Endpoint, QP, AbstractBodyRequest
from ...enums import Currency


Expand All @@ -15,5 +15,35 @@ class QueryParams(QP):
currency: Optional[Currency] = None

@property
def query(self) -> QueryParams|None:
return self._query
def query(self) -> QueryParams | None:
return self._query


class RequestPaymentTransferEndpoint(Endpoint):
_method: str = "POST"
_endpoint: str = "float-request-payment-transfer"
_route: str = "/api/v2/float/request-payment-transfer"

@dataclass(frozen=True)
class RequestBody(AbstractBodyRequest):
@dataclass(frozen=True)
class ProformaInvoiceParams:
company_name: Optional[str] = None,
address_line_1: Optional[str] = None,
address_line_2: Optional[str] = None,
address_line_3: Optional[str] = None,
address_line_4: Optional[str] = None,
city: Optional[str] = None,
post_code: Optional[str] = None,
county: Optional[str] = None,
country: Optional[str] = None,

currency: Currency
amount: str
payment_reference: str
finance_email: str
proforma_invoice: Optional[ProformaInvoiceParams] = None
float: str = "universal-float"

def get_sign_attrs(self) -> tuple:
return ()
21 changes: 20 additions & 1 deletion src/jpy_tillo_sdk/domain/float/factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint
import string
from typing import Optional

from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint, RequestPaymentTransferEndpoint
from jpy_tillo_sdk.enums import Currency


def create_check_floats_query(currency: Currency):
return CheckFloatsEndpoint.QueryParams(currency=currency.value)


def create_payment_transfer_request(
currency: Currency,
amount: string,
payment_reference: string,
finance_email: string,
proforma_invoice: Optional[RequestPaymentTransferEndpoint.RequestBody.ProformaInvoiceParams] = None
):
return RequestPaymentTransferEndpoint.RequestBody(
currency=Currency.EUR,
amount="100",
payment_reference="PAY_REF",
finance_email="<EMAIL>",
proforma_invoice=proforma_invoice,
)
43 changes: 32 additions & 11 deletions src/jpy_tillo_sdk/domain/float/services.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import logging

from .endpoints import CheckFloatsEndpoint
from .endpoints import CheckFloatsEndpoint, RequestPaymentTransferEndpoint
from ...http_client import HttpClient, AsyncHttpClient
from typing import Optional

logger = logging.getLogger(__name__)


class FloatService:
@staticmethod
def check_floats(
client: HttpClient,
query_params: Optional[CheckFloatsEndpoint.QueryParams] = None,
client: HttpClient,
query_params: Optional[CheckFloatsEndpoint.QueryParams] = None,
):
logger.debug("Checking floats: sync HTTP client with query_params: %s", query_params)

Expand All @@ -24,8 +25,8 @@ def check_floats(

@staticmethod
async def check_floats_async(
client: AsyncHttpClient,
query_params: Optional[CheckFloatsEndpoint.QueryParams] = None,
client: AsyncHttpClient,
query_params: Optional[CheckFloatsEndpoint.QueryParams] = None,
):
logger.debug("Checking floats: sync HTTP client with query_params: %s", query_params)

Expand All @@ -38,11 +39,31 @@ async def check_floats_async(
return response

@staticmethod
def request_payment_transfer():
logger.debug("Method request_payment_transfer not implemented.")
raise NotImplementedError("This method is not implemented.")
def request_payment_transfer(
client: HttpClient,
body: RequestPaymentTransferEndpoint.RequestBody
):
logger.debug("Checking floats: sync HTTP client with body: %s", body)

endpoint = RequestPaymentTransferEndpoint(body=body)

response = client.request(
endpoint=endpoint,
)

return response

@staticmethod
async def request_payment_transfer_async():
logger.debug("Method request_payment_transfer_async not implemented.")
raise NotImplementedError("This method is not implemented.")
async def request_payment_transfer_async(
client: AsyncHttpClient,
body: RequestPaymentTransferEndpoint.RequestBody
):
logger.debug("Checking floats: sync HTTP client with body: %s", body)

endpoint = RequestPaymentTransferEndpoint(body=body)

response = await client.request(
endpoint=endpoint,
)

return response
10 changes: 0 additions & 10 deletions tests/domain/float/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
from jpy_tillo_sdk.http_client import HttpClient, AsyncHttpClient


@pytest.fixture
def mock_query_params():
return {"currency": "EUR", "template": "standard"}


@pytest.fixture
def mock_empty_query_params():
return {}


@pytest.fixture
def mock_http_client():
client = Mock(spec=HttpClient)
Expand Down
14 changes: 13 additions & 1 deletion tests/domain/float/test_float_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint
from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint, RequestPaymentTransferEndpoint
from jpy_tillo_sdk.enums import Domains
from jpy_tillo_sdk.http_methods import HttpMethods

Expand All @@ -13,3 +13,15 @@ def test_check_floats_endpoint():
assert endpoint.sign_attrs is None
assert endpoint.is_body_not_empty() is False
assert endpoint.params == {}


def test_request_payment_transfer_endpoint():
endpoint = RequestPaymentTransferEndpoint()

assert endpoint.method == HttpMethods.POST.value
assert endpoint.endpoint == 'float-request-payment-transfer'
assert endpoint.route == "/api/v2/float/request-payment-transfer"
assert endpoint.body == {}
assert endpoint.sign_attrs is None
assert endpoint.is_body_not_empty() is False
assert endpoint.params == {}
17 changes: 15 additions & 2 deletions tests/domain/float/test_float_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint
from jpy_tillo_sdk.domain.float.endpoints import CheckFloatsEndpoint, RequestPaymentTransferEndpoint
from jpy_tillo_sdk.enums import Currency
from jpy_tillo_sdk.domain.float.factory import create_check_floats_query
from jpy_tillo_sdk.domain.float.factory import create_check_floats_query, create_payment_transfer_request


def test_create_check_floats_query():
request = create_check_floats_query(
Expand All @@ -9,3 +10,15 @@ def test_create_check_floats_query():

assert isinstance(request, CheckFloatsEndpoint.QueryParams)
assert request.currency == Currency.EUR.value


def test_create_payment_transfer_request():
request = create_payment_transfer_request(
currency=Currency.EUR,
amount="100",
payment_reference="ref",
finance_email='finance_email'
)

assert isinstance(request, RequestPaymentTransferEndpoint.RequestBody)
assert request.currency == Currency.EUR
37 changes: 28 additions & 9 deletions tests/domain/float/test_float_services.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest
from httpx import Response

from jpy_tillo_sdk.domain.float.endpoints import RequestPaymentTransferEndpoint
from jpy_tillo_sdk.domain.float.services import FloatService
from jpy_tillo_sdk.enums import Currency


def test_check_floats(mock_http_client, mock_query_params):
def test_check_floats(mock_http_client):
response = FloatService.check_floats(mock_http_client)

mock_http_client.request.assert_called_once()
Expand All @@ -19,14 +21,31 @@ async def test_check_floats_async(mock_async_http_client):
assert isinstance(response, Response)


def test_request_payment_transfer():
service = FloatService()
with pytest.raises(NotImplementedError):
service.request_payment_transfer()
def test_request_payment_transfer(mock_http_client):
response = FloatService.request_payment_transfer(
mock_http_client,
RequestPaymentTransferEndpoint.RequestBody(
currency=Currency.EUR,
amount="100",
payment_reference="PAY_REF",
finance_email="<EMAIL>"
)
)
mock_http_client.request.assert_called_once()
assert isinstance(response, Response)


@pytest.mark.asyncio
async def test_request_payment_transfer_async():
service = FloatService()
with pytest.raises(NotImplementedError):
await service.request_payment_transfer_async()
async def test_request_payment_transfer_async(mock_async_http_client):
response = await FloatService.request_payment_transfer_async(
mock_async_http_client,
RequestPaymentTransferEndpoint.RequestBody(
currency=Currency.EUR,
amount="100",
payment_reference="PAY_REF",
finance_email="<EMAIL>"
)
)

mock_async_http_client.request.assert_called_once()
assert isinstance(response, Response)

0 comments on commit 54e5058

Please sign in to comment.