Skip to content

components.payment_gateway.public.accounts

This module defines the public API for the accounts subcomponent.

Only business logic is exposed here. Basic entities and enums are exposed in separate modules to avoid loading the entire subcomponent with its models and dependencies when they are not needed.

Classes

AccountHolderLogic

AccountHolderLogic(
    account_holder_queries, account_holder_actions
)

This class is the public interface to the account holder logic.

Implements the following Nullable patterns: - Nullables: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#nullables ⧉ - Parameterless instantiation: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#instantiation ⧉

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
def __init__(
    self,
    account_holder_queries: AccountHolderQueries,
    account_holder_actions: AccountHolderActions,
) -> None:
    self.account_holder_queries = account_holder_queries
    self.account_holder_actions = account_holder_actions

Attributes

account_holder_actions instance-attribute
account_holder_actions = account_holder_actions
account_holder_queries instance-attribute
account_holder_queries = account_holder_queries

Functions

create classmethod
create()

Normal factory

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@classmethod
def create(cls) -> "AccountHolderLogic":
    """Normal factory"""
    return cls(
        AccountHolderQueries(),
        AccountHolderActions.create(),
    )
create_null classmethod
create_null()

Null factory

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@classmethod
def create_null(
    cls,
) -> "AccountHolderLogic":
    """Null factory"""
    return cls(
        AccountHolderQueries(),
        AccountHolderActions.create_null(),
    )
declare_account_holder
declare_account_holder(
    session, /, description, external_id, reference=None
)

Declare an account holder.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@obs.api_call()
def declare_account_holder(
    self,
    session: Session,
    /,
    description: str,
    external_id: str,
    reference: str | None = None,
) -> AccountHolderId:
    """
    Declare an account holder.
    """
    return self.account_holder_actions.declare_account_holder(
        session,
        description=description,
        external_id=external_id,
        reference=reference,
    )
get_account_holder
get_account_holder(session, /, id)

Get an account holder entity from its ID.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@obs.api_call()
def get_account_holder(
    self,
    session: Session,
    /,
    id: AccountHolderId,
) -> AccountHolder:
    """
    Get an account holder entity from its ID.
    """
    return self.account_holder_queries.get_account_holder(
        session,
        id,
    )
get_account_holder_id_by_external_id
get_account_holder_id_by_external_id(
    session, /, provider, external_id
)

Get an account holder entity from its external ID.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@obs.api_call()
def get_account_holder_id_by_external_id(
    self,
    session: Session,
    /,
    provider: PaymentServiceProvider,
    external_id: str,
) -> AccountHolderId:
    """
    Get an account holder entity from its external ID.
    """
    return self.account_holder_queries.get_account_holder_id_by_external_id(
        session,
        provider=provider,
        external_id=external_id,
    )
terminate_account_holder
terminate_account_holder(session, /, id)

Terminate an account holder.

Account holders in terminal state cannot be modified or used anymore.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@obs.api_call()
def terminate_account_holder(
    self,
    session: Session,
    /,
    id: AccountHolderId,
) -> None:
    """
    Terminate an account holder.

    Account holders in terminal state cannot be modified or used anymore.
    """
    self.account_holder_actions.terminate_account_holder(
        session,
        id,
    )
update_account_holder_legal_name(
    session, /, id, legal_name
)

Update the legal name of an account holder.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/account_holders.py
@obs.api_call()
def update_account_holder_legal_name(
    self,
    session: Session,
    /,
    id: AccountHolderId,
    legal_name: str,
) -> None:
    """
    Update the legal name of an account holder.
    """
    return self.account_holder_actions.update_account_holder_legal_name(
        session,
        id=id,
        legal_name=legal_name,
    )

AccountHolderNotFoundException

Bases: PaymentAccountException

Exception raised when trying to use a non-existing Account Holder.

AccountHolderTerminatedException

Bases: PaymentAccountException

Exception raised when trying to use a terminated Account Holder.

AccountLogic

AccountLogic(account_queries, account_actions)

This class is the public interface to the account logic.

Implements the following Nullable patterns: - Nullables: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#nullables ⧉ - Parameterless instantiation: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#instantiation ⧉

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
def __init__(
    self, account_queries: AccountQueries, account_actions: AccountActions
) -> None:
    self.account_queries = account_queries
    self.account_actions = account_actions

Attributes

account_actions instance-attribute
account_actions = account_actions
account_queries instance-attribute
account_queries = account_queries

Functions

activate_account
activate_account(session, /, id)

Activate an account.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def activate_account(
    self,
    session: Session,
    /,
    id: AccountId,
) -> None:
    """
    Activate an account.
    """
    self.account_actions.activate_account(
        session,
        id,
    )
create classmethod
create()

Normal factory

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@classmethod
def create(cls) -> "AccountLogic":
    """Normal factory"""
    return cls(
        AccountQueries(),
        AccountActions.create(),
    )
create_account
create_account(
    session,
    /,
    account_holder_id,
    description,
    reference=None,
)

Create an account for an account holder.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def create_account(
    self,
    session: Session,
    /,
    account_holder_id: AccountHolderId,
    description: str,
    reference: str | None = None,
) -> AccountId:
    """
    Create an account for an account holder.
    """
    return self.account_actions.create_account(
        session,
        account_holder_id=account_holder_id,
        description=description,
        reference=reference,
    )
create_null classmethod
create_null(track_adyen_requests=None)

Null factory

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@classmethod
def create_null(
    cls,
    track_adyen_requests: list[tuple[str, dict, dict]] | None = None,  # type: ignore[type-arg]
) -> "AccountLogic":
    """Null factory"""
    return cls(
        AccountQueries(),
        AccountActions.create_null(track_adyen_requests=track_adyen_requests),
    )
deactivate_account
deactivate_account(session, /, id)

Deactivate an account.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def deactivate_account(
    self,
    session: Session,
    /,
    id: AccountId,
) -> None:
    """
    Deactivate an account.
    """
    self.account_actions.deactivate_account(
        session,
        id,
    )
get_account
get_account(session, /, id)

Get an account entity from its ID.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def get_account(
    self,
    session: Session,
    /,
    id: AccountId,
) -> Account:
    """
    Get an account entity from its ID.
    """
    return self.account_queries.get_account(
        session,
        id,
    )
get_account_id_by_external_id
get_account_id_by_external_id(
    session, /, provider, external_id
)

Find an account using its external id.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def get_account_id_by_external_id(
    self,
    session: Session,
    /,
    provider: PaymentServiceProvider,
    external_id: str,
) -> AccountId:
    """
    Find an account using its external id.
    """
    return self.account_queries.get_account_id_by_external_id(
        session,
        provider=provider,
        external_id=external_id,
    )
get_account_ids_for_account_holder
get_account_ids_for_account_holder(
    session, /, account_holder_id
)

Get all the account IDs for an account holder.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def get_account_ids_for_account_holder(
    self,
    session: Session,
    /,
    account_holder_id: AccountHolderId,
) -> list[AccountId]:
    """
    Get all the account IDs for an account holder.
    """
    return self.account_queries.get_account_ids_for_account_holder(
        session,
        account_holder_id,
    )
get_accounts_for_account_holder
get_accounts_for_account_holder(
    session, /, account_holder_id
)

Get all the accounts for an account holder.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def get_accounts_for_account_holder(
    self,
    session: Session,
    /,
    account_holder_id: AccountHolderId,
) -> list[Account]:
    """
    Get all the accounts for an account holder.
    """
    return self.account_queries.get_accounts_for_account_holder(
        session,
        account_holder_id,
    )
terminate_account
terminate_account(session, /, id)

Terminate an account.

Accounts in terminal state cannot be modified or used anymore.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def terminate_account(
    self,
    session: Session,
    /,
    id: AccountId,
) -> None:
    """
    Terminate an account.

    Accounts in terminal state cannot be modified or used anymore.
    """
    self.account_actions.terminate_account(
        session,
        id,
    )
update_account
update_account(session, /, id, description, reference=None)

Update the account description and reference

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/accounts.py
@obs.api_call()
def update_account(
    self,
    session: Session,
    /,
    id: AccountId,
    description: str,
    reference: str | None = None,
) -> None:
    """
    Update the account description and reference
    """
    return self.account_actions.update_account(
        session,
        id=id,
        description=description,
        reference=reference,
    )

AccountNotFoundException

Bases: PaymentAccountException

Exception raised when trying to use a non-existing Account.

AccountTerminatedException

Bases: PaymentAccountException

Exception raised when trying to use a terminated Account.

InvalidAccountStatusTransitionException

Bases: PaymentAccountException, ValueError

Exception raised when attempting an invalid Account status transition.

PaymentAccountException

Bases: PaymentGatewayException

Base class for all Account exceptions.

SepaBeneficiaryLogic

This class is the public interface to the SEPA beneficiaries logic.

Functions

create_sepa_beneficiary
create_sepa_beneficiary(
    session,
    /,
    account_id,
    provider,
    external_id,
    issued_at,
    name,
    iban,
    status=SepaBeneficiaryStatus.enabled,
)

Create a new SEPA beneficiary on the given account.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/sepa_beneficiaries.py
@obs.api_call()
def create_sepa_beneficiary(
    self,
    session: Session,
    /,
    account_id: AccountId,
    provider: PaymentServiceProvider,
    external_id: str,
    issued_at: datetime,
    name: str,
    iban: str,
    status: SepaBeneficiaryStatus = SepaBeneficiaryStatus.enabled,
) -> SepaBeneficiary:
    """
    Create a new SEPA beneficiary on the given account.
    """
    sepa_beneficiary = SepaBeneficiaryModelBroker.create_sepa_beneficiary(
        session,
        status=status,
        account_id=account_id,
        provider=provider,
        external_id=external_id,
        issued_at=issued_at,
        name=name,
        iban=iban,
    )

    return _to_sepa_beneficiary(sepa_beneficiary_model=sepa_beneficiary)
get_sepa_beneficiary
get_sepa_beneficiary(session, /, id)

Get a SEPA beneficiary entity from its ID.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/sepa_beneficiaries.py
@obs.api_call()
def get_sepa_beneficiary(
    self,
    session: Session,
    /,
    id: SepaBeneficiaryId,
) -> SepaBeneficiary:
    """
    Get a SEPA beneficiary entity from its ID.
    """
    with raise_if_sepa_beneficiary_not_found(id):
        sepa_beneficiary = SepaBeneficiaryModelBroker.get_sepa_beneficiary(
            session,
            id=id,
        )

    return _to_sepa_beneficiary(sepa_beneficiary_model=sepa_beneficiary)
get_sepa_beneficiary_by_external_id
get_sepa_beneficiary_by_external_id(
    session, /, provider, external_id
)

Find a SEPA beneficiary by its external ID.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/sepa_beneficiaries.py
@obs.api_call()
def get_sepa_beneficiary_by_external_id(
    self,
    session: Session,
    /,
    provider: PaymentServiceProvider,
    external_id: str,
) -> Optional[SepaBeneficiary]:
    """
    Find a SEPA beneficiary by its external ID.
    """
    with raise_if_sepa_beneficiary_not_found_for_external_id(external_id):
        sepa_beneficiary = (
            SepaBeneficiaryModelBroker.find_sepa_beneficiary_by_external_id(
                session,
                provider=provider,
                external_id=external_id,
            )
        )

    return (
        _to_sepa_beneficiary(sepa_beneficiary_model=sepa_beneficiary)
        if sepa_beneficiary is not None
        else None
    )
set_sepa_beneficiary_status
set_sepa_beneficiary_status(session, /, id, status)

Update the status of the given SEPA beneficiary.

Source code in components/payment_gateway/subcomponents/accounts/protected/business_logic/sepa_beneficiaries.py
@obs.api_call()
def set_sepa_beneficiary_status(
    self,
    session: Session,
    /,
    id: SepaBeneficiaryId,
    status: SepaBeneficiaryStatus,
) -> None:
    """
    Update the status of the given SEPA beneficiary.
    """
    with raise_if_sepa_beneficiary_not_found(id):
        SepaBeneficiaryModelBroker.set_sepa_beneficiary_status(
            session,
            id=id,
            status=status,
        )