components.payment_gateway.public.authorizations ¶
This module defines the public API for the transfers 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.
Attributes¶
Classes¶
DuplicateExpenseCategoryException ¶
Bases: PaymentAuthorizationsException
Exception raised when trying to create a duplicate Expense Category.
DuplicateLineOfCreditException ¶
Bases: PaymentAuthorizationsException
Exception raised when trying to create a duplicate Line of Credit.
ExpenseCategory
dataclass
¶
An Expense Category is a high level concept to categorize expenses (or payments), as its name implies. A given payment can match several categories, for example food expenses, grocery stores, payments made abroad, payments made on Sunday, etc.
Expense Limits are typically in limited number for a given application. They are not linked to a specific card, account, or payment method.
Each payment must belong to at least one Expense Category to be authorized.
Attributes¶
ExpenseCategoryLogic ¶
This class is the public interface to the Expense Category logic.
Functions¶
create_expense_category ¶
Create an expense category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
code
|
str
|
The code of the expense category (must be unique). |
required |
name
|
str
|
The name of the expense category. |
required |
description
|
str | None
|
The description of the expense category. |
None
|
reference
|
str | None
|
The reference of the expense category. |
None
|
Returns:
| Type | Description |
|---|---|
ExpenseCategoryId
|
ID of the created expense category. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/expense_categories.py
get_expense_category_id_by_code ¶
Get expense category ID by its code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
code
|
str
|
Expense category code. |
required |
Returns:
| Type | Description |
|---|---|
ExpenseCategoryId
|
Expense category ID. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/expense_categories.py
get_expense_category_ids_by_codes ¶
Get expense category IDs by codes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
codes
|
set[str]
|
Set of expense category codes. |
required |
Returns:
| Type | Description |
|---|---|
set[ExpenseCategoryId]
|
Set of expense category IDs. |
Warning
The length of the output set may be less than the length of the input set if some entries do not exist in the database.
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/expense_categories.py
ExpenseCategoryNotFoundException ¶
Bases: PaymentAuthorizationsException
Exception raised when trying to use a non-existing Expense Category.
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.
Functions¶
resolve_expense_categories
abstractmethod
¶
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
LineOfCredit
dataclass
¶
LineOfCredit(
id,
expense_category_id,
owner_type,
owner_ref,
credits_limit,
expensed_credits,
available_credits,
)
A Line of Credit is a high level concept to manage expenses made by a given owner. Each Line of Credit belongs to an Expense Category.
For each Expense Category a payment belongs to, there must be a matching Line of Credit with sufficient credits to cover the payment.
Attributes¶
available_credits
instance-attribute
¶
Available credits for the Line of Credit (in minor units).
credits_limit
instance-attribute
¶
Credits limit for the Line of Credit (in minor units).
expense_category_id
instance-attribute
¶
Category of expenses covered by the line of credit
expensed_credits
instance-attribute
¶
Expensed credits for the Line of Credit (in minor units).
owner_ref
instance-attribute
¶
Application-specific reference to the owner of the line of credit.
owner_type
instance-attribute
¶
Application-specific type of owner for the line of credit.
LineOfCreditLogic ¶
This class is the public interface to the Line of Credit logic.
Functions¶
create_line_of_credit ¶
create_line_of_credit(
session,
/,
owner_type,
owner_ref,
expense_category_id,
credits_limit=0,
expensed_credits=0,
)
Create a Line of Credit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
owner_type
|
str
|
Application-specific type of owner for the Line of Credit. |
required |
owner_ref
|
UUID
|
Application-specific reference to the owner of the Line of Credit. |
required |
expense_category_id
|
ExpenseCategoryId
|
ID of the Expense Category the Line of Credit belongs to. |
required |
credits_limit
|
int
|
The limit of credits for the Line of Credit (in minor units). |
0
|
expensed_credits
|
int
|
The amount of credits already expensed (in minor units). |
0
|
Returns:
| Type | Description |
|---|---|
LineOfCreditId
|
ID of the created Line of Credit. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
get_line_of_credit ¶
Get a Line of Credit by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LineOfCreditId
|
ID of the Line of Credit. |
required |
Returns:
| Type | Description |
|---|---|
LineOfCredit
|
Line of Credit entity. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
get_line_of_credit_id_for_owner_and_expense_category_id ¶
get_line_of_credit_id_for_owner_and_expense_category_id(
session, /, owner_type, owner_ref, expense_category_id
)
Get Line of Credit ID for a specific owner and Expense Category ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
owner_type
|
str
|
Application-specific type of owner for the Line of Credit. |
required |
owner_ref
|
UUID
|
Application-specific reference to the owner of the Line of Credit. |
required |
expense_category_id
|
ExpenseCategoryId
|
Expense Category IDs to resolve. |
required |
Returns:
| Type | Description |
|---|---|
LineOfCreditId | None
|
Line of Credit ID or None if none found. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
get_line_of_credit_ids_for_owner_and_expense_category_ids ¶
get_line_of_credit_ids_for_owner_and_expense_category_ids(
session, /, owner_type, owner_ref, expense_category_ids
)
Get Line of Credit IDs for a given owner and Expense Category IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
owner_type
|
str
|
Application-specific type of owner for the Line of Credit. |
required |
owner_ref
|
UUID
|
Application-specific reference to the owner of the Line of Credit. |
required |
expense_category_ids
|
set[ExpenseCategoryId]
|
Set of Expense Category IDs. |
required |
Returns:
| Type | Description |
|---|---|
set[LineOfCreditId]
|
Set of Line of Credit IDs. |
Warning
The length of the output set may be less than the length of the input set if some entries do not exist in the database.
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
get_lines_of_credit_for_owner ¶
Get all Line of Credit IDs for a specific owner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
owner_type
|
str
|
Application-specific type of owner for the Line of Credit. |
required |
owner_ref
|
UUID
|
Application-specific reference to the owner of the Line of Credit. |
required |
Returns:
| Type | Description |
|---|---|
list[LineOfCredit]
|
Set of Line of Credit IDs. |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
reset_credits ¶
Reset the credits limit and expensed credits of a Line of Credit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
line_of_credit_id
|
LineOfCreditId
|
ID of the Line of Credit. |
required |
credits_limit
|
int
|
New credits limit (in minor units). |
required |
expensed_credits
|
int
|
New expensed credits (in minor units). |
required |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
set_credits_limit ¶
Set the credits limit of a Line of Credit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
line_of_credit_id
|
LineOfCreditId
|
ID of the Line of Credit. |
required |
credits_limit
|
int
|
New credits limit (in minor units). |
required |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
terminate_line_of_credit ¶
Terminate a Line of Credit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
line_of_credit_id
|
LineOfCreditId
|
ID of the Line of Credit. |
required |
Source code in components/payment_gateway/subcomponents/authorizations/protected/business_logic/lines_of_credit.py
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.
Functions¶
resolve_lines_of_credit
abstractmethod
¶
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
PaymentAuthorizationsException ¶
Bases: PaymentGatewayException
Base class for all authorizations exceptions.
PendingTransaction
dataclass
¶
PendingTransactionMerchantInfo
dataclass
¶
PendingTransactionMerchantInfo(
merchant_id,
acquirer_id,
mcc,
name,
country,
postal_code=None,
city=None,
)
Merchant information for a pending transaction.
Note
All fields are always present during authorization, those which are None might simply be irrelevant for the merchant (e.g. e-commerce platforms may not have a postal code)