Skip to content

Commit d6993ce

Browse files
authored
Merge pull request #46 from MazumaGo/eng-1335-handle-receivedpaymentmarkedforreturn-event
ENG-1335: handle receivedpaymentmarkedforreturn event
2 parents 95aeefe + 16520ea commit d6993ce

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

unit/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from unit.api.account_end_of_day_resource import AccountEndOfDayResource
2828
from unit.api.reward_resource import RewardResource
2929
from unit.api.dispute_resource import DisputeResource
30+
from unit.api.received_payment_resource import ReceivedPaymentResource
3031

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

@@ -62,3 +63,4 @@ def __init__(self, api_url, token):
6263
self.check_payments = CheckPaymentResource(api_url, token)
6364
self.check_stop_payments = CheckStopPaymentResource(api_url, token)
6465
self.disputes = DisputeResource(api_url, token)
66+
self.received_payments = ReceivedPaymentResource(api_url, token)

unit/api/received_payment_resource.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def list(self, params: ListReceivedPaymentParams = None) -> Union[UnitResponse[L
3838

3939
def advance(self, payment_id: str) -> Union[UnitResponse[AchReceivedPaymentDTO], UnitError]:
4040
response = super().post(f"{self.resource}/{payment_id}/advance")
41+
if response.status_code == 200:
42+
data = response.json().get("data")
43+
return UnitResponse[AchReceivedPaymentDTO](DtoDecoder.decode(data), None)
44+
else:
45+
return UnitError.from_json_api(response.json())
46+
47+
def reprocess(self, payment_id: str) -> Union[UnitResponse[AchReceivedPaymentDTO], UnitError]:
48+
response = super().post(f"{self.resource}/{payment_id}/reprocess")
4149
if response.status_code == 200:
4250
data = response.json().get("data")
4351
return UnitResponse[AchReceivedPaymentDTO](DtoDecoder.decode(data), None)

unit/models/codecs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@
370370
"negativeBalanceCoverageTransaction": lambda _id, _type, attributes, relationships:
371371
NegativeBalanceCoverageTransactionDTO.from_json_api(_id, _type, attributes, relationships),
372372

373+
"receivedPayment.created": lambda _id, _type, attributes, relationships:
374+
ReceivedPaymentCreatedEvent.from_json_api(_id, _type, attributes, relationships),
373375
}
374376

375377

unit/models/event.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,48 @@ def from_json_api(_id, _type, attributes, relationships):
761761
return DisputeStatusChangedEvent(_id, date_utils.to_datetime(attributes["createdAt"]), attributes["previousStatus"],
762762
attributes["newStatus"], attributes.get("tags"), relationships)
763763

764+
class ReceivedPaymentCreatedEvent(BaseEvent):
765+
def __init__(self, id: str, created_at: datetime,
766+
status: str,
767+
type: str,
768+
amount: int,
769+
completion_date: date,
770+
company_name: str,
771+
counterparty_routing_number: str,
772+
description: str,
773+
trace_number: str,
774+
sec_code: str,
775+
return_cutoff_time: Optional[datetime],
776+
can_be_reprocessed: Optional[bool],
777+
addenda: Optional[str],
778+
tags: Optional[Dict[str, str]],
779+
relationships: Optional[Dict[str, Relationship]]):
780+
BaseEvent.__init__(self, id, created_at, tags, relationships)
781+
self.attributes["status"] = status
782+
self.attributes["type"] = type
783+
self.attributes["amount"] = amount
784+
self.attributes["completionDate"] = completion_date
785+
self.attributes["companyName"] = company_name
786+
self.attributes["counterpartyRoutingNumber"] = counterparty_routing_number
787+
self.attributes["description"] = description
788+
self.attributes["traceNumber"] = trace_number
789+
self.attributes["secCode"] = sec_code
790+
self.attributes["returnCutoffTime"] = return_cutoff_time
791+
self.attributes["canBeReprocessed"] = can_be_reprocessed
792+
self.attributes["addenda"] = addenda
793+
794+
self.type = 'receivedPayment.created'
795+
796+
@staticmethod
797+
def from_json_api(_id, _type, attributes, relationships):
798+
return ReceivedPaymentCreatedEvent(_id, date_utils.to_datetime(attributes["createdAt"]),
799+
attributes["status"], attributes["type"], attributes["amount"],
800+
attributes["completionDate"], attributes["companyName"],
801+
attributes["counterpartyRoutingNumber"], attributes["description"],
802+
attributes["traceNumber"], attributes["secCode"],
803+
attributes.get("returnCutoffTime"), attributes.get("canBeReprocessed"),
804+
attributes.get("addenda"), attributes.get("tags"), relationships)
805+
764806

765807
EventDTO = Union[
766808
AccountClosedEvent, AccountFrozenEvent, ApplicationDeniedEvent, ApplicationAwaitingDocumentsEvent,
@@ -778,7 +820,7 @@ def from_json_api(_id, _type, attributes, relationships):
778820
CustomerCreatedEvent, PaymentClearingEvent, PaymentSentEvent, PaymentReturnedEvent,
779821
StatementsCreatedEvent, TransactionCreatedEvent, AccountReopenedEvent, RawUnitObject,
780822
StopPaymentCreatedEvent, StopPaymentPaymentStoppedEvent, StopPaymentDisabledEvent,
781-
DisputeCreatedEvent, DisputeStatusChangedEvent,
823+
DisputeCreatedEvent, DisputeStatusChangedEvent, ReceivedPaymentCreatedEvent
782824
]
783825

784826

unit/models/payment.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,15 @@ class AchReceivedPaymentDTO(object):
149149
def __init__(self, id: str, created_at: datetime, status: AchReceivedPaymentStatus, was_advanced: bool,
150150
completion_date: datetime, return_reason: Optional[str], amount: int, description: str,
151151
addenda: Optional[str], company_name: str, counterparty_routing_number: str, trace_number: str,
152-
sec_code: Optional[str], tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]):
152+
sec_code: Optional[str], return_cutoff_time: Optional[datetime], can_be_reprocessed: Optional[bool],
153+
tags: Optional[Dict[str, str]], relationships: Optional[Dict[str, Relationship]]):
153154
self.type = "achReceivedPayment"
154155
self.attributes = {"createdAt": created_at, "status": status, "wasAdvanced": was_advanced,
155156
"completionDate": completion_date, "returnReason": return_reason, "description": description,
156157
"amount": amount, "addenda": addenda, "companyName": company_name,
157158
"counterpartyRoutingNumber": counterparty_routing_number, "traceNumber": trace_number,
158-
"secCode": sec_code, "tags": tags}
159+
"secCode": sec_code, "returnCutoffTime": return_cutoff_time, "canBeReprocessed": can_be_reprocessed,
160+
"tags": tags}
159161
self.relationships = relationships
160162

161163
@staticmethod
@@ -165,7 +167,8 @@ def from_json_api(_id, _type, attributes, relationships):
165167
attributes.get("returnReason"),attributes["amount"], attributes["description"],
166168
attributes.get("addenda"), attributes.get("companyName"),
167169
attributes.get("counterpartyRoutingNumber"), attributes.get("traceNumber"),
168-
attributes.get("secCode"), attributes.get("tags"), relationships)
170+
attributes.get("secCode"), attributes.get("returnCutoffTime"), attributes.get("canBeReprocessed"),
171+
attributes.get("tags"), relationships)
169172

170173
class CreatePaymentBaseRequest(UnitRequest):
171174
def __init__(self, amount: int, description: str, relationships: Dict[str, Relationship],

0 commit comments

Comments
 (0)