Skip to content
Open
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
10 changes: 5 additions & 5 deletions unit/api/applicationForm_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ def __init__(self, api_url, token):
super().__init__(api_url, token)
self.resource = "application-forms"

def create(self, request: CreateApplicationFormRequest) -> Union[UnitResponse[ApplicationFormDTO], UnitError]:
def create(self, request: CreateApplicationFormRequest) -> Union[UnitResponse[ApplicationFormV2DTO], UnitError]:
payload = request.to_json_api()
response = super().post(
self.resource,
payload,
data=payload,
headers={
"X-Accept-Version": "V2024_06"
}
)
if super().is_20x(response.status_code):
data = response.json().get("data")
return UnitResponse[ApplicationFormDTO](DtoDecoder.decode(data), None)
return UnitResponse[ApplicationFormV2DTO](DtoDecoder.decode(data), None)
else:
return UnitError.from_json_api(response.json())

def get(self, application_form_id: str, include: Optional[str] = "") -> Union[UnitResponse[ApplicationFormDTO], UnitError]:
def get(self, application_form_id: str, include: Optional[str] = "") -> Union[UnitResponse[ApplicationFormV2DTO], UnitError]:
response = super().get(f"{self.resource}/{application_form_id}", {"include": include})
if super().is_20x(response.status_code):
data = response.json().get("data")
included = response.json().get("included")
return UnitResponse[ApplicationFormDTO](DtoDecoder.decode(data), DtoDecoder.decode(included))
return UnitResponse[ApplicationFormV2DTO](DtoDecoder.decode(data), DtoDecoder.decode(included))
else:
return UnitError.from_json_api(response.json())

Expand Down
3 changes: 1 addition & 2 deletions unit/api/base_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ def __merge_headers(self, headers: Optional[Dict[str, str]] = None):
return merged

def is_20x(self, status: int):
return status == 200 or status == 201 or status == 204

return status == 200 or status == 201 or status == 204
70 changes: 66 additions & 4 deletions unit/models/applicationForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,58 @@ def __init__(self, application_type: Optional[str], full_name: Optional[FullName
self.phone = phone


class ApplicationLink(object):
def __init__(
self,
type,
href,
):
self.type = type
self.href = type


class ApplicationFormV2DTO(object):
def __init__(
self,
id,
created_at: datetime,
updated_at: datetime,
tags: Optional[Dict[str, str]],
token: str,
expiration: datetime,
relationships: Optional[Dict[str, Relationship]],
url: str
):
self.type = "applicationFormV2"
self.id = id
self.attributes = {
"created_at": created_at,
"updated_at": updated_at,
"tags": tags,
"token": token,
"expiration": expiration,
}
self.relationships = relationships
self.url = url

@staticmethod
def from_json_api(
_id,
attributes,
relationships,
links,
):
return ApplicationFormV2DTO(
id=_id,
created_at=attributes["createdAt"],
updated_at=attributes["updatedAt"],
tags=attributes["tags"],
token=attributes["applicationFormToken"]["token"],
expiration=attributes["applicationFormToken"]["expiration"],
relationships=relationships,
url=links["related"]["href"],
)

class ApplicationFormDTO(object):
def __init__(self, id: str, url: str, stage: ApplicationFormStage, applicant_details: ApplicationFormPrefill,
tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]):
Expand All @@ -55,18 +107,28 @@ def from_json_api(_id, _type, attributes, relationships):


class CreateApplicationFormRequest(UnitRequest):
def __init__(self, tags: Optional[Dict[str, str]] = None,
application_details: Optional[ApplicationFormPrefill] = None,
allowed_application_types: [AllowedApplicationTypes] = None):
def __init__(
self,
relationships: [Dict[str, Relationship]],
idempotency_key: str = None,
tags: Optional[Dict[str, str]] = None,
application_details: Optional[ApplicationFormPrefill] = None,
allowed_application_types: [AllowedApplicationTypes] = None
):
self.idempotency_key = idempotency_key
self.tags = tags
self.application_details = application_details
self.allowed_application_types = allowed_application_types
self.relationships = relationships

def to_json_api(self) -> Dict:
payload = {
"data": {
"type": "applicationForm",
"attributes": {}
"attributes": {
"idempotencyKey": self.idempotency_key
},
"relationships": self.relationships,
}
}

Expand Down
27 changes: 15 additions & 12 deletions unit/models/codecs.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import json
from unit.models import *
from datetime import datetime, date

from unit.models.batch_release import BatchReleaseDTO
from unit.models.check_payment import CheckPaymentDTO
from unit.models.reward import RewardDTO
from unit.utils import date_utils
from unit.models.applicationForm import ApplicationFormDTO
from unit.models.applicationForm import ApplicationFormDTO, ApplicationFormV2DTO
from unit.models.application import IndividualApplicationDTO, BusinessApplicationDTO, ApplicationDocumentDTO
from unit.models.account import DepositAccountDTO, AccountLimitsDTO
from unit.models.customer import IndividualCustomerDTO, BusinessCustomerDTO
from unit.models.card import IndividualDebitCardDTO, BusinessDebitCardDTO, IndividualVirtualDebitCardDTO,\
BusinessVirtualDebitCardDTO, PinStatusDTO, CardLimitsDTO
from unit.models.transaction import *
from unit.models.payment import AchPaymentDTO, BookPaymentDTO, WirePaymentDTO, AchReceivedPaymentDTO, BillPaymentDTO, \
SimulateIncomingAchPaymentDTO
from unit.models.payment import AchPaymentDTO, BookPaymentDTO, WirePaymentDTO, AchReceivedPaymentDTO, BillPaymentDTO
from unit.models.customerToken import CustomerTokenDTO, CustomerVerificationTokenDTO
from unit.models.fee import FeeDTO
from unit.models.event import *
Expand Down Expand Up @@ -214,6 +208,9 @@
"applicationForm": lambda _id, _type, attributes, relationships:
ApplicationFormDTO.from_json_api(_id, _type, attributes, relationships),

"applicationFormV2": lambda _id, _type, attributes, relationships, links:
ApplicationFormV2DTO.from_json_api(_id, attributes, relationships, links),

"fee": lambda _id, _type, attributes, relationships:
FeeDTO.from_json_api(_id, _type, attributes, relationships),

Expand Down Expand Up @@ -361,6 +358,10 @@
def split_json_api_single_response(payload: Dict):
_id, _type, attributes = payload.get("id"), payload["type"], payload["attributes"]
relationships = None
links = None

if payload.get("links"):
links = payload.get("links")

if payload.get("relationships"):
relationships = dict()
Expand All @@ -371,7 +372,7 @@ def split_json_api_single_response(payload: Dict):
else:
relationships[k] = Relationship(v["data"]["type"], v["data"]["id"])

return _id, _type, attributes, relationships
return _id, _type, attributes, relationships, links


def split_json_api_array_response(payload):
Expand All @@ -391,8 +392,10 @@ def decode_limits(attributes: Dict):
else:
return CardLimitsDTO.from_json_api(attributes)

def mapping_wraper(_id, _type, attributes, relationships):
def mapping_wraper(_id, _type, attributes, relationships, links):
if _type in mappings:
if links:
return mappings[_type](_id, _type, attributes, relationships, links)
return mappings[_type](_id, _type, attributes, relationships)
else:
return RawUnitObject(_id, _type, attributes, relationships)
Expand All @@ -411,8 +414,8 @@ def decode(payload):

return response
else:
_id, _type, attributes, relationships = split_json_api_single_response(payload)
return mapping_wraper(_id, _type, attributes, relationships)
_id, _type, attributes, relationships, links = split_json_api_single_response(payload)
return mapping_wraper(_id, _type, attributes, relationships, links)

class UnitEncoder(json.JSONEncoder):
def default(self, obj):
Expand Down