Skip to content

Resolvers

ExpenseCategoryResolver

Bases: ABC

This abstract class defines the interface responsible for resolving the expense categories for a pending transaction.

Warning

Implementations of this class should be stateless and fail-safe, as they are used for critical idempotent operations in a real-time context.

resolve_expense_categories abstractmethod

resolve_expense_categories(pending_transaction)

Resolve the expense category codes for a pending transaction.

Parameters:

Name Type Description Default
pending_transaction PendingTransaction

The pending transaction to resolve the expense categories for.

required

Returns:

Type Description
set[str] | None

The matching expense category codes, or None if no expense category could be resolved.

Source code in components/payment_gateway/subcomponents/authorizations/protected/resolvers.py
@abstractmethod
def resolve_expense_categories(
    self, pending_transaction: PendingTransaction
) -> set[str] | None:
    """
    Resolve the expense category codes for a pending transaction.

    Args:
        pending_transaction: The pending transaction to resolve the expense
            categories for.

    Returns:
        The matching expense category codes, or None if no expense category
            could be resolved.
    """
    raise NotImplementedError

LineOfCreditResolver

Bases: ABC

This abstract class defines the interface responsible for resolving the lines of credit for a pending transaction.

Warning

Implementations of this class should be stateless and fail-safe, as they are used for critical idempotent operations in a real-time context.

resolve_lines_of_credit abstractmethod

resolve_lines_of_credit(
    expense_category_ids, pending_transaction
)

Resolve the line of credit IDs for a pending transaction and expense categories.

Parameters:

Name Type Description Default
expense_category_ids set[ExpenseCategoryId]

The expense categories for the pending transaction.

required
pending_transaction PendingTransaction

The pending transaction to resolve the lines of credit for.

required

Returns:

Type Description
set[LineOfCreditId] | None

The matching lines of credit IDs, or None if at least one could not be resolved.

Invariant

There is a one-to-one relationship between input expense categories and output lines of credit.

Note

We don't need to return the entities themselves, because the authorization process only depends on their ID.

Source code in components/payment_gateway/subcomponents/authorizations/protected/resolvers.py
@abstractmethod
def resolve_lines_of_credit(
    self,
    expense_category_ids: set[ExpenseCategoryId],
    pending_transaction: PendingTransaction,
) -> set[LineOfCreditId] | None:
    """
    Resolve the line of credit IDs for a pending transaction and expense categories.

    Args:
        expense_category_ids: The expense categories for the pending transaction.
        pending_transaction: The pending transaction to resolve the lines of
            credit for.

    Returns:
        The matching lines of credit IDs, or None if at least one could not
            be resolved.

    Invariant:
        There is a one-to-one relationship between input expense categories
        and output lines of credit.

    Note:
        We don't need to return the entities themselves, because the
        authorization process only depends on their ID.
    """
    raise NotImplementedError