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/organization.ex
defmodule Mercury.OrganizationInfo do
@moduledoc "The Mercury organisation (business entity) associated with the API token."
@type t :: %__MODULE__{
id: String.t(),
legal_business_name: String.t(),
ein: String.t() | nil,
dbas: [String.t()]
}
defstruct [:id, :legal_business_name, :ein, :dbas]
@doc false
def from_json(map) when is_map(map) do
%__MODULE__{
id: map["id"],
legal_business_name: map["legalBusinessName"],
ein: map["ein"],
dbas: map["dbas"] || []
}
end
end
defmodule Mercury.Organization do
@moduledoc "The Mercury Organization API — the org tied to the API token, and partner onboarding."
alias Mercury.{Client, HTTP, OrganizationInfo, Support}
@doc "Returns the organisation associated with the API token. `GET /organisation`"
@spec get(client :: Client.t()) :: {:ok, OrganizationInfo.t()} | {:error, Exception.t()}
def get(%Client{} = client) do
with {:ok, body} <- HTTP.get(client, "organisation") do
{:ok, OrganizationInfo.from_json(body)}
end
end
@spec get!(client :: Client.t()) :: OrganizationInfo.t()
def get!(client), do: Support.bang!(get(client))
@doc """
Submits pre-fill data for a new Mercury applicant (partner integration
flows). `data` may be any JSON-serializable map. `POST /onboarding`
"""
@spec submit_onboarding(client :: Client.t(), data :: map()) :: :ok | {:error, Exception.t()}
def submit_onboarding(%Client{} = client, data) when is_map(data) do
case HTTP.post(client, "onboarding", data) do
{:ok, _body} -> :ok
{:error, _error} = error -> error
end
end
@spec submit_onboarding!(client :: Client.t(), data :: map()) :: :ok
def submit_onboarding!(client, data), do: Support.bang!(submit_onboarding(client, data))
end