components.payment_gateway.public.ledgers ¶
This module defines the public API for the ledgers 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¶
LedgerEntryNotFoundException ¶
Bases: PaymentLedgerException
Exception raised when trying to use a non-existing Ledger Entry.
LedgerLogic ¶
This class is the public interface to the ledger logic.
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
Attributes¶
Functions¶
create_ledger ¶
Create a ledger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
description
|
str
|
The description of the ledger. |
required |
reference
|
str | None
|
An optional reference to the ledger. |
None
|
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
get_entries_by_reference_prefix ¶
Get all the ledger entries for a reference prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
ledger_id
|
LedgerId
|
The ID of the ledger. |
required |
reference_prefix
|
str
|
The reference prefix of the ledger entries. |
required |
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
get_entry ¶
Get a ledger entry entity from its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LedgerEntryId
|
The ID of the ledger entry. |
required |
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
get_ledger ¶
Get a ledger entity from its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LedgerId
|
The ID of the ledger. |
required |
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
get_ledger_balance ¶
Get current balance of a ledger.
This is the ending balance of the entry that is effective at the given date, or the last entry if no date is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LedgerId
|
The ID of the ledger. |
required |
effective_at
|
datetime | None
|
The point in time to get the ledger balance for. |
None
|
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
get_ledger_ids_by_reference ¶
Get all the ledger IDs for a reference.
Returns 0-n ledger IDs because nothing prevents a reference from being shared between multiple ledgers (this is a business concern and there's no unicity constraint).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
reference
|
str
|
The reference of the ledger(s). |
required |
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
record_entry ¶
record_entry(
session,
/,
id,
amount,
occurred_at,
description=None,
reference=None,
metadata=None,
external_transaction_id=None,
)
Record a new entry in a ledger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LedgerId
|
The ID of the ledger. |
required |
amount
|
int
|
The amount of the entry. |
required |
occurred_at
|
datetime
|
The time the event occurred (not the time we process it). |
required |
description
|
str | None
|
An optional description of the entry. |
None
|
reference
|
str | None
|
An optional reference to the entry. |
None
|
metadata
|
dict | None
|
An optional metadata dictionary. |
None
|
external_transaction_id
|
str | None
|
An optional external transaction ID. Useful for recording transactions from external systems. |
None
|
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
record_entry_overwriting_created_at ¶
record_entry_overwriting_created_at(
session,
/,
id,
amount,
occurred_at,
created_at,
description=None,
reference=None,
metadata=None,
external_transaction_id=None,
)
Record a new entry in a ledger overwriting the created_at. ⚠️ WARNING: This method should be used carefully, as it can break the linear history of a ledger if not used carefully Args: session: The session to use for the database operations. id: The ID of the ledger. amount: The amount of the entry. occurred_at: The time the event occurred (not the time we process it). description: An optional description of the entry. reference: An optional reference to the entry. metadata: An optional metadata dictionary. external_transaction_id: An optional external transaction ID. Useful for recording transactions from external systems. created_at: The time the entry was created.
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
terminate_ledger ¶
Terminate a ledger.
The operation is idempotent, i.e. it has no effect on already terminated entities.
Ledgers in terminal state cannot be modified or used anymore. Any
attempt to use or retrieve a terminated ledger will raise a
LedgerTerminatedException.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
id
|
LedgerId
|
The ID of the ledger to terminate. |
required |
Source code in components/payment_gateway/subcomponents/ledgers/protected/business_logic/ledgers.py
LedgerNotFoundException ¶
Bases: PaymentLedgerException
Exception raised when trying to use a non-existing Ledger.
LedgerTerminatedException ¶
Bases: PaymentLedgerException
Exception raised when trying to use a terminated Ledger.
PaymentLedgerException ¶
Bases: PaymentGatewayException
Base class for all Ledger exceptions.