Models
components.payment_gateway.subcomponents.authorizations.models.authorization_request ¶
AuthorizationRequest ¶
Bases: BaseModel
This model is used to manage the lifecycle of an authorization request.
__table_args__
class-attribute
instance-attribute
¶
__table_args__ = (
UniqueConstraint(
"provider",
"external_id",
name="authorization_request__unique_external_id_per_provider",
),
{"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)
authorization_metadata
class-attribute
instance-attribute
¶
Metadata passed around between layers.
Note: 'metadata' is reserved so use 'entry_metadata' instead.
external_id
class-attribute
instance-attribute
¶
ID used by the external payment service provider to identify the transaction.
provider
class-attribute
instance-attribute
¶
The payment service provider that manages the transaction.
status
class-attribute
instance-attribute
¶
The status of the authorization request.
validate_provider
class-attribute
instance-attribute
¶
components.payment_gateway.subcomponents.authorizations.models.expense_category ¶
ExpenseCategory ¶
Bases: BaseModel
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.
__table_args__
class-attribute
instance-attribute
¶
code
class-attribute
instance-attribute
¶
Machine-readable code of the category, unique within the system.
description
class-attribute
instance-attribute
¶
Description of the category.
name
class-attribute
instance-attribute
¶
Human-readable name of the category.
reference
class-attribute
instance-attribute
¶
Application-specific reference to the category.
terminated_at
class-attribute
instance-attribute
¶
Termination is done at the initiative of the business layer. Expense categories in terminal state cannot be modified or used anymore.
components.payment_gateway.subcomponents.authorizations.models.expense_tracker ¶
ExpenseTracker ¶
Bases: BaseModel
Companion model to LineOfCredit.
We keep the credits limit and the expensed credits in a separate model to limit database contention during relayed authorization requests. See:
__table_args__
class-attribute
instance-attribute
¶
available_credits ¶
credits_limit
class-attribute
instance-attribute
¶
Credits limit for the Line of Credit (in minor units).
This represents the maximum amount of credits that can be expensed during the current period.
expensed_credits
class-attribute
instance-attribute
¶
Expensed credits for the Line of Credit (in minor units).
This represents the total amount of credits that have been expensed so far during the current period.
line_of_credit
class-attribute
instance-attribute
¶
line_of_credit_id
class-attribute
instance-attribute
¶
line_of_credit_id = mapped_column(
UUID(as_uuid=True),
ForeignKey(
f"{PAYMENT_GATEWAY_SCHEMA_NAME}.line_of_credit.id"
),
index=True,
unique=True,
nullable=False,
)
components.payment_gateway.subcomponents.authorizations.models.helpers ¶
load_all_models ¶
Source code in components/payment_gateway/subcomponents/authorizations/models/helpers.py
components.payment_gateway.subcomponents.authorizations.models.line_of_credit ¶
LineOfCredit ¶
Bases: BaseModel
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. Credits are tracked in a companion model ExpenseTracker for performance reasons.
__table_args__
class-attribute
instance-attribute
¶
__table_args__ = (
Index(
"line_of_credit__unique_owner_per_expense_category",
"expense_category_id",
"owner_type",
"owner_ref",
unique=True,
postgresql_where=text("terminated_at IS NULL"),
),
{"schema": PAYMENT_GATEWAY_SCHEMA_NAME},
)
expense_category
class-attribute
instance-attribute
¶
expense_category = relationship(
ExpenseCategory,
foreign_keys=expense_category_id,
uselist=False,
)
expense_category_id
class-attribute
instance-attribute
¶
expense_category_id = mapped_column(
UUID(as_uuid=True),
ForeignKey(id),
index=True,
nullable=False,
)
expense_tracker
class-attribute
instance-attribute
¶
owner_ref
class-attribute
instance-attribute
¶
Application-specific reference to the owner of the line of credit.
owner_type
class-attribute
instance-attribute
¶
Application-specific type of owner for the line of credit.
terminated_at
class-attribute
instance-attribute
¶
Termination is done at the initiative of the business layer. Lines of Credit in terminal state cannot be modified or used anymore.