Unit — Production-grade Elixir client for the Unit embedded banking API.
Overview
Full Unit API coverage across all 24 resource domains:
| Domain | Module |
|---|---|
| Applications (KYC/KYB) | Unit.API.Applications |
| Customers | Unit.API.Customers |
| Accounts | Unit.API.Accounts |
| Cards | Unit.API.Cards |
| Authorizations | Unit.API.Authorizations |
| Payments | Unit.API.Payments |
| Recurring Payments | Unit.API.RecurringPayments |
| Transactions | Unit.API.Transactions |
| Counterparties | Unit.API.Counterparties |
| Repayments | Unit.API.Repayments |
| Recurring Repayments | Unit.API.RecurringRepayments |
| Check Deposits | Unit.API.CheckDeposits |
| Check Payments | Unit.API.CheckPayments |
| Stop Payments | Unit.API.StopPayments |
| Chargebacks | Unit.API.Chargebacks |
| Disputes | Unit.API.Disputes |
| Rewards | Unit.API.Rewards |
| Fees | Unit.API.Fees |
| Statements | Unit.API.Statements |
| Tax Forms | Unit.API.TaxForms |
| Webhooks | Unit.API.Webhooks |
| Events | Unit.API.Events |
| Tokens | Unit.API.Tokens |
| Institutions | Unit.API.Institutions |
| ATM Locations | Unit.API.AtmLocations |
| Account End-of-Day | Unit.API.AccountEndOfDay |
| Account Limit Overrides | Unit.API.AccountLimitOverrides |
| Sandbox | Unit.API.Sandbox |
Configuration
# config/runtime.exs
config :unit,
api_token: System.get_env("UNIT_API_TOKEN"),
environment: :sandbox # :sandbox | :productionQuick start
# 1. Onboard an individual customer
{:ok, app} = Unit.API.Applications.create_individual(%{
full_name: %{first: "Jane", last: "Doe"},
ssn: "000000002",
date_of_birth: ~D[1990-01-15],
address: %{street: "123 Main St", city: "SF", state: "CA",
postal_code: "94105", country: "US"},
email: "jane@example.com",
phone: %{country_code: "1", number: "5555550100"},
ip: "127.0.0.1"
})
# 2. Open accounts
{:ok, account} = Unit.API.Accounts.create_deposit(app.customer_id, "checking")
{:ok, credit} = Unit.API.Accounts.create_credit(app.customer_id, "basic-credit")
# 3. Issue a virtual debit card
{:ok, card} = Unit.API.Cards.create_individual_virtual_debit(%{
customer_id: app.customer_id,
account_id: account.id
})
# 4. Send money
{:ok, payment} = Unit.API.Payments.create_ach(%{
account_id: account.id,
amount: 10_000,
direction: "Credit",
description: "Payroll",
counterparty: %{routing_number: "812345678",
account_number: "1000000002",
account_type: "Checking", name: "Jane Doe"}
})
# 5. Set up recurring payments
{:ok, _} = Unit.API.RecurringPayments.create_credit_ach(%{
account_id: account.id,
amount: 5_000,
description: "Monthly savings transfer",
counterparty_id: counterparty.id,
schedule: %{interval: "Monthly", day_of_month: 1,
start_time: ~D[2024-02-01]}
})
# 6. Reward the customer
{:ok, _} = Unit.API.Rewards.create(%{
amount: 500,
description: "Sign-up bonus",
receiving_account_id: account.id,
funding_account_id: revenue_account_id
})Error handling
All functions return {:ok, result} or {:error, %Unit.Error{}}:
case Unit.API.Payments.create_ach(params) do
{:ok, payment} ->
Logger.info("Payment created: #{payment.id}")
{:error, %Unit.Error{type: :validation_error, errors: errors}} ->
Logger.warning("Validation: #{inspect(errors)}")
{:error, %Unit.Error{type: :auth_error}} ->
Logger.error("Invalid token")
{:error, %Unit.Error{type: :network_error}} ->
Logger.error("Network failure — will retry automatically")
endPer-request overrides
# Use a customer-scoped token
Unit.API.Accounts.list(api_token: customer_token)
# Point to a custom base URL
Unit.API.Sandbox.receive_ach(params, base_url: "http://localhost:8080")Telemetry
:telemetry.attach("unit-log", [:unit, :request, :stop],
fn _evt, %{duration: d}, %{resource: r, action: a, status: s}, _ ->
Logger.info("[Unit] #{r}.#{a} → #{s} (#{div(d, 1_000_000)}ms)")
end, nil)