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
16 changes: 16 additions & 0 deletions unit/api/authorization_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def get(self, authorization_id: str, include_non_authorized: Optional[bool] = Fa
def list(self, params: ListAuthorizationParams = None) -> Union[UnitResponse[List[AuthorizationDTO]], UnitError]:
params = params or ListAuthorizationParams()
response = super().get(self.resource, params.to_dict())
if super().is_20x(response.status_code):
data = response.json().get("data")
return UnitResponse[AuthorizationDTO](DtoDecoder.decode(data), None)
else:
return UnitError.from_json_api(response.json())

def sandbox_increase(self, request: SimulateAuthorizationIncrease) -> Union[UnitResponse[AuthorizationDTO], UnitError]:
response = super().post(f"sandbox/{self.resource}/{request.authorization_id}/increase", request.to_json_api())
if super().is_20x(response.status_code):
data = response.json().get("data")
return UnitResponse[AuthorizationDTO](DtoDecoder.decode(data), None)
else:
return UnitError.from_json_api(response.json())

def sandbox_cancel(self, request: SimulateAuthorizationCancel) -> Union[UnitResponse[AuthorizationDTO], UnitError]:
response = super().post(f"sandbox/{self.resource}/{request.authorization_id}/cancel", request.to_json_api())
if super().is_20x(response.status_code):
data = response.json().get("data")
return UnitResponse[AuthorizationDTO](DtoDecoder.decode(data), None)
Expand Down
38 changes: 38 additions & 0 deletions unit/models/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,41 @@ def to_dict(self) -> Dict:
if self.sort:
parameters["sort"] = self.sort
return parameters


class SimulateAuthorizationIncrease(UnitRequest):
def __init__(self, authorization_id: str, amount: int, card_last_4_digits: str, account_id: str):
self.authorization_id = authorization_id
self.amount = amount
self.card_last_4_digits = card_last_4_digits
self.account_id = account_id

def to_json_api(self) -> Dict:
return {
"data": {
"type": "authorization",
"attributes": {
"amount": self.amount,
"cardLast4Digits": self.card_last_4_digits,
},
"relationships": {
"account": {"data": {"type": "depositAccount", "id": self.account_id}}
},
}
}


class SimulateAuthorizationCancel(UnitRequest):
def __init__(self, authorization_id: str, account_id: str):
self.authorization_id = authorization_id
self.account_id = account_id

def to_json_api(self) -> Dict:
return {
"data": {
"type": "authorization",
"relationships": {
"account": {"data": {"type": "depositAccount", "id": self.account_id}}
},
}
}
Loading