components.payment_gateway.public.transfers ¶
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.
Classes¶
AccountTransferActions ¶
Actions for initiating account-to-account transfers on PSP platforms.
These are internal transfers between balance accounts managed by the same PSP, not banking operations. Adyen processes them immediately.
Source code in components/payment_gateway/subcomponents/transfers/protected/business_logic/actions/account_transfer_actions.py
Functions¶
create
classmethod
¶
Normal factory.
create_null
classmethod
¶
Null factory.
Source code in components/payment_gateway/subcomponents/transfers/protected/business_logic/actions/account_transfer_actions.py
initiate_account_transfer ¶
initiate_account_transfer(
session,
/,
*,
source_account_id,
destination_account_id,
amount,
currency,
reference,
description=None,
)
Initiate an internal transfer between two PSP balance accounts.
The transfer is immediate on Adyen. The returned external ID can be used to correlate with AccountTransfer records created by webhooks.
Idempotency: the Adyen Idempotency-Key is f"{reference}-{YYYY-MM-DD:HH}"
in UTC. Adyen caches idempotency responses for at least 7 days, so
reusing reference verbatim after a failed transfer (e.g. insufficient
funds → Adyen records a failed transfer + caches the response) would
return the cached failure for up to a week. Hour bucketing keeps
same-hour retries (UI double-click, Celery retry, network blip) deduped
while letting operators retry by waiting for the next hour boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
SQLAlchemy session for DB operations. |
required |
source_account_id
|
AccountId
|
Account to transfer funds from. |
required |
destination_account_id
|
AccountId
|
Account to transfer funds to. |
required |
amount
|
int
|
Amount in minor currency units. Must be positive. |
required |
currency
|
str
|
ISO 4217 currency code. |
required |
reference
|
str
|
Unique reference for tracking and reconciliation. |
required |
description
|
str | None
|
Optional human-readable description. |
None
|
Returns:
| Type | Description |
|---|---|
AccountTransferInitiationResult
|
The initiation result with external ID and success status. |
Source code in components/payment_gateway/subcomponents/transfers/protected/business_logic/actions/account_transfer_actions.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
AccountTransferInitiationResult
dataclass
¶
AccountTransferRouter ¶
Bases: ABC
Router for the account transfer processor to route the account transfers (a.k.a. Adyen's "internalTransfer") to the appropriate entities
Note: the source or the destination account must be a known account to the Payment Gateway
Functions¶
route
abstractmethod
¶
Route an account transfer to the appropriate entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
TransferDirection
|
The transfer direction |
required |
reference
|
str
|
The transfer reference; this is mostly used for tracking and reconciliation |
required |
account_id
|
AccountId
|
The ID of the account involved in the transfer |
required |
effective_date
|
datetime
|
The effective date at which the transfer occurred |
required |
Returns:
| Type | Description |
|---|---|
AccountTransferRoutingResult
|
The entities with which the transfer should be associated. |
Source code in components/payment_gateway/subcomponents/transfers/protected/routers.py
AccountTransferRoutingException ¶
Bases: PaymentTransferException
Exception raised for errors in the account transfer routing process.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Explanation of the error |
Source code in components/payment_gateway/subcomponents/transfers/protected/exceptions.py
AccountTransferRoutingResult
dataclass
¶
BankTransferRouter ¶
Bases: ABC
Router for the bank transfer processor to route the bank transfers (a.k.a. Adyen's "bankTransfer") to the appropriate entities
Functions¶
route
abstractmethod
¶
Route a bank transfer to the appropriate entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
TransferDirection
|
The transfer direction |
required |
account_id
|
AccountId
|
The ID of the account involved in the transfer |
required |
effective_date
|
datetime
|
The effective date at which the transfer occurred |
required |
Returns:
| Type | Description |
|---|---|
BankTransferRoutingResult
|
The entities with which the transfer should be associated. |
Source code in components/payment_gateway/subcomponents/transfers/protected/routers.py
BankTransferRoutingException ¶
Bases: PaymentTransferException
Exception raised for errors in the bank transfer routing process.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Explanation of the error |
Source code in components/payment_gateway/subcomponents/transfers/protected/exceptions.py
BankTransferRoutingResult
dataclass
¶
Result of the bank transfer routing.
Attributes¶
ledger_id
class-attribute
instance-attribute
¶
Ledger ID the transfer should affect.
Can be None if the transfer does not affect a Ledger, or if the Transfer
History is not associated with a Ledger.
transfer_history_id
instance-attribute
¶
Transfer History ID the transfer should belong to.
CardTransferRouter ¶
Bases: ABC
Router for the card transfer processor to route the card transfers (a.k.a. Adyen's "payment") to the appropriate entities
Functions¶
route
abstractmethod
¶
Route a card transfer to the appropriate entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_id
|
CardId
|
The ID of the card involved in the transfer |
required |
merchant_info
|
MerchantInfo
|
Info about the merchant involved in the transfer |
required |
effective_date
|
datetime
|
The effective date at which the transfer occurred |
required |
transfer_status
|
str
|
The status of the transfer |
required |
transfer_external_id
|
str
|
The external ID of the transfer |
required |
Returns:
| Type | Description |
|---|---|
CardTransferRoutingResult
|
The entities with which the transfer should be associated. |
Source code in components/payment_gateway/subcomponents/transfers/protected/routers.py
CardTransferRoutingException ¶
Bases: PaymentTransferException
Exception raised for errors in the card transfer routing process.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Explanation of the error |
Source code in components/payment_gateway/subcomponents/transfers/protected/exceptions.py
CardTransferRoutingResult
dataclass
¶
CardTransferRoutingResult(
transfer_history_id,
ledger_id=None,
expense_category_ids=None,
line_of_credit_ids=None,
)
Result of the card transfer routing.
Attributes¶
expense_category_ids
class-attribute
instance-attribute
¶
Expense Category IDs the transfer should match.
Can be None if the transfer does not belong to any Expense Category, which
can happen for declined or refused transfer.
ledger_id
class-attribute
instance-attribute
¶
Ledger ID the transfer should affect.
Can be None if the transfer does not affect a Ledger, or if the Transfer
History is not associated with a Ledger.
line_of_credit_ids
class-attribute
instance-attribute
¶
Line of Credit IDs the transfer should affect.
Can be None if the transfer does not match any Line of Credit, which can
happen for unknown cards or unsupported Expense Categories.
transfer_history_id
instance-attribute
¶
Transfer History ID the transfer should belong to.
TransferLogic ¶
Functions¶
create_internal_transfer ¶
create_internal_transfer(
session,
/,
*,
source,
destination,
amount,
effective_date,
description,
reference,
)
Create a double-entry internal transfer.
This will create a pair of internal transfers with opposite amounts, one negative for the source and one postitive for the destination.
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
create_internal_transfer_entry ¶
create_internal_transfer_entry(
session,
/,
*,
transfer_history_id,
amount,
effective_date,
description,
reference,
)
Create a single-entry internal transfer.
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
create_transfer_history ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_account_transfer_balance_within_period ¶
get_account_transfer_balance_within_period(
session,
/,
transfer_history_id,
*,
period_start_date,
period_end_date,
)
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_account_transfers_by_references ¶
List account transfers matching any of the given references.
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_all_transfers ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_balance ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_bank_transfer_balance_within_period ¶
get_bank_transfer_balance_within_period(
session,
/,
transfer_history_id,
*,
period_start_date,
period_end_date,
)
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_card_transfers_by_card_ids ¶
Retrieves a list of CardTransfer objects associated with a specific card ID, optionally filtering for those without a transfer history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to use for the database operations. |
required |
card_ids
|
Iterable[CardId]
|
The ID of the card for which to retrieve associated CardTransfer objects. |
required |
without_transfer_history_only
|
bool
|
If True, the method will return only those CardTransfer objects that have no associated transfer history. Defaults to False. |
False
|
- list[CardTransfer]: A list of CardTransfer objects matching the provided criteria. This list may be empty if no matching objects are found.
Note: - The returned CardTransfer objects are ordered by their effective date in descending order, meaning the most recent payments are returned first.
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_internal_transfer_balance_within_period ¶
get_internal_transfer_balance_within_period(
session,
/,
transfer_history_id,
*,
period_start_date,
period_end_date,
)
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_internal_transfers_by_references ¶
List internal transfers matching any of the given references.
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_transfer_by_ref ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_transfer_histories ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_transfer_history_id_by_private_ref ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_transfers_by_effective_date ¶
get_transfers_by_effective_date(
session,
/,
transfer_history_ids,
*,
start_effective_date,
end_effective_date=None,
)
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
get_transfers_by_event_date ¶
get_transfers_by_event_date(
session,
/,
transfer_history_ids,
*,
start_effective_date,
end_effective_date,
transfer_types=None,
)
Use when dealing with card transfers and
you are not only interested in the date at which the card transfer was originated, but want to fetch the individual events associated to it. A Card payment can be theoretically opened for 30 days on mastercard (on Adyen is even more, we have cases of years, a bug on their side). During this period, each event can performa a balance change, therefore the date at which you made a balance change can be different of that of when the card transfer was originated. In Spain, for healthy benefits we have a real time approach for card transfers, therefore the flag filter_by_event_dates allows to retrieve events that happened during a given period, not just card transfers for which we only have the date at which it was started. NON card transfers are more simple and don't need to be treated differently for real time cases vs non-real time.
This method returns each type of transfer ordered by created_at, then it orders by effective_at
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
upsert_transfer_history ¶
Source code in components/payment_gateway/subcomponents/transfers/protected/api.py
Functions¶
calculate_amount_from_events ¶
Calculate the amount from a list of transfer events We include the received balance if including_received is True.