Mercury.Accounts (mercury_client v1.0.0)

Copy Markdown View Source

The Mercury Accounts API — bank accounts, cards, statements, and sending money from an account.

Summary

Functions

Downloads a statement PDF, returning the raw bytes. GET /statements/{id}/pdf

Returns a single account by ID. GET /account/{id}

Same as get/2 but raises on error.

Returns one page of accounts. GET /accounts

Same as list/2 but raises on error.

Returns every card issued on an account. GET /account/{id}/cards

Returns one page of statements for an account. GET /account/{id}/statements

Returns one page of transactions for an account. GET /account/{id}/transactions

Sends money from an account to a recipient. attrs accepts snake_case keys, e.g.

A lazy, auto-paginating stream of every account.

A lazy, auto-paginating stream of every statement for an account.

A lazy, auto-paginating stream of every transaction for an account.

Functions

download_statement(client, statement_id)

@spec download_statement(client :: Mercury.Client.t(), statement_id :: String.t()) ::
  {:ok, binary()} | {:error, Exception.t()}

Downloads a statement PDF, returning the raw bytes. GET /statements/{id}/pdf

download_statement!(client, statement_id)

@spec download_statement!(client :: Mercury.Client.t(), statement_id :: String.t()) ::
  binary()

get(client, account_id)

@spec get(client :: Mercury.Client.t(), account_id :: String.t()) ::
  {:ok, Mercury.Account.t()} | {:error, Exception.t()}

Returns a single account by ID. GET /account/{id}

get!(client, account_id)

@spec get!(client :: Mercury.Client.t(), account_id :: String.t()) ::
  Mercury.Account.t()

Same as get/2 but raises on error.

list(client, opts \\ [])

@spec list(client :: Mercury.Client.t(), opts :: keyword()) ::
  {:ok, Mercury.Page.t(Mercury.Account.t())} | {:error, Exception.t()}

Returns one page of accounts. GET /accounts

Accepts the common list options: :limit, :order (:asc | :desc), :start_after, :end_before.

list!(client, opts \\ [])

@spec list!(client :: Mercury.Client.t(), opts :: keyword()) ::
  Mercury.Page.t(Mercury.Account.t())

Same as list/2 but raises on error.

list_cards(client, account_id)

@spec list_cards(client :: Mercury.Client.t(), account_id :: String.t()) ::
  {:ok, [Mercury.Card.t()]} | {:error, Exception.t()}

Returns every card issued on an account. GET /account/{id}/cards

list_cards!(client, account_id)

@spec list_cards!(client :: Mercury.Client.t(), account_id :: String.t()) :: [
  Mercury.Card.t()
]

list_statements(client, account_id, opts \\ [])

@spec list_statements(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, Mercury.Page.t(Mercury.AccountStatement.t())} | {:error, Exception.t()}

Returns one page of statements for an account. GET /account/{id}/statements

list_statements!(client, account_id, opts \\ [])

@spec list_statements!(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  Mercury.Page.t(Mercury.AccountStatement.t())

list_transactions(client, account_id, opts \\ [])

@spec list_transactions(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, Mercury.Page.t(Mercury.Transaction.t())} | {:error, Exception.t()}

Returns one page of transactions for an account. GET /account/{id}/transactions

list_transactions!(client, account_id, opts \\ [])

@spec list_transactions!(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  Mercury.Page.t(Mercury.Transaction.t())

send_money(client, account_id, attrs)

@spec send_money(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  attrs :: map() | keyword()
) ::
  {:ok, Mercury.Transaction.t()} | {:error, Exception.t()}

Sends money from an account to a recipient. attrs accepts snake_case keys, e.g.:

Mercury.Accounts.send_money(client, account_id, %{
  recipient_id: recipient_id,
  amount: 100.00,
  payment_method: :ach,
  idempotency_key: idempotency_key
})

POST /account/{id}/transactions

send_money!(client, account_id, attrs)

@spec send_money!(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  attrs :: map() | keyword()
) ::
  Mercury.Transaction.t()

stream(client, opts \\ [])

@spec stream(client :: Mercury.Client.t(), opts :: keyword()) :: Enumerable.t()

A lazy, auto-paginating stream of every account.

stream_statements(client, account_id, opts \\ [])

@spec stream_statements(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  Enumerable.t()

A lazy, auto-paginating stream of every statement for an account.

stream_transactions(client, account_id, opts \\ [])

@spec stream_transactions(
  client :: Mercury.Client.t(),
  account_id :: String.t(),
  opts :: keyword()
) ::
  Enumerable.t()

A lazy, auto-paginating stream of every transaction for an account.