Skip to content

Models

components.payment_gateway.subcomponents.transfers.models.account_transfer

AccountTransfer

Bases: BaseModel

__table_args__ class-attribute instance-attribute

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

__tablename__ class-attribute instance-attribute

__tablename__ = 'account_transfer'

account class-attribute instance-attribute

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

account_id class-attribute instance-attribute

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

direction class-attribute instance-attribute

direction = mapped_column(
    AlanBaseEnumTypeDecorator(TransferDirection),
    nullable=False,
)

effective_date class-attribute instance-attribute

effective_date = mapped_column(DateTime, nullable=False)

events class-attribute instance-attribute

events = relationship(
    "TransferEvent",
    secondary=f"{PAYMENT_GATEWAY_SCHEMA_NAME}.{__tablename__}",
    order_by=sequence,
    uselist=True,
    viewonly=True,
)

external_id class-attribute instance-attribute

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

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

provider class-attribute instance-attribute

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

The payment service provider the bank transfer happened with.

raw class-attribute instance-attribute

raw = mapped_column(JSONB(none_as_null=True), nullable=True)

reference class-attribute instance-attribute

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

transfer_history class-attribute instance-attribute

transfer_history = relationship(
    TransferHistory,
    foreign_keys=[transfer_history_id],
    back_populates="account_transfers",
)

transfer_history_id class-attribute instance-attribute

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

updates class-attribute instance-attribute

updates = relationship(
    "TransferUpdate",
    primaryjoin="AccountTransfer.id == foreign(TransferUpdate.transfer_id)",
    order_by="TransferUpdate.sequence_number",
    uselist=True,
    viewonly=True,
)

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

AccountTransferTransferEventAssociation

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "account_transfer_id",
        "sequence",
        name="account_transfer_transfer_event_sequence_unique_constraint",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = (
    "account_transfer_transfer_event_association"
)

account_transfer class-attribute instance-attribute

account_transfer = relationship('AccountTransfer')

account_transfer_id class-attribute instance-attribute

account_transfer_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.account_transfer.id"
    ),
    index=True,
    nullable=False,
)

sequence class-attribute instance-attribute

sequence = mapped_column(Integer, nullable=False)

transfer_event class-attribute instance-attribute

transfer_event = relationship('TransferEvent')

transfer_event_id class-attribute instance-attribute

transfer_event_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.transfer_event.id"
    ),
    index=True,
    unique=True,
    nullable=False,
)

components.payment_gateway.subcomponents.transfers.models.bank_transfer

BankTransfer

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "provider",
        "external_id",
        name="bank_transfer__unique_external_id_per_provider",
    ),
    CheckConstraint(
        "sepa_mandate_id IS NULL OR sepa_beneficiary_id IS NULL",
        name="bank_transfer__no_sepa_mandate_and_sepa_beneficiary",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'bank_transfer'

account class-attribute instance-attribute

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

account_id class-attribute instance-attribute

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

direction class-attribute instance-attribute

direction = mapped_column(
    AlanBaseEnumTypeDecorator(TransferDirection),
    nullable=False,
)

effective_date class-attribute instance-attribute

effective_date = mapped_column(DateTime, nullable=False)

events class-attribute instance-attribute

events = relationship(
    "TransferEvent",
    secondary=f"{PAYMENT_GATEWAY_SCHEMA_NAME}.{__tablename__}",
    order_by=sequence,
    uselist=True,
    viewonly=True,
)

external_id class-attribute instance-attribute

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

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

provider class-attribute instance-attribute

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

The payment service provider the bank transfer happened with.

raw class-attribute instance-attribute

raw = mapped_column(JSONB(none_as_null=True), nullable=True)

sepa_beneficiary class-attribute instance-attribute

sepa_beneficiary = relationship(
    SepaBeneficiary,
    foreign_keys=[sepa_beneficiary_id],
    back_populates="bank_transfers",
)

sepa_beneficiary_id class-attribute instance-attribute

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

sepa_mandate class-attribute instance-attribute

sepa_mandate = relationship(
    SepaMandate,
    foreign_keys=[sepa_mandate_id],
    back_populates="bank_transfers",
)

sepa_mandate_id class-attribute instance-attribute

sepa_mandate_id = mapped_column(
    UUID(as_uuid=True), ForeignKey(id), index=True
)

transfer_history class-attribute instance-attribute

transfer_history = relationship(
    TransferHistory,
    foreign_keys=[transfer_history_id],
    back_populates="bank_transfers",
)

transfer_history_id class-attribute instance-attribute

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

updates class-attribute instance-attribute

updates = relationship(
    "TransferUpdate",
    primaryjoin="BankTransfer.id == foreign(TransferUpdate.transfer_id)",
    order_by="TransferUpdate.sequence_number",
    uselist=True,
    viewonly=True,
)

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

BankTransferTransferEventAssociation

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "bank_transfer_id",
        "sequence",
        name="bank_transfer_transfer_event_sequence_unique_constraint",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'bank_transfer_transfer_event_association'

bank_transfer class-attribute instance-attribute

bank_transfer = relationship('BankTransfer')

bank_transfer_id class-attribute instance-attribute

bank_transfer_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.bank_transfer.id"
    ),
    index=True,
    nullable=False,
)

sequence class-attribute instance-attribute

sequence = mapped_column(Integer, nullable=False)

transfer_event class-attribute instance-attribute

transfer_event = relationship('TransferEvent')

transfer_event_id class-attribute instance-attribute

transfer_event_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.transfer_event.id"
    ),
    index=True,
    unique=True,
    nullable=False,
)

components.payment_gateway.subcomponents.transfers.models.card_transfer

CardTransfer

Bases: BaseModel

__table_args__ class-attribute instance-attribute

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

__tablename__ class-attribute instance-attribute

__tablename__ = 'card_payment'

account class-attribute instance-attribute

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

account_id class-attribute instance-attribute

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

card class-attribute instance-attribute

card = relationship(
    Card, foreign_keys=[card_id], back_populates="payments"
)

card_id class-attribute instance-attribute

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

city class-attribute instance-attribute

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

Merchant city name

country class-attribute instance-attribute

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

Merchant english country name

effective_date class-attribute instance-attribute

effective_date = mapped_column(DateTime, nullable=False)

Date and time when the card payment happened (not when it was ingested in our system).

events class-attribute instance-attribute

events = relationship(
    "TransferEvent",
    secondary=f"{PAYMENT_GATEWAY_SCHEMA_NAME}.{__tablename__}",
    order_by=sequence,
    uselist=True,
    viewonly=True,
)

external_id class-attribute instance-attribute

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

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

mcc class-attribute instance-attribute

mcc = mapped_column(String(10), nullable=False)

Merchant Category Code (MCC)

merchant_id class-attribute instance-attribute

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

Merchant ID

name class-attribute instance-attribute

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

Merchant name

postal_code class-attribute instance-attribute

postal_code = mapped_column(String(255), nullable=True)

Merchant postal code

provider class-attribute instance-attribute

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

The payment service provider the card payment happened with.

raw class-attribute instance-attribute

raw = mapped_column(JSONB(none_as_null=True), nullable=True)

transfer_history class-attribute instance-attribute

transfer_history = relationship(
    TransferHistory,
    foreign_keys=[transfer_history_id],
    back_populates="card_payments",
)

transfer_history_id class-attribute instance-attribute

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

updates class-attribute instance-attribute

updates = relationship(
    "TransferUpdate",
    primaryjoin="CardTransfer.id == foreign(TransferUpdate.transfer_id)",
    order_by="TransferUpdate.sequence_number",
    uselist=True,
    viewonly=True,
)

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

CardTransferTransferEventAssociation

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "card_payment_id",
        "sequence",
        name="card_payment_transfer_event_sequence_unique_constraint",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'card_payment_transfer_event_association'

card_payment class-attribute instance-attribute

card_payment = relationship('CardTransfer')

card_payment_id class-attribute instance-attribute

card_payment_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.card_payment.id"
    ),
    index=True,
    nullable=False,
)

sequence class-attribute instance-attribute

sequence = mapped_column(Integer, nullable=False)

transfer_event class-attribute instance-attribute

transfer_event = relationship('TransferEvent')

transfer_event_id class-attribute instance-attribute

transfer_event_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(
        f"{PAYMENT_GATEWAY_SCHEMA_NAME}.transfer_event.id"
    ),
    index=True,
    unique=True,
    nullable=False,
)

components.payment_gateway.subcomponents.transfers.models.helpers

load_all_models

load_all_models()
Source code in components/payment_gateway/subcomponents/transfers/models/helpers.py
def load_all_models() -> list[type[DbModel]]:
    from components.payment_gateway.subcomponents.transfers.models.account_transfer import (
        AccountTransfer,
        AccountTransferTransferEventAssociation,
    )
    from components.payment_gateway.subcomponents.transfers.models.bank_transfer import (
        BankTransfer,
        BankTransferTransferEventAssociation,
    )
    from components.payment_gateway.subcomponents.transfers.models.card_transfer import (
        CardTransfer,
        CardTransferTransferEventAssociation,
    )
    from components.payment_gateway.subcomponents.transfers.models.internal_transfer import (
        InternalTransfer,
    )
    from components.payment_gateway.subcomponents.transfers.models.transfer_event import (
        TransferEvent,
    )
    from components.payment_gateway.subcomponents.transfers.models.transfer_history import (
        TransferHistory,
    )
    from components.payment_gateway.subcomponents.transfers.models.transfer_update import (
        TransferUpdate,
    )

    return [
        TransferHistory,
        TransferUpdate,
        CardTransfer,
        BankTransfer,
        InternalTransfer,
        AccountTransfer,
        TransferEvent,
        BankTransferTransferEventAssociation,
        CardTransferTransferEventAssociation,
        AccountTransferTransferEventAssociation,
    ]

components.payment_gateway.subcomponents.transfers.models.internal_transfer

InternalTransfer

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'internal_transfer'

amount class-attribute instance-attribute

amount = mapped_column(Integer, nullable=False)

description class-attribute instance-attribute

description = mapped_column(Text, nullable=False)

effective_date class-attribute instance-attribute

effective_date = mapped_column(DateTime, nullable=False)

reference class-attribute instance-attribute

reference = mapped_column(String, nullable=False)

transfer_history class-attribute instance-attribute

transfer_history = relationship(
    TransferHistory,
    foreign_keys=[transfer_history_id],
    back_populates="internal_transfers",
)

transfer_history_id class-attribute instance-attribute

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

components.payment_gateway.subcomponents.transfers.models.transfer_event

TransferEvent

Bases: BaseModel

__table_args__ class-attribute instance-attribute

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

__tablename__ class-attribute instance-attribute

__tablename__ = 'transfer_event'

balance class-attribute instance-attribute

balance = mapped_column(Integer, nullable=False, default=0)

effective_date class-attribute instance-attribute

effective_date = mapped_column(
    DateTime, nullable=False, index=True
)

external_id class-attribute instance-attribute

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

ID used by the external payment service provider to identify the transfer event.

provider class-attribute instance-attribute

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

The payment service provider the transfer event happened with.

raw class-attribute instance-attribute

raw = mapped_column(JSONB(none_as_null=True), nullable=True)

received class-attribute instance-attribute

received = mapped_column(Integer, nullable=False, default=0)

reserved class-attribute instance-attribute

reserved = mapped_column(Integer, nullable=False, default=0)

status class-attribute instance-attribute

status = mapped_column(String, nullable=False)

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')

components.payment_gateway.subcomponents.transfers.models.transfer_history

TransferHistory

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "private_type",
        "private_ref",
        name="transfer_history_private_key_and_ref_unique_constraint",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'transfer_history'

account_transfers class-attribute instance-attribute

account_transfers = relationship(
    "AccountTransfer",
    back_populates="transfer_history",
    order_by="AccountTransfer.created_at.asc()",
    uselist=True,
)

bank_transfers class-attribute instance-attribute

bank_transfers = relationship(
    "BankTransfer",
    back_populates="transfer_history",
    order_by="BankTransfer.created_at.asc()",
    uselist=True,
)

card_payments class-attribute instance-attribute

card_payments = relationship(
    "CardTransfer",
    back_populates="transfer_history",
    order_by="CardTransfer.created_at.asc()",
    uselist=True,
)

internal_transfers class-attribute instance-attribute

internal_transfers = relationship(
    "InternalTransfer",
    back_populates="transfer_history",
    order_by="InternalTransfer.created_at.asc()",
    uselist=True,
)

private_ref class-attribute instance-attribute

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

private_type class-attribute instance-attribute

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

components.payment_gateway.subcomponents.transfers.models.transfer_update

TransferUpdate

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = (
    UniqueConstraint(
        "provider",
        "external_transfer_id",
        "sequence_number",
        name="transfer_update__unique_provider_specific_ids",
    ),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'transfer_update'

amount class-attribute instance-attribute

amount = mapped_column(Integer, nullable=False)

Amount of the transfer update (in minor units).

currency class-attribute instance-attribute

currency = mapped_column(String(length=3), nullable=False)

Currency of the transfer update, represented as a 3-letter ISO 4217 code.

direction class-attribute instance-attribute

direction = mapped_column(
    AlanBaseEnumTypeDecorator(TransferDirection),
    nullable=False,
)

Direction of the transfer. Same for all updates in the sequence but denormalized here for convenience.

external_transaction_id class-attribute instance-attribute

external_transaction_id = mapped_column(
    String(255), nullable=True, index=True
)

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

There can be several transactions within the same transfer update sequence, each having one or several updates.

external_transfer_id class-attribute instance-attribute

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

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

occurred_at class-attribute instance-attribute

occurred_at = mapped_column(
    DateTime, nullable=False, index=True
)

Date and time when the transfer update occurred.

provider class-attribute instance-attribute

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

The payment service provider the transfer happened with.

raw class-attribute instance-attribute

raw = mapped_column(JSONB(none_as_null=True), nullable=True)

sequence_number class-attribute instance-attribute

sequence_number = mapped_column(Integer, nullable=False)

Sequence number of the update within the transfer update sequence.

status class-attribute instance-attribute

status = mapped_column(String, nullable=False)

transfer_id class-attribute instance-attribute

transfer_id = mapped_column(
    UUID(as_uuid=True), nullable=False, index=True
)

ID of the transfer this update belongs to (any kind of transfer type, e.g. card/bank/account).

Note: we don't use a foreign key here because we have several transfer types having their own transfer model.

transfer_type class-attribute instance-attribute

transfer_type = mapped_column(
    AlanBaseEnumTypeDecorator(TransferUpdateTransferType),
    nullable=False,
)

Type of the transfer this update belongs to.

validate_provider class-attribute instance-attribute

validate_provider = create_validator('provider')