Skip to content

Actions

components.payment_gateway.subcomponents.parties.protected.business_logic.actions.financial_instrument_actions

FinancialInstrumentActions

FinancialInstrumentActions()

Actions for financial instrument operations.

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/financial_instrument_actions.py
def __init__(
    self,
) -> None:
    pass

create classmethod

create()

Normal factory

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/financial_instrument_actions.py
@classmethod
def create(cls) -> "FinancialInstrumentActions":
    """Normal factory"""
    return cls()

create_iban_account_financial_instrument

create_iban_account_financial_instrument(
    session,
    /,
    *,
    legal_entity_id,
    iban,
    bank_country_code,
    bic,
)

Create an IBAN account financial instrument for the given legal entity.

Parameters:

Name Type Description Default
session Session

SQLAlchemy session to use for DB operations.

required
legal_entity_id LegalEntityId

ID of the legal entity owning the financial instrument.

required
iban str

IBAN of the bank account.

required
bank_country_code str

Country code of the bank in ISO 3166-1 alpha-2 format.

required
bic str | None

BIC/SWIFT code of the bank.

required

Returns:

Name Type Description
FinancialInstrumentId FinancialInstrumentId

ID of the newly created financial instrument.

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/financial_instrument_actions.py
def create_iban_account_financial_instrument(
    self,
    session: Session,
    /,
    *,
    legal_entity_id: LegalEntityId,
    iban: str,
    bank_country_code: str,
    bic: str | None,
) -> FinancialInstrumentId:
    """Create an IBAN account financial instrument for the given legal entity.

    Args:
        session: SQLAlchemy session to use for DB operations.
        legal_entity_id: ID of the legal entity owning the financial instrument.
        iban: IBAN of the bank account.
        bank_country_code: Country code of the bank in ISO 3166-1 alpha-2 format.
        bic: BIC/SWIFT code of the bank.

    Returns:
        FinancialInstrumentId: ID of the newly created financial instrument.
    """
    with raise_if_legal_entity_not_found(legal_entity_id):
        legal_entity = LegalEntityModelBroker.get_legal_entity(
            session, legal_entity_id
        )
    raise_on_terminated_legal_entity(legal_entity)

    financial_instrument = IBANAccountFinancialInstrumentModelBroker.create_iban_account_financial_instrument(
        session,
        legal_entity_id=legal_entity_id,
        iban=iban,
        bank_country_code=bank_country_code,
        bic=bic,
    )
    return FinancialInstrumentId(financial_instrument.id)

create_null classmethod

create_null()

Null factory

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/financial_instrument_actions.py
@classmethod
def create_null(cls) -> "FinancialInstrumentActions":
    """Null factory"""
    return cls()

terminate_financial_instrument

terminate_financial_instrument(session, /, id)

Terminate a financial instrument.

The operation is idempotent, i.e. it has no effect on already terminated entities.

Financial instruments in terminal state cannot be modified or used anymore. Any attempt to use or retrieve a terminated financial instrument will raise a FinancialInstrumentTerminatedException.

Parameters:

Name Type Description Default
session Session

SQLAlchemy session to use for DB operations.

required
id FinancialInstrumentId

ID of the financial instrument to terminate.

required
Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/financial_instrument_actions.py
def terminate_financial_instrument(
    self,
    session: Session,
    /,
    id: FinancialInstrumentId,
) -> None:
    """Terminate a financial instrument.

    The operation is idempotent, i.e. it has no effect on already terminated
    entities.

    Financial instruments in terminal state cannot be modified or used anymore.
    Any attempt to use or retrieve a terminated financial instrument will raise a
    `FinancialInstrumentTerminatedException`.

    Args:
        session: SQLAlchemy session to use for DB operations.
        id: ID of the financial instrument to terminate.
    """
    with raise_if_financial_instrument_not_found(id):
        financial_instrument = (
            FinancialInstrumentModelBroker.get_financial_instrument(session, id=id)
        )

    if not financial_instrument.is_terminated:
        FinancialInstrumentModelBroker.terminate_financial_instrument(
            session, id=id
        )

components.payment_gateway.subcomponents.parties.protected.business_logic.actions.legal_entity_actions

LegalEntityActions

LegalEntityActions()

Actions for legal entity operations.

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/legal_entity_actions.py
def __init__(
    self,
) -> None:
    pass

create classmethod

create()

Normal factory

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/legal_entity_actions.py
@classmethod
def create(cls) -> "LegalEntityActions":
    """Normal factory"""
    return cls()

create_null classmethod

create_null()

Null factory

Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/legal_entity_actions.py
@classmethod
def create_null(cls) -> "LegalEntityActions":
    """Null factory"""
    return cls()
terminate_legal_entity(session, /, id)

Terminate a legal entity.

The operation is idempotent, i.e. it has no effect on already terminated entities.

Legal entities in terminal state cannot be modified or used anymore. Any attempt to use or retrieve a terminated legal entity will raise a LegalEntityTerminatedException.

Parameters:

Name Type Description Default
session Session

The session to use for the database operations.

required
id LegalEntityId

The ID of the legal entity to terminate.

required
Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/legal_entity_actions.py
def terminate_legal_entity(
    self,
    session: Session,
    /,
    id: LegalEntityId,
) -> None:
    """Terminate a legal entity.

    The operation is idempotent, i.e. it has no effect on already terminated
    entities.

    Legal entities in terminal state cannot be modified or used anymore. Any
    attempt to use or retrieve a terminated legal entity will raise a
    `LegalEntityTerminatedException`.

    Args:
        session: The session to use for the database operations.
        id: The ID of the legal entity to terminate.
    """
    with raise_if_legal_entity_not_found(id):
        legal_entity = LegalEntityModelBroker.get_legal_entity(session, id)

    if not legal_entity.is_terminated:
        # Terminating an account should set its termination date on first call only
        LegalEntityModelBroker.terminate_legal_entity(session, id)
upsert_legal_entity(
    session,
    /,
    *,
    unique_key,
    entity_type,
    legal_name,
    first_name,
    last_name,
    legal_country_code,
    address_street,
    address_street_2,
    address_city,
    address_postal_code,
    address_country_code,
    address_subdivision_code,
)

Upsert a legal entity.

This is a full upsert operation. All fields must be provided and will override the existing values.

Parameters:

Name Type Description Default
session Session

The session to use for the database operations.

required
unique_key str

The unique key of the legal entity. If a legal entity with the same unique key already exists, it will be updated. Otherwise, a new legal entity will be created.

required
entity_type LegalEntityType

The type of the legal entity.

required
legal_name str

The legal name of the legal entity.

required
first_name str | None

The first name of the legal entity (persons only).

required
last_name str | None

The last name of the legal entity (persons only).

required
legal_country_code str

The country code of the legal entity in ISO 3166-1 alpha-2 format.

required
address_street str | None

The street address of the legal entity.

required
address_street_2 str | None

The street address 2 of the legal entity (apartment, floor, building, etc.).

required
address_city str | None

The city name of the legal entity.

required
address_postal_code str | None

The postal/ZIP code of the legal entity.

required
address_country_code str

The country of the physical address of the legal entity in ISO 3166-1 alpha-2 format.

required
address_subdivision_code str | None

The state/province/territory code of the legal entity in ISO 3166-2 format (e.g., "CA-ON", "FR-PF", "US-NY").

required
Source code in components/payment_gateway/subcomponents/parties/protected/business_logic/actions/legal_entity_actions.py
def upsert_legal_entity(
    self,
    session: Session,
    /,
    *,
    unique_key: str,
    entity_type: LegalEntityType,
    legal_name: str,
    first_name: str | None,
    last_name: str | None,
    legal_country_code: str,
    address_street: str | None,
    address_street_2: str | None,
    address_city: str | None,
    address_postal_code: str | None,
    address_country_code: str,
    address_subdivision_code: str | None,
) -> LegalEntityId:
    """Upsert a legal entity.

    This is a full upsert operation. All fields must be provided and will
    override the existing values.

    Args:
        session: The session to use for the database operations.
        unique_key: The unique key of the legal entity. If a legal entity
            with the same unique key already exists, it will be updated.
            Otherwise, a new legal entity will be created.
        entity_type: The type of the legal entity.
        legal_name: The legal name of the legal entity.
        first_name: The first name of the legal entity (persons only).
        last_name: The last name of the legal entity (persons only).
        legal_country_code: The country code of the legal entity in ISO
            3166-1 alpha-2 format.
        address_street: The street address of the legal entity.
        address_street_2: The street address 2 of the legal entity
            (apartment, floor, building, etc.).
        address_city: The city name of the legal entity.
        address_postal_code: The postal/ZIP code of the legal entity.
        address_country_code: The country of the physical address of the
            legal entity in ISO 3166-1 alpha-2 format.
        address_subdivision_code: The state/province/territory code of the
            legal entity in ISO 3166-2 format (e.g., "CA-ON", "FR-PF", "US-NY").
    """
    legal_entity = LegalEntityModelBroker.upsert_legal_entity(
        session,
        unique_key=unique_key,
        entity_type=entity_type,
        legal_name=legal_name,
        first_name=first_name,
        last_name=last_name,
        legal_country_code=legal_country_code,
        address_street=address_street,
        address_street_2=address_street_2,
        address_city=address_city,
        address_postal_code=address_postal_code,
        address_country_code=address_country_code,
        address_subdivision_code=address_subdivision_code,
    )
    return LegalEntityId(legal_entity.id)