Packages
mercury_client
1.0.0
A complete, production-grade Elixir client for the Mercury Banking API (accounts, transactions, recipients, invoices, payments, treasury, webhooks, and more), with typed errors, retry with backoff, and lazy auto-paginating streams.
Current section
Files
Jump to
Current section
Files
lib/mercury/transaction.ex
defmodule Mercury.Transaction do
@moduledoc """
A Mercury transaction (a payment, deposit, fee, or transfer).
Compound nested fields that don't have their own resource module are
grouped under `extra` (keeping their original camelCase API keys) rather
than as individual top-level struct fields — Elixir structs with 32 or
more fields change their internal BEAM representation, so keeping the
struct under that threshold avoids the extra memory overhead. `extra`
holds: `"glAllocations"`, `"attachments"`, `"relatedTransactions"`,
`"categoryData"`, `"merchant"`, `"currencyExchangeInfo"`, `"details"` —
consult the [Mercury API reference](https://docs.mercury.com/reference)
for their shape.
"""
@type t :: %__MODULE__{
id: String.t(),
account_id: String.t(),
amount: float(),
status: String.t(),
kind: String.t(),
created_at: DateTime.t() | nil,
estimated_delivery_date: DateTime.t() | nil,
counterparty_id: String.t() | nil,
counterparty_name: String.t() | nil,
counterparty_nickname: String.t() | nil,
dashboard_link: String.t(),
compliant_with_receipt_policy: boolean(),
has_generated_receipt: boolean(),
note: String.t() | nil,
external_memo: String.t() | nil,
bank_description: String.t() | nil,
check_number: String.t() | nil,
tracking_number: String.t() | nil,
request_id: String.t() | nil,
fee_id: String.t() | nil,
posted_at: DateTime.t() | nil,
failed_at: DateTime.t() | nil,
reason_for_failure: String.t() | nil,
mercury_category: String.t() | nil,
credit_account_period_id: String.t() | nil,
extra: map()
}
defstruct [
:id,
:account_id,
:amount,
:status,
:kind,
:created_at,
:estimated_delivery_date,
:counterparty_id,
:counterparty_name,
:counterparty_nickname,
:dashboard_link,
:compliant_with_receipt_policy,
:has_generated_receipt,
:note,
:external_memo,
:bank_description,
:check_number,
:tracking_number,
:request_id,
:fee_id,
:posted_at,
:failed_at,
:reason_for_failure,
:mercury_category,
:credit_account_period_id,
:extra
]
@doc false
@spec from_json(map :: map()) :: t()
def from_json(map) when is_map(map) do
%__MODULE__{
id: map["id"],
account_id: map["accountId"],
amount: map["amount"],
status: map["status"],
kind: map["kind"],
created_at: Mercury.Types.datetime(map["createdAt"]),
estimated_delivery_date: Mercury.Types.datetime(map["estimatedDeliveryDate"]),
counterparty_id: map["counterpartyId"],
counterparty_name: map["counterpartyName"],
counterparty_nickname: map["counterpartyNickname"],
dashboard_link: map["dashboardLink"],
compliant_with_receipt_policy: map["compliantWithReceiptPolicy"],
has_generated_receipt: map["hasGeneratedReceipt"],
note: map["note"],
external_memo: map["externalMemo"],
bank_description: map["bankDescription"],
check_number: map["checkNumber"],
tracking_number: map["trackingNumber"],
request_id: map["requestId"],
fee_id: map["feeId"],
posted_at: Mercury.Types.datetime(map["postedAt"]),
failed_at: Mercury.Types.datetime(map["failedAt"]),
reason_for_failure: map["reasonForFailure"],
mercury_category: map["mercuryCategory"],
credit_account_period_id: map["creditAccountPeriodId"],
extra: %{
"glAllocations" => map["glAllocations"] || [],
"attachments" => map["attachments"] || [],
"relatedTransactions" => map["relatedTransactions"] || [],
"categoryData" => map["categoryData"],
"merchant" => map["merchant"],
"currencyExchangeInfo" => map["currencyExchangeInfo"],
"details" => map["details"]
}
}
end
end