From 10ac731b557e51ac7555622f7a64d381d791b109 Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 12:58:51 -0400 Subject: [PATCH 1/7] applications/check-registered-agent-address --- unit/api/application_resource.py | 14 +++++++ unit/api/check_registered_address.py | 21 ++++++++++ unit/models/check_registered_address.py | 51 +++++++++++++++++++++++++ unit/models/event.py | 1 + 4 files changed, 87 insertions(+) create mode 100644 unit/api/check_registered_address.py create mode 100644 unit/models/check_registered_address.py diff --git a/unit/api/application_resource.py b/unit/api/application_resource.py index 82d041e7..21cef727 100644 --- a/unit/api/application_resource.py +++ b/unit/api/application_resource.py @@ -71,6 +71,20 @@ def update(self, request: PatchApplicationRequest) -> Union[UnitResponse[Applica else: return UnitError.from_json_api(response.json()) + def check_registered_agent_address(self, request: Union[CreateIndividualApplicationRequest, CreateBusinessApplicationRequest]) -> Union[UnitResponse[ApplicationDTO], UnitError]: + payload = request.to_json_api() + response = super().post(f"{self.resource}/check-registered-agent-address", payload) + + if response.ok: + data = response.json().get("data") + included = response.json().get("included") + if data["type"] == "individualApplication": + return UnitResponse[IndividualApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) + else: + return UnitResponse[BusinessApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) + else: + return UnitError.from_json_api(response.json()) + def approve_sb(self, request: ApproveApplicationSBRequest): url = f"sandbox/{self.resource}/{request.application_id}/approve" diff --git a/unit/api/check_registered_address.py b/unit/api/check_registered_address.py new file mode 100644 index 00000000..dfdd27a5 --- /dev/null +++ b/unit/api/check_registered_address.py @@ -0,0 +1,21 @@ +from unit.api.base_resource import BaseResource +from unit.models.application import * +from unit.models.check_registered_address import CheckRegisteredAddressRequest, CheckRegisteredAddressResponse +from unit.models.codecs import DtoDecoder + + +class CheckRegisteredAddressResource(BaseResource): + def __init__(self, api_url, token): + super().__init__(api_url, token) + self.resource = "applications/check-registered-agent-address" + + def create(self, request: CheckRegisteredAddressRequest) -> Union[UnitResponse[CheckRegisteredAddressResponse], UnitError]: + payload = request.to_json_api() + response = super().post(self.resource, payload) + + if response.ok: + data = response.json().get("data") + return UnitResponse[CheckRegisteredAddressResponse](DtoDecoder.decode(data), None) + else: + return UnitError.from_json_api(response.json()) + diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py new file mode 100644 index 00000000..e61713ad --- /dev/null +++ b/unit/models/check_registered_address.py @@ -0,0 +1,51 @@ +from unit.models import * + + + +class CheckRegisteredAddressRequest(UnitDTO): + def __init__( + self, + street: str, + city: str, + state: str, + postal_code: str, + country: str, + street2: Optional[str] = None, + ): + self.type = "checkRegisteredAgentAddress" + + self.attributes = { + "street": street, + "city": city, + "state": state, + "postalCode": postal_code, + "country": country, + "street2": street2, + } + + def to_json_api(self) -> Dict: + payload = { + "data": { + "type": "individualApplication", + "attributes": self.attributes, + } + } + return payload + + +class CheckRegisteredAddressResponse(UnitDTO): + def __init__( + self, + is_registered_agent_address: bool, + ): + self.type = "checkRegisteredAgentAddress" + self.is_registered_agent_address = is_registered_agent_address + self.attributes = { + "isRegisteredAgentAddress": is_registered_agent_address, + } + + @staticmethod + def from_json_api(data: Dict): + return CheckRegisteredAddressRequest( + data.get("isRegisteredAgentAddress"), + ) diff --git a/unit/models/event.py b/unit/models/event.py index a9d2e286..ace181e7 100644 --- a/unit/models/event.py +++ b/unit/models/event.py @@ -913,6 +913,7 @@ def from_json_api(_id, _type, attributes, relationships): StatementsCreatedEvent, TransactionCreatedEvent, AccountReopenedEvent, RawUnitObject, StopPaymentCreatedEvent, StopPaymentPaymentStoppedEvent, StopPaymentDisabledEvent, DisputeCreatedEvent, DisputeStatusChangedEvent, ReceivedPaymentCreatedEvent + ] From 2298c92ed23eb9b69d9e4495ac891d397688037c Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 13:00:34 -0400 Subject: [PATCH 2/7] remove unused code --- unit/api/application_resource.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/unit/api/application_resource.py b/unit/api/application_resource.py index 21cef727..82d041e7 100644 --- a/unit/api/application_resource.py +++ b/unit/api/application_resource.py @@ -71,20 +71,6 @@ def update(self, request: PatchApplicationRequest) -> Union[UnitResponse[Applica else: return UnitError.from_json_api(response.json()) - def check_registered_agent_address(self, request: Union[CreateIndividualApplicationRequest, CreateBusinessApplicationRequest]) -> Union[UnitResponse[ApplicationDTO], UnitError]: - payload = request.to_json_api() - response = super().post(f"{self.resource}/check-registered-agent-address", payload) - - if response.ok: - data = response.json().get("data") - included = response.json().get("included") - if data["type"] == "individualApplication": - return UnitResponse[IndividualApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) - else: - return UnitResponse[BusinessApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) - else: - return UnitError.from_json_api(response.json()) - def approve_sb(self, request: ApproveApplicationSBRequest): url = f"sandbox/{self.resource}/{request.application_id}/approve" From c2861674bb676641dd52dffecbc68dcd54654564 Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 13:01:13 -0400 Subject: [PATCH 3/7] Remove blank space --- unit/models/event.py | 1 - 1 file changed, 1 deletion(-) diff --git a/unit/models/event.py b/unit/models/event.py index ace181e7..a9d2e286 100644 --- a/unit/models/event.py +++ b/unit/models/event.py @@ -913,7 +913,6 @@ def from_json_api(_id, _type, attributes, relationships): StatementsCreatedEvent, TransactionCreatedEvent, AccountReopenedEvent, RawUnitObject, StopPaymentCreatedEvent, StopPaymentPaymentStoppedEvent, StopPaymentDisabledEvent, DisputeCreatedEvent, DisputeStatusChangedEvent, ReceivedPaymentCreatedEvent - ] From b7c19039d882be95f7d9b5cba0094c7232a85097 Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 13:17:13 -0400 Subject: [PATCH 4/7] MR Feedback --- unit/__init__.py | 2 ++ unit/api/check_registered_address.py | 2 +- unit/models/check_registered_address.py | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/unit/__init__.py b/unit/__init__.py index 8c404483..371846ce 100644 --- a/unit/__init__.py +++ b/unit/__init__.py @@ -28,6 +28,7 @@ from unit.api.reward_resource import RewardResource from unit.api.dispute_resource import DisputeResource from unit.api.received_payment_resource import ReceivedPaymentResource +from unit.api.check_registered_address import CheckRegisteredAddressResource __all__ = ["api", "models", "utils"] @@ -64,3 +65,4 @@ def __init__(self, api_url, token): self.check_stop_payments = CheckStopPaymentResource(api_url, token) self.disputes = DisputeResource(api_url, token) self.received_payments = ReceivedPaymentResource(api_url, token) + self.check_registered_address = CheckRegisteredAddressResource(api_url, token) diff --git a/unit/api/check_registered_address.py b/unit/api/check_registered_address.py index dfdd27a5..b6ae299e 100644 --- a/unit/api/check_registered_address.py +++ b/unit/api/check_registered_address.py @@ -1,5 +1,5 @@ from unit.api.base_resource import BaseResource -from unit.models.application import * +from unit.models import * from unit.models.check_registered_address import CheckRegisteredAddressRequest, CheckRegisteredAddressResponse from unit.models.codecs import DtoDecoder diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py index e61713ad..2b9f0f46 100644 --- a/unit/models/check_registered_address.py +++ b/unit/models/check_registered_address.py @@ -20,9 +20,11 @@ def __init__( "state": state, "postalCode": postal_code, "country": country, - "street2": street2, } + if street2: + self.attributes["street2"] = street2 + def to_json_api(self) -> Dict: payload = { "data": { @@ -45,7 +47,7 @@ def __init__( } @staticmethod - def from_json_api(data: Dict): - return CheckRegisteredAddressRequest( - data.get("isRegisteredAgentAddress"), + def from_json_api(_id, _type, attributes, relationships): + return CheckRegisteredAddressResponse( + attributes.get("isRegisteredAgentAddress"), ) From 3f02a895da2eeb1c9dc1e1168925177a10a24aae Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 13:18:16 -0400 Subject: [PATCH 5/7] Fix type --- unit/models/check_registered_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py index 2b9f0f46..14451de6 100644 --- a/unit/models/check_registered_address.py +++ b/unit/models/check_registered_address.py @@ -28,7 +28,7 @@ def __init__( def to_json_api(self) -> Dict: payload = { "data": { - "type": "individualApplication", + "type": self.type, "attributes": self.attributes, } } From 5b7d74fab7e0f4504ca15d79eca7337015e4e190 Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 15:08:26 -0400 Subject: [PATCH 6/7] Inherit request --- unit/models/check_registered_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py index 14451de6..d453b4e6 100644 --- a/unit/models/check_registered_address.py +++ b/unit/models/check_registered_address.py @@ -2,7 +2,7 @@ -class CheckRegisteredAddressRequest(UnitDTO): +class CheckRegisteredAddressRequest(UnitRequest): def __init__( self, street: str, From d0109357edcd6b902509fcec56dd918877135025 Mon Sep 17 00:00:00 2001 From: Avery Kushner Date: Wed, 22 Oct 2025 15:56:25 -0400 Subject: [PATCH 7/7] Fix attrs --- unit/models/check_registered_address.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py index d453b4e6..6862a4c8 100644 --- a/unit/models/check_registered_address.py +++ b/unit/models/check_registered_address.py @@ -15,15 +15,17 @@ def __init__( self.type = "checkRegisteredAgentAddress" self.attributes = { - "street": street, - "city": city, - "state": state, - "postalCode": postal_code, - "country": country, + "address": { + "street": street, + "city": city, + "state": state, + "postalCode": postal_code, + "country": country, + } } if street2: - self.attributes["street2"] = street2 + self.attributes["address"]["street2"] = street2 def to_json_api(self) -> Dict: payload = {