Skip to content

Models

components.payment_gateway.subcomponents.banking_documents.models.helpers

load_all_models

load_all_models()
Source code in components/payment_gateway/subcomponents/banking_documents/models/helpers.py
def load_all_models() -> list[type[DbModel]]:
    from components.payment_gateway.subcomponents.banking_documents.models.pad_payment_mandate import (
        PadPaymentMandate,
    )
    from components.payment_gateway.subcomponents.banking_documents.models.payment_mandate import (
        PaymentMandate,
    )
    from components.payment_gateway.subcomponents.banking_documents.models.payment_mandate_provider_mapping import (
        PaymentMandateProviderMapping,
    )
    from components.payment_gateway.subcomponents.banking_documents.models.payment_mandate_status_log import (
        PaymentMandateStatusLog,
    )
    from components.payment_gateway.subcomponents.banking_documents.models.sepa_mandate import (
        SepaMandate,
        SepaMandateStatusLog,
    )
    from components.payment_gateway.subcomponents.banking_documents.models.sepa_payment_mandate import (
        SepaPaymentMandate,
    )

    return [
        SepaMandate,
        SepaMandateStatusLog,
        PaymentMandate,
        SepaPaymentMandate,
        PadPaymentMandate,
        PaymentMandateStatusLog,
        PaymentMandateProviderMapping,
    ]

components.payment_gateway.subcomponents.banking_documents.models.pad_payment_mandate

PadPaymentMandate

Bases: PaymentMandate

Pre-Authorized Debit (Canada) payment mandate.

__mapper_args__ class-attribute instance-attribute

__mapper_args__ = {'polymorphic_identity': PAD}

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'pad_payment_mandate'

__versioned__ class-attribute instance-attribute

__versioned__ = {'exclude': []}

id class-attribute instance-attribute

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

components.payment_gateway.subcomponents.banking_documents.models.payment_mandate

PaymentMandate

Bases: BaseModel

A formal, revocable authorization given by a Grantor to a Grantee, allowing the Grantee to initiate Payments from a specified Financial Instrument belonging to the Grantor (acting as a Debtor), for a defined purpose and payment method, subject to agreed limitations and backed by a Proof of Consent.

See

__mapper_args__ class-attribute instance-attribute

__mapper_args__ = {
    "polymorphic_abstract": True,
    "polymorphic_on": "mandate_type",
}

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'payment_mandate'

consent_captured_at class-attribute instance-attribute

consent_captured_at = mapped_column(DateTime, nullable=True)

Timestamp of signature or explicit consent.

creditor_legal_entity = relationship(
    LegalEntity, foreign_keys=[creditor_legal_entity_id]
)
creditor_legal_entity_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    nullable=False,
    index=True,
)

The legal entity authorized to collect.

current_status_log class-attribute instance-attribute

current_status_log = relationship(
    "PaymentMandateStatusLog",
    uselist=False,
    viewonly=True,
    primaryjoin="and_(   PaymentMandateStatusLog.payment_mandate_id == PaymentMandate.id,   PaymentMandateStatusLog.created_at == (       select(func.max(PaymentMandateStatusLog.created_at))       .where(PaymentMandateStatusLog.payment_mandate_id == PaymentMandate.id)       .correlate(PaymentMandate)       .scalar_subquery()   ))",
)

Most recent status log for this mandate.

debtor_financial_instrument class-attribute instance-attribute

debtor_financial_instrument = relationship(
    FinancialInstrument,
    foreign_keys=[debtor_financial_instrument_id],
)

debtor_financial_instrument_id class-attribute instance-attribute

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

The financial instrument to debit from.

mandate_type class-attribute instance-attribute

mandate_type = mapped_column(
    AlanBaseEnumTypeDecorator(PaymentMandateType),
    nullable=False,
)

Discriminator: sepa | pad.

payment_type class-attribute instance-attribute

payment_type = mapped_column(
    AlanBaseEnumTypeDecorator(PaymentMandatePaymentType),
    nullable=False,
)

Whether the mandate authorizes recurring or one-off payments.

status property

status

Current status from the most recent status log.

status_history class-attribute instance-attribute

status_history = relationship(
    "PaymentMandateStatusLog",
    back_populates="payment_mandate",
    order_by="PaymentMandateStatusLog.created_at.desc()",
    uselist=True,
    viewonly=True,
)

All status logs for this mandate, most recent first.

unique_key class-attribute instance-attribute

unique_key = mapped_column(
    String(255), nullable=False, unique=True, index=True
)

Namespaced unique identifier {country}:{model}:{id} for deduplication and idempotency.

components.payment_gateway.subcomponents.banking_documents.models.payment_mandate_provider_mapping

PaymentMandateProviderMapping

Bases: ProviderEntityMixin, BaseModel

Maps a PaymentMandate to its identifier on a given PSP workspace.

__table_args__

__table_args__()
Source code in components/payment_gateway/subcomponents/banking_documents/models/payment_mandate_provider_mapping.py
@declared_attr.directive
def __table_args__(cls) -> tuple[Any, ...]:
    return (
        # Override the mixin's constraint with a shorter name to fit PostgreSQL's 63-char limit
        UniqueConstraint(
            "workspace_key",
            "external_id",
            name="payment_mandate_provider_map__uq_external_id_workspace",
        ),
        # We don't want the same mapped entity to exist several times on the same workspace
        UniqueConstraint(
            "workspace_key",
            "payment_mandate_id",
            name="payment_mandate_provider_map__uq_local_id_workspace",
        ),
        {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
    )

__tablename__ class-attribute instance-attribute

__tablename__ = 'payment_mandate_provider_mapping'

payment_mandate class-attribute instance-attribute

payment_mandate = relationship(
    PaymentMandate, foreign_keys=[payment_mandate_id]
)

payment_mandate_id class-attribute instance-attribute

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

components.payment_gateway.subcomponents.banking_documents.models.payment_mandate_status_log

PaymentMandateStatusLog

Bases: BaseModel

Status history entry for a PaymentMandate.

__repr__

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

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'payment_mandate_status_log'

payment_mandate class-attribute instance-attribute

payment_mandate = relationship(
    PaymentMandate,
    foreign_keys=[payment_mandate_id],
    back_populates="status_history",
)

payment_mandate_id class-attribute instance-attribute

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

reason class-attribute instance-attribute

reason = mapped_column(String(), nullable=True)

Optional free-text comment on what happened.

status class-attribute instance-attribute

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

components.payment_gateway.subcomponents.banking_documents.models.sepa_mandate

SepaMandate

Bases: ProviderEntityMixin, BaseModel

__table_args__

__table_args__()
Source code in components/payment_gateway/subcomponents/banking_documents/models/sepa_mandate.py
@declared_attr.directive
def __table_args__(cls) -> tuple[Any, ...]:
    return cls._provider_entity_mixin_table_args() + (
        {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
    )

__tablename__ class-attribute instance-attribute

__tablename__ = 'sepa_mandate'

account_holder class-attribute instance-attribute

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

account_holder_id class-attribute instance-attribute

account_holder_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_mandate",
    order_by="BankTransfer.created_at.desc()",
    uselist=True,
    viewonly=True,
)

current_status_log class-attribute instance-attribute

current_status_log = relationship(
    "SepaMandateStatusLog",
    uselist=False,
    viewonly=True,
    primaryjoin="and_(   SepaMandateStatusLog.sepa_mandate_id == SepaMandate.id,   SepaMandateStatusLog.created_at == (       select(func.max(SepaMandateStatusLog.created_at))       .where(SepaMandateStatusLog.sepa_mandate_id == SepaMandate.id)       .correlate(SepaMandate)       .scalar_subquery()   ))",
)

debtor_country class-attribute instance-attribute

debtor_country = mapped_column(String(3), nullable=False)

The country of residence of the debtor as specified in the mandate.

debtor_iban class-attribute instance-attribute

debtor_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 the mandate is issued for.

debtor_name class-attribute instance-attribute

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

The name of the debtor as specified in the mandate.

issued_at class-attribute instance-attribute

issued_at = mapped_column(DateTime, nullable=False)

sepa_creditor_identifier class-attribute instance-attribute

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

SCI (ICS in French - Identifiant Créancier SEPA).

status property

status

status_history class-attribute instance-attribute

status_history = relationship(
    "SepaMandateStatusLog",
    back_populates="sepa_mandate",
    order_by="SepaMandateStatusLog.created_at.desc()",
    uselist=True,
    viewonly=True,
)

unique_mandate_reference class-attribute instance-attribute

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

Unique mandate reference (known as RUM in French - Référence Unique de Mandat)

SepaMandateStatusLog

Bases: BaseModel

__repr__

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

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'sepa_mandate_status_log'

sepa_mandate class-attribute instance-attribute

sepa_mandate = relationship(
    SepaMandate,
    foreign_keys=sepa_mandate_id,
    back_populates="status_history",
)

sepa_mandate_id class-attribute instance-attribute

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

status class-attribute instance-attribute

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

components.payment_gateway.subcomponents.banking_documents.models.sepa_payment_mandate

SepaPaymentMandate

Bases: PaymentMandate

SEPA payment mandate is a type of payment mandate identified by its UMR.

__mapper_args__ class-attribute instance-attribute

__mapper_args__ = {'polymorphic_identity': SEPA}

__table_args__ class-attribute instance-attribute

__table_args__ = (
    Index("ix_sepa_payment_mandate_umr_creditor", "umr"),
    {"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)

__tablename__ class-attribute instance-attribute

__tablename__ = 'sepa_payment_mandate'

__versioned__ class-attribute instance-attribute

__versioned__ = {'exclude': []}

id class-attribute instance-attribute

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

scheme class-attribute instance-attribute

scheme = mapped_column(
    AlanBaseEnumTypeDecorator(SepaPaymentMandateScheme),
    nullable=False,
)

SEPA scheme: core | b2b.

umr class-attribute instance-attribute

umr = mapped_column(String(35), nullable=False)

Unique Mandate Reference. Max 35 chars, Latin only. Unique per (Creditor Identifier + UMR) combination.

valid_until class-attribute instance-attribute

valid_until = mapped_column(DateTime, nullable=False)

Mandate is valid for 36 months since creation or last collection.