Skip to content

components.payment_gateway.public.rules

This module defines the public API for the rules 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

ExpenseLimitRuleNotFoundException

Bases: PaymentRulesException

Exception raised when trying to use a non-existing Expense Limit Rule.

ExpenseLimitRuleTerminatedException

Bases: PaymentRulesException

Exception raised when trying to use a terminated Expense Limit Rule.

ExpenseLimitsLogic

ExpenseLimitsLogic(
    expense_limit_rule_queries, expense_limit_rule_actions
)

This class is the public interface to the expense limit 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/rules/protected/business_logic/expense_limits.py
def __init__(
    self,
    expense_limit_rule_queries: ExpenseLimitRuleQueries,
    expense_limit_rule_actions: ExpenseLimitRuleActions,
) -> None:
    self.expense_limit_rule_queries = expense_limit_rule_queries
    self.expense_limit_rule_actions = expense_limit_rule_actions

Attributes

expense_limit_rule_actions instance-attribute
expense_limit_rule_actions = expense_limit_rule_actions
expense_limit_rule_queries instance-attribute
expense_limit_rule_queries = expense_limit_rule_queries

Functions

activate_expense_limit_rule
activate_expense_limit_rule(session, /, id)

Activate an expense limit rule.

Activating a rule will also set the start date to the current date.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def activate_expense_limit_rule(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
) -> None:
    """
    Activate an expense limit rule.

    Activating a rule will also set the start date to the current date.
    """
    self.expense_limit_rule_actions.set_expense_limit_rule_status(
        session,
        id,
        True,
    )
create classmethod
create()

Normal factory

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@classmethod
def create(cls) -> "ExpenseLimitsLogic":
    """Normal factory"""
    return cls(
        ExpenseLimitRuleQueries(),
        ExpenseLimitRuleActions.create(),
    )
create_expense_limit_rule
create_expense_limit_rule(
    session,
    /,
    description,
    reference,
    card_id,
    amount,
    currency,
    period,
    criteria,
    first_day=None,
    is_active=False,
    start=None,
    end=None,
)

Create an expense limit rule for a card.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def create_expense_limit_rule(
    self,
    session: Session,
    /,
    description: str,
    reference: str,
    card_id: CardId,
    amount: int,
    currency: CurrencyCode,
    period: ExpenseLimitPeriod,
    criteria: list[RuleCriterion],
    first_day: int | None = None,
    is_active: bool = False,
    start: datetime | None = None,
    end: datetime | None = None,
) -> ExpenseLimitRuleId:
    """
    Create an expense limit rule for a card.
    """
    return self.expense_limit_rule_actions.create_expense_limit_rule(
        session,
        card_id=card_id,
        description=description,
        reference=reference,
        amount=amount,
        currency=currency,
        period=period,
        criteria=criteria,
        first_day=first_day,
        is_active=is_active,
        start=start,
        end=end,
    )
create_null classmethod
create_null(track_adyen_requests=None)

Null factory

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@classmethod
def create_null(
    cls,
    track_adyen_requests: list[tuple[str, dict, dict]] | None = None,  # type: ignore[type-arg]
) -> "ExpenseLimitsLogic":
    """Null factory"""
    return cls(
        ExpenseLimitRuleQueries(),
        ExpenseLimitRuleActions.create_null(
            track_adyen_requests=track_adyen_requests
        ),
    )
deactivate_expense_limit_rule
deactivate_expense_limit_rule(session, /, id)

Deactivate an expense limit rule.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def deactivate_expense_limit_rule(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
) -> None:
    """
    Deactivate an expense limit rule.
    """
    self.expense_limit_rule_actions.set_expense_limit_rule_status(
        session,
        id,
        False,
    )
get_expense_limit_rule
get_expense_limit_rule(session, /, id)

Get an expense limit from its ID.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def get_expense_limit_rule(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
) -> ExpenseLimitRule:
    """
    Get an expense limit from its ID.
    """
    return self.expense_limit_rule_queries.get_expense_limit_rule(
        session,
        id,
    )
get_expense_limit_rule_ids_for_card
get_expense_limit_rule_ids_for_card(session, /, card_id)

Get all the expense limit rule IDs for a card.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def get_expense_limit_rule_ids_for_card(
    self,
    session: Session,
    /,
    card_id: CardId,
) -> list[ExpenseLimitRuleId]:
    """
    Get all the expense limit rule IDs for a card.
    """
    return self.expense_limit_rule_queries.get_expense_limit_rule_ids_for_card(
        session,
        card_id,
    )
get_expense_limit_rules_for_card
get_expense_limit_rules_for_card(session, /, card_id)

Get all the expense limit rules for a card.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def get_expense_limit_rules_for_card(
    self,
    session: Session,
    /,
    card_id: CardId,
) -> list[ExpenseLimitRule]:
    """
    Get all the expense limit rules for a card.
    """
    return self.expense_limit_rule_queries.get_expense_limit_rules_for_card(
        session,
        card_id,
    )
set_expense_limit_rule_validity_period
set_expense_limit_rule_validity_period(
    session, /, id, start=None, end=None
)

Define the period when an expense limit rule is valid.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def set_expense_limit_rule_validity_period(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
    start: datetime | None = None,
    end: datetime | None = None,
) -> None:
    """
    Define the period when an expense limit rule is valid.
    """
    self.expense_limit_rule_actions.set_expense_limit_rule_validity_period(
        session,
        id,
        start,
        end,
    )
terminate_expense_limit_rule
terminate_expense_limit_rule(session, /, id)

Terminate an expense limit rule.

Usage restrictions in terminal state cannot be modified or used anymore.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def terminate_expense_limit_rule(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
) -> None:
    """
    Terminate an expense limit rule.

    Usage restrictions in terminal state cannot be modified or used anymore.
    """
    self.expense_limit_rule_actions.terminate_expense_limit_rule(
        session,
        id,
    )
update_expense_limit_rule_amount
update_expense_limit_rule_amount(session, /, id, amount)

Update the amount of an expense limit rule.

This operation can be safely performed in the middle of a validity period. The new limit will be applied to all future transactions.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def update_expense_limit_rule_amount(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
    amount: int,
) -> None:
    """
    Update the amount of an expense limit rule.

    This operation can be safely performed in the middle of a validity
    period. The new limit will be applied to all future transactions.
    """
    self.expense_limit_rule_actions.update_expense_limit_rule_amount(
        session,
        id,
        amount,
    )
update_expense_limit_rule_criteria
update_expense_limit_rule_criteria(
    session, /, id, criteria
)

Update the criteria of an expense limit rule.

Warning: we don't know yet how this will behave when performed in the middle of a validity period with respect to the cumulated amount so far. Use with caution.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/expense_limits.py
@obs.api_call()
def update_expense_limit_rule_criteria(
    self,
    session: Session,
    /,
    id: ExpenseLimitRuleId,
    criteria: list[RuleCriterion],
) -> None:
    """
    Update the criteria of an expense limit rule.

    Warning: we don't know yet how this will behave when performed in the
    middle of a validity period with respect to the cumulated amount so far.
    Use with caution.
    """
    self.expense_limit_rule_actions.update_expense_limit_rule_criteria(
        session,
        id,
        criteria,
    )

InvalidValidityPeriodException

Bases: PaymentRulesException, ValueError

Exception raised when creating or updating a Rule with invalid start/end dates.

PaymentRulesException

Bases: PaymentGatewayException

Base class for all Rules exceptions.

UsageRestrictionRuleNotFoundException

Bases: PaymentRulesException

Exception raised when trying to use a non-existing Usage Restriction Rule.

UsageRestrictionRuleTerminatedException

Bases: PaymentRulesException

Exception raised when trying to use a terminated Usage Restriction Rule.

UsageRestrictionsLogic

UsageRestrictionsLogic(
    usage_restriction_rule_queries,
    usage_restriction_rule_actions,
)

This class is the public interface to the usage restriction 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/rules/protected/business_logic/usage_restrictions.py
def __init__(
    self,
    usage_restriction_rule_queries: UsageRestrictionRuleQueries,
    usage_restriction_rule_actions: UsageRestrictionRuleActions,
) -> None:
    self.usage_restriction_rule_queries = usage_restriction_rule_queries
    self.usage_restriction_rule_actions = usage_restriction_rule_actions

Attributes

usage_restriction_rule_actions instance-attribute
usage_restriction_rule_actions = (
    usage_restriction_rule_actions
)
usage_restriction_rule_queries instance-attribute
usage_restriction_rule_queries = (
    usage_restriction_rule_queries
)

Functions

activate_usage_restriction_rule
activate_usage_restriction_rule(session, /, id)

Activate a usage restriction rule.

Activating a rule will also set the start date to the current date.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def activate_usage_restriction_rule(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
) -> None:
    """
    Activate a usage restriction rule.

    Activating a rule will also set the start date to the current date.
    """
    return self.usage_restriction_rule_actions.set_usage_restriction_rule_status(
        session,
        id,
        True,
    )
create classmethod
create()

Normal factory

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@classmethod
def create(cls) -> "UsageRestrictionsLogic":
    """Normal factory"""
    return cls(
        UsageRestrictionRuleQueries(),
        UsageRestrictionRuleActions.create(),
    )
create_null classmethod
create_null(track_adyen_requests=None)

Null factory

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@classmethod
def create_null(
    cls,
    track_adyen_requests: list[tuple[str, dict, dict]] | None = None,  # type: ignore[type-arg]
) -> "UsageRestrictionsLogic":
    """Null factory"""
    return cls(
        UsageRestrictionRuleQueries(),
        UsageRestrictionRuleActions.create_null(
            track_adyen_requests=track_adyen_requests
        ),
    )
create_usage_restriction_rule
create_usage_restriction_rule(
    session,
    /,
    description,
    reference,
    account_id,
    criteria,
    is_active=False,
    start=None,
    end=None,
)

Create a usage restriction rule for an account.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def create_usage_restriction_rule(
    self,
    session: Session,
    /,
    description: str,
    reference: str,
    account_id: AccountId,
    criteria: list[RuleCriterion],
    is_active: bool = False,
    start: datetime | None = None,
    end: datetime | None = None,
) -> UsageRestrictionRuleId:
    """
    Create a usage restriction rule for an account.
    """
    return self.usage_restriction_rule_actions.create_usage_restriction_rule(
        session,
        description=description,
        reference=reference,
        account_id=account_id,
        criteria=criteria,
        is_active=is_active,
        start=start,
        end=end,
    )
deactivate_usage_restriction_rule
deactivate_usage_restriction_rule(session, /, id)

Deactivate a usage restriction rule.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def deactivate_usage_restriction_rule(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
) -> None:
    """
    Deactivate a usage restriction rule.
    """
    return self.usage_restriction_rule_actions.set_usage_restriction_rule_status(
        session,
        id,
        False,
    )
get_usage_restriction_rule
get_usage_restriction_rule(session, /, id)

Get a usage restriction rule from its ID.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def get_usage_restriction_rule(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
) -> UsageRestrictionRule:
    """
    Get a usage restriction rule from its ID.
    """
    return self.usage_restriction_rule_queries.get_usage_restriction_rule(
        session,
        id,
    )
get_usage_restriction_rule_ids_for_account
get_usage_restriction_rule_ids_for_account(
    session, /, account_id
)

Get all the usage restriction rule IDs for an account.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def get_usage_restriction_rule_ids_for_account(
    self,
    session: Session,
    /,
    account_id: AccountId,
) -> list[UsageRestrictionRuleId]:
    """
    Get all the usage restriction rule IDs for an account.
    """
    return self.usage_restriction_rule_queries.get_usage_restriction_rule_ids_for_account(
        session,
        account_id,
    )
get_usage_restriction_rules_for_account
get_usage_restriction_rules_for_account(
    session, /, account_id
)

Get all the usage restriction rules for an account.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def get_usage_restriction_rules_for_account(
    self,
    session: Session,
    /,
    account_id: AccountId,
) -> list[UsageRestrictionRule]:
    """
    Get all the usage restriction rules for an account.
    """
    return (
        self.usage_restriction_rule_queries.get_usage_restriction_rules_for_account(
            session,
            account_id,
        )
    )
set_usage_restriction_rule_validity_period
set_usage_restriction_rule_validity_period(
    session, /, id, start=None, end=None
)

Define the period when a usage restriction rule is valid.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def set_usage_restriction_rule_validity_period(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
    start: datetime | None = None,
    end: datetime | None = None,
) -> None:
    """
    Define the period when a usage restriction rule is valid.
    """
    return self.usage_restriction_rule_actions.set_usage_restriction_rule_validity_period(
        session,
        id,
        start,
        end,
    )
terminate_usage_restriction_rule
terminate_usage_restriction_rule(session, /, id)

Terminate a usage restriction rule.

Usage restrictions in terminal state cannot be modified or used anymore.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def terminate_usage_restriction_rule(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
) -> None:
    """
    Terminate a usage restriction rule.

    Usage restrictions in terminal state cannot be modified or used anymore.
    """
    self.usage_restriction_rule_actions.terminate_usage_restriction_rule(
        session,
        id,
    )
update_usage_restriction_rule_criteria
update_usage_restriction_rule_criteria(
    session, /, id, criteria
)

Update the criteria of a usage restriction rule.

Source code in components/payment_gateway/subcomponents/rules/protected/business_logic/usage_restrictions.py
@obs.api_call()
def update_usage_restriction_rule_criteria(
    self,
    session: Session,
    /,
    id: UsageRestrictionRuleId,
    criteria: list[RuleCriterion],
) -> None:
    """
    Update the criteria of a usage restriction rule.
    """
    return (
        self.usage_restriction_rule_actions.update_usage_restriction_rule_criteria(
            session,
            id,
            criteria,
        )
    )