Update an existing legal entity from a profile change event.
Only updates existing entities — does not create new ones.
Returns None if no entity exists or if it is terminated.
Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/policies/legal_entity_sync.py
| def on_profile_updated(
self,
unique_key: str,
**data: Unpack[LegalEntityUpdate],
) -> LegalEntityId | None:
"""Update an existing legal entity from a profile change event.
Only updates existing entities — does not create new ones.
Returns None if no entity exists or if it is terminated.
"""
existing = LegalEntityModelBroker.find_legal_entity_by_unique_key(
current_session, unique_key
)
if existing is None:
current_logger.info(
"No legal entity found for %s, skipping sync",
unique_key,
)
return None
if existing.is_terminated:
current_logger.info(
"Legal entity %s is terminated, skipping sync",
unique_key,
)
return None
legal_entity = LegalEntityModelBroker.upsert_legal_entity(
current_session, unique_key=unique_key, **data
)
return LegalEntityId(legal_entity.id)
|