Packages

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
mercury_client lib mercury safe_requests.ex
Raw

lib/mercury/safe_requests.ex

defmodule Mercury.SafeRequest do
@moduledoc "A Simple Agreement for Future Equity (SAFE) request."
@type t :: %__MODULE__{
id: String.t(),
status: String.t(),
amount: float(),
currency: String.t(),
created_at: DateTime.t() | nil,
investor_name: String.t() | nil,
document_url: String.t() | nil
}
defstruct [:id, :status, :amount, :currency, :created_at, :investor_name, :document_url]
@doc false
def from_json(map) when is_map(map) do
%__MODULE__{
id: map["id"],
status: map["status"],
amount: map["amount"],
currency: map["currency"],
created_at: Mercury.Types.datetime(map["createdAt"]),
investor_name: map["investorName"],
document_url: map["documentUrl"]
}
end
end
defmodule Mercury.SafeRequests do
@moduledoc "The Mercury SAFEs API — Simple Agreements for Future Equity."
alias Mercury.{Client, HTTP, SafeRequest, Support}
@doc "Returns a single SAFE request by ID. `GET /safe-requests/{id}`"
@spec get(client :: Client.t(), safe_id :: String.t()) ::
{:ok, SafeRequest.t()} | {:error, Exception.t()}
def get(%Client{} = client, safe_id) do
with {:ok, body} <- HTTP.get(client, "safe-requests/#{safe_id}") do
{:ok, SafeRequest.from_json(body)}
end
end
@spec get!(client :: Client.t(), safe_id :: String.t()) :: SafeRequest.t()
def get!(client, safe_id), do: Support.bang!(get(client, safe_id))
@doc "Returns every SAFE request for the organisation (not paginated). `GET /safe-requests`"
@spec list(client :: Client.t()) :: {:ok, [SafeRequest.t()]} | {:error, Exception.t()}
def list(%Client{} = client) do
with {:ok, body} <- HTTP.get(client, "safe-requests") do
{:ok, Mercury.Types.list_of(body, &SafeRequest.from_json/1)}
end
end
@spec list!(client :: Client.t()) :: [SafeRequest.t()]
def list!(client), do: Support.bang!(list(client))
@doc "Downloads the SAFE agreement PDF, returning the raw bytes. `GET /safe-requests/{id}/document`"
@spec download_document(client :: Client.t(), safe_id :: String.t()) ::
{:ok, binary()} | {:error, Exception.t()}
def download_document(%Client{} = client, safe_id) do
HTTP.download_binary(client, "safe-requests/#{safe_id}/document")
end
@spec download_document!(client :: Client.t(), safe_id :: String.t()) :: binary()
def download_document!(client, safe_id), do: Support.bang!(download_document(client, safe_id))
end