Skip to content

Models

components.payment_gateway.subcomponents.accounts.models.account

Account

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "provider",
        "external_id",
        name="account__unique_external_id_per_provider",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'account'

account_holder class-attribute instance-attribute

account_holder = relationship(
    AccountHolder,
    foreign_keys=account_holder_id,
    back_populates="accounts",
)

account_holder_id class-attribute instance-attribute

account_holder_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    index=True,
    nullable=True,
)

account_transfers class-attribute instance-attribute

account_transfers = relationship(
    "AccountTransfer",
    back_populates="account",
    order_by="AccountTransfer.created_at.desc()",
    uselist=True,
    viewonly=True,
)

bank_transfers class-attribute instance-attribute

bank_transfers = relationship(
    "BankTransfer",
    back_populates="account",
    order_by="BankTransfer.created_at.desc()",
    uselist=True,
    viewonly=True,
)

card_payments class-attribute instance-attribute

card_payments = relationship(
    "CardTransfer",
    back_populates="account",
    order_by="CardTransfer.created_at.desc()",
    uselist=True,
    viewonly=True,
)

current_status_log class-attribute instance-attribute

current_status_log = relationship(
    "AccountStatusLog",
    uselist=False,
    viewonly=True,
    primaryjoin=f"and_(  AccountStatusLog.account_id == {ACCOUNT_MODEL}.id,   AccountStatusLog.created_at == (       select(func.max(AccountStatusLog.created_at))      .where(AccountStatusLog.account_id == {ACCOUNT_MODEL}.id)      .correlate({ACCOUNT_MODEL})       .scalar_subquery()   ))",
)

description class-attribute instance-attribute

description = mapped_column(Text, nullable=False)

external_id class-attribute instance-attribute

external_id = mapped_column(
    String(255), nullable=False, index=True
)

ID used by the external payment service provider to identify the account.

is_terminated property

is_terminated

provider class-attribute instance-attribute

provider = mapped_column(
    AlanBaseEnumTypeDecorator(PaymentServiceProvider),
    nullable=False,
)

The payment service provider that manages the account.

reference class-attribute instance-attribute

reference = mapped_column(Text, nullable=True)

sepa_beneficiaries class-attribute instance-attribute

sepa_beneficiaries = relationship(
    "SepaBeneficiary",
    back_populates="account",
    order_by="SepaBeneficiary.created_at.desc()",
    uselist=True,
    viewonly=True,
)

status property

status

status_history class-attribute instance-attribute

status_history = relationship(
    "AccountStatusLog",
    back_populates="account",
    order_by="AccountStatusLog.created_at.desc()",
    uselist=True,
    viewonly=True,
)

terminated_at class-attribute instance-attribute

terminated_at = mapped_column(DateTime, nullable=True)

Termination is done at the initiative of the business layer. Accounts in terminal state cannot be modified or used anymore.

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

AccountStatusLog

Bases: BaseModel

__repr__

__repr__()
Source code in components/payment_gateway/subcomponents/accounts/models/account.py
def __repr__(self) -> str:
    return f"<AccountStatusLog [{self.id}]: {self.status}>"

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'account_status_log'

account class-attribute instance-attribute

account = relationship(
    Account,
    foreign_keys=account_id,
    back_populates="status_history",
)

account_id class-attribute instance-attribute

account_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    nullable=False,
    index=True,
)

status class-attribute instance-attribute

status = mapped_column(
    AlanBaseEnumTypeDecorator(AccountStatus), nullable=False
)

components.payment_gateway.subcomponents.accounts.models.account_holder

AccountHolder

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "provider",
        "external_id",
        name="account_holder__unique_external_id_per_provider",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'account_holder'

accounts class-attribute instance-attribute

accounts = relationship(
    ACCOUNT_MODEL,
    back_populates="account_holder",
    order_by=ACCOUNT_MODEL + ".created_at.desc()",
    uselist=True,
)

description class-attribute instance-attribute

description = mapped_column(Text, nullable=False)

external_id class-attribute instance-attribute

external_id = mapped_column(
    String(255), nullable=False, index=True
)

ID used by the external payment service provider to identify the account holder.

is_terminated property

is_terminated

provider class-attribute instance-attribute

provider = mapped_column(
    AlanBaseEnumTypeDecorator(PaymentServiceProvider),
    nullable=False,
)

The payment service provider the account holder id declared to.

reference class-attribute instance-attribute

reference = mapped_column(Text, nullable=True)

sepa_mandates class-attribute instance-attribute

sepa_mandates = relationship(
    "SepaMandate",
    back_populates="account_holder",
    order_by="SepaMandate.created_at.desc()",
    uselist=True,
    viewonly=True,
)

terminated_at class-attribute instance-attribute

terminated_at = mapped_column(DateTime, nullable=True)

Termination is done at the initiative of the business layer. Account holders in terminal state cannot be modified or used anymore.

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

components.payment_gateway.subcomponents.accounts.models.helpers

ACCOUNT_MODEL module-attribute

ACCOUNT_MODEL = __package__ + '.account.Account'

load_all_models

load_all_models()
Source code in components/payment_gateway/subcomponents/accounts/models/helpers.py
def load_all_models() -> list[type[DbModel]]:
    from components.payment_gateway.subcomponents.accounts.models.account import (
        Account,
        AccountStatusLog,
    )
    from components.payment_gateway.subcomponents.accounts.models.account_holder import (
        AccountHolder,
    )
    from components.payment_gateway.subcomponents.accounts.models.sepa_beneficiary import (
        SepaBeneficiary,
        SepaBeneficiaryStatusLog,
    )

    return [
        AccountHolder,
        Account,
        AccountStatusLog,
        SepaBeneficiary,
        SepaBeneficiaryStatusLog,
    ]

components.payment_gateway.subcomponents.accounts.models.sepa_beneficiary

SepaBeneficiary

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "provider",
        "external_id",
        name="sepa_beneficiary__unique_external_id_per_provider",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'sepa_beneficiary'

account class-attribute instance-attribute

account = relationship(
    Account,
    foreign_keys=[account_id],
    back_populates="sepa_beneficiaries",
)

account_id class-attribute instance-attribute

account_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    index=True,
    nullable=True,
)

bank_transfers class-attribute instance-attribute

bank_transfers = relationship(
    "BankTransfer",
    back_populates="sepa_beneficiary",
    order_by="BankTransfer.created_at.desc()",
    uselist=True,
    viewonly=True,
)

current_status_log class-attribute instance-attribute

current_status_log = relationship(
    "SepaBeneficiaryStatusLog",
    uselist=False,
    viewonly=True,
    primaryjoin="and_(   SepaBeneficiaryStatusLog.sepa_beneficiary_id == SepaBeneficiary.id,   SepaBeneficiaryStatusLog.created_at == (       select(func.max(SepaBeneficiaryStatusLog.created_at))       .where(SepaBeneficiaryStatusLog.sepa_beneficiary_id == SepaBeneficiary.id)       .correlate(SepaBeneficiary)       .scalar_subquery()   ))",
)

external_id class-attribute instance-attribute

external_id = mapped_column(
    String(255), nullable=False, index=True
)

ID used by the external payment service provider to identify the SEPA beneficiary.

iban class-attribute instance-attribute

iban = mapped_column_with_privacy(
    String(34),
    nullable=False,
    privacy_properties=PrivacyProperties(
        other,
        NoneOrPrefixRedactedHashed(keep_prefix_length=9),
        NoneOrPrefixRedactedHashed(keep_prefix_length=9),
        CustomSQL(IBAN_CUSTOM_SQL),
        PassThrough(),
    ),
)

The IBAN of the SEPA beneficiary.

issued_at class-attribute instance-attribute

issued_at = mapped_column(DateTime, nullable=False)

name class-attribute instance-attribute

name = mapped_column(String(255), nullable=False)

The name of the SEPA beneficiary.

provider class-attribute instance-attribute

provider = mapped_column(
    AlanBaseEnumTypeDecorator(PaymentServiceProvider),
    nullable=False,
)

The payment service provider the SEPA beneficiary is issued for.

status property

status

status_history class-attribute instance-attribute

status_history = relationship(
    "SepaBeneficiaryStatusLog",
    back_populates="sepa_beneficiary",
    order_by="SepaBeneficiaryStatusLog.created_at.desc()",
    uselist=True,
    viewonly=True,
)

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

SepaBeneficiaryStatusLog

Bases: BaseModel

__repr__

__repr__()
Source code in components/payment_gateway/subcomponents/accounts/models/sepa_beneficiary.py
def __repr__(self) -> str:
    return f"<SepaBeneficiaryStatusLog [{self.id}]: {self.status}>"

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'sepa_beneficiary_status_log'

sepa_beneficiary class-attribute instance-attribute

sepa_beneficiary = relationship(
    SepaBeneficiary,
    foreign_keys=sepa_beneficiary_id,
    back_populates="status_history",
)

sepa_beneficiary_id class-attribute instance-attribute

sepa_beneficiary_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    nullable=False,
    index=True,
)

status class-attribute instance-attribute

status = mapped_column(
    AlanBaseEnumTypeDecorator(SepaBeneficiaryStatus),
    nullable=False,
)