diff --git a/unit/__init__.py b/unit/__init__.py index 7be2e41..8c40448 100644 --- a/unit/__init__.py +++ b/unit/__init__.py @@ -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"] @@ -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) diff --git a/unit/api/received_payment_resource.py b/unit/api/received_payment_resource.py index b453d6a..888fd89 100644 --- a/unit/api/received_payment_resource.py +++ b/unit/api/received_payment_resource.py @@ -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) diff --git a/unit/models/codecs.py b/unit/models/codecs.py index b8fbec3..6e78950 100644 --- a/unit/models/codecs.py +++ b/unit/models/codecs.py @@ -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), } diff --git a/unit/models/event.py b/unit/models/event.py index 64092e2..17d421f 100644 --- a/unit/models/event.py +++ b/unit/models/event.py @@ -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, @@ -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 ] diff --git a/unit/models/payment.py b/unit/models/payment.py index 984c69b..971b173 100644 --- a/unit/models/payment.py +++ b/unit/models/payment.py @@ -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 @@ -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],