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
2 changes: 2 additions & 0 deletions unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from unit.api.account_end_of_day_resource import AccountEndOfDayResource
from unit.api.reward_resource import RewardResource
from unit.api.dispute_resource import DisputeResource
from unit.api.received_payment_resource import ReceivedPaymentResource

__all__ = ["api", "models", "utils"]

Expand Down Expand Up @@ -62,3 +63,4 @@ def __init__(self, api_url, token):
self.check_payments = CheckPaymentResource(api_url, token)
self.check_stop_payments = CheckStopPaymentResource(api_url, token)
self.disputes = DisputeResource(api_url, token)
self.received_payments = ReceivedPaymentResource(api_url, token)
8 changes: 8 additions & 0 deletions unit/api/received_payment_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def list(self, params: ListReceivedPaymentParams = None) -> Union[UnitResponse[L

def advance(self, payment_id: str) -> Union[UnitResponse[AchReceivedPaymentDTO], UnitError]:
response = super().post(f"{self.resource}/{payment_id}/advance")
if response.status_code == 200:
data = response.json().get("data")
return UnitResponse[AchReceivedPaymentDTO](DtoDecoder.decode(data), None)
else:
return UnitError.from_json_api(response.json())

def reprocess(self, payment_id: str) -> Union[UnitResponse[AchReceivedPaymentDTO], UnitError]:
response = super().post(f"{self.resource}/{payment_id}/reprocess")
if response.status_code == 200:
data = response.json().get("data")
return UnitResponse[AchReceivedPaymentDTO](DtoDecoder.decode(data), None)
Expand Down
2 changes: 2 additions & 0 deletions unit/models/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@
"negativeBalanceCoverageTransaction": lambda _id, _type, attributes, relationships:
NegativeBalanceCoverageTransactionDTO.from_json_api(_id, _type, attributes, relationships),

"receivedPayment.created": lambda _id, _type, attributes, relationships:
ReceivedPaymentCreatedEvent.from_json_api(_id, _type, attributes, relationships),
}


Expand Down
44 changes: 43 additions & 1 deletion unit/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,48 @@ def from_json_api(_id, _type, attributes, relationships):
return DisputeStatusChangedEvent(_id, date_utils.to_datetime(attributes["createdAt"]), attributes["previousStatus"],
attributes["newStatus"], attributes.get("tags"), relationships)

class ReceivedPaymentCreatedEvent(BaseEvent):
def __init__(self, id: str, created_at: datetime,
status: str,
type: str,
amount: int,
completion_date: date,
company_name: str,
counterparty_routing_number: str,
description: str,
trace_number: str,
sec_code: str,
return_cutoff_time: Optional[datetime],
can_be_reprocessed: Optional[bool],
addenda: Optional[str],
tags: Optional[Dict[str, str]],
relationships: Optional[Dict[str, Relationship]]):
BaseEvent.__init__(self, id, created_at, tags, relationships)
self.attributes["status"] = status
self.attributes["type"] = type
self.attributes["amount"] = amount
self.attributes["completionDate"] = completion_date
self.attributes["companyName"] = company_name
self.attributes["counterpartyRoutingNumber"] = counterparty_routing_number
self.attributes["description"] = description
self.attributes["traceNumber"] = trace_number
self.attributes["secCode"] = sec_code
self.attributes["returnCutoffTime"] = return_cutoff_time
self.attributes["canBeReprocessed"] = can_be_reprocessed
self.attributes["addenda"] = addenda

self.type = 'receivedPayment.created'

@staticmethod
def from_json_api(_id, _type, attributes, relationships):
return ReceivedPaymentCreatedEvent(_id, date_utils.to_datetime(attributes["createdAt"]),
attributes["status"], attributes["type"], attributes["amount"],
attributes["completionDate"], attributes["companyName"],
attributes["counterpartyRoutingNumber"], attributes["description"],
attributes["traceNumber"], attributes["secCode"],
attributes.get("returnCutoffTime"), attributes.get("canBeReprocessed"),
attributes.get("addenda"), attributes.get("tags"), relationships)


EventDTO = Union[
AccountClosedEvent, AccountFrozenEvent, ApplicationDeniedEvent, ApplicationAwaitingDocumentsEvent,
Expand All @@ -778,7 +820,7 @@ def from_json_api(_id, _type, attributes, relationships):
CustomerCreatedEvent, PaymentClearingEvent, PaymentSentEvent, PaymentReturnedEvent,
StatementsCreatedEvent, TransactionCreatedEvent, AccountReopenedEvent, RawUnitObject,
StopPaymentCreatedEvent, StopPaymentPaymentStoppedEvent, StopPaymentDisabledEvent,
DisputeCreatedEvent, DisputeStatusChangedEvent,
DisputeCreatedEvent, DisputeStatusChangedEvent, ReceivedPaymentCreatedEvent
]


Expand Down
9 changes: 6 additions & 3 deletions unit/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ class AchReceivedPaymentDTO(object):
def __init__(self, id: str, created_at: datetime, status: AchReceivedPaymentStatus, was_advanced: bool,
completion_date: datetime, return_reason: Optional[str], amount: int, description: str,
addenda: Optional[str], company_name: str, counterparty_routing_number: str, trace_number: str,
sec_code: Optional[str], tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]):
sec_code: Optional[str], return_cutoff_time: Optional[datetime], can_be_reprocessed: Optional[bool],
tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]):
self.type = "achReceivedPayment"
self.attributes = {"createdAt": created_at, "status": status, "wasAdvanced": was_advanced,
"completionDate": completion_date, "returnReason": return_reason, "description": description,
"amount": amount, "addenda": addenda, "companyName": company_name,
"counterpartyRoutingNumber": counterparty_routing_number, "traceNumber": trace_number,
"secCode": sec_code, "tags": tags}
"secCode": sec_code, "returnCutoffTime": return_cutoff_time, "canBeReprocessed": can_be_reprocessed,
"tags": tags}
self.relationships = relationships

@staticmethod
Expand All @@ -165,7 +167,8 @@ def from_json_api(_id, _type, attributes, relationships):
attributes.get("returnReason"),attributes["amount"], attributes["description"],
attributes.get("addenda"), attributes.get("companyName"),
attributes.get("counterpartyRoutingNumber"), attributes.get("traceNumber"),
attributes.get("secCode"), attributes.get("tags"), relationships)
attributes.get("secCode"), attributes.get("returnCutoffTime"), attributes.get("canBeReprocessed"),
attributes.get("tags"), relationships)

class CreatePaymentBaseRequest(UnitRequest):
def __init__(self, amount: int, description: str, relationships: Dict[str, Relationship],
Expand Down
Loading