Production-ready Elixir client for the GoCardlessClient API.
Quick Start
# 1. Configure in config/config.exs
config :gocardless_client,
access_token: System.get_env("GOCARDLESS_ACCESS_TOKEN"),
environment: :sandbox # or :live
# 2. Build a client
client = GoCardlessClient.client!()
# 3. Call the API
{:ok, customer} = GoCardlessClient.Resources.Customers.create(client, %{
email: "alice@example.com",
given_name: "Alice",
family_name: "Smith",
country_code: "GB"
})
{:ok, mandate} = GoCardlessClient.Resources.Mandates.create(client, %{
scheme: "bacs",
links: %{customer_bank_account: bank_account_id}
})
{:ok, payment} = GoCardlessClient.Resources.Payments.create(client, %{
amount: 1500,
currency: "GBP",
description: "Monthly fee",
links: %{mandate: mandate_id}
})Runtime Clients
client = GoCardlessClient.client!(access_token: "tok", environment: :live)
# Per-merchant token (OAuth partner apps)
client = GoCardlessClient.client!(access_token: merchant_token)Pagination
# Stream lazily — no memory pressure on large datasets
GoCardlessClient.Resources.Payments.stream(client, %{status: "paid_out"})
|> Stream.each(&reconcile/1)
|> Stream.run()
# Or collect all pages eagerly
{:ok, all_customers} = GoCardlessClient.Resources.Customers.collect_all(client)Webhooks
# In your Phoenix controller:
def handle(conn, _params) do
events = conn.private[:gocardless_events]
Enum.each(events, &dispatch_event/1)
send_resp(conn, 200, "")
endModules
Using Resource Modules
All resource operations live in GoCardlessClient.Resources.*. Use module aliases
for ergonomic access:
alias GoCardlessClient.Resources.{Customers, Payments, Mandates, Subscriptions}
{:ok, customer} = Customers.create(client, %{email: "alice@example.com"})
{:ok, payment} = Payments.create(client, %{amount: 1500, currency: "GBP"})
Summary
Functions
Returns the resolved base URL for a client's environment.
Builds a GoCardlessClient.Client from application config merged with opts.
Like client/1 but raises ArgumentError on invalid options.
Returns a new idempotency key (32 random hex chars).
Returns the current rate-limit state from the last observed API response.
Functions
@spec base_url(GoCardlessClient.Client.t()) :: String.t()
Returns the resolved base URL for a client's environment.
@spec client(keyword()) :: {:ok, GoCardlessClient.Client.t()} | {:error, NimbleOptions.ValidationError.t()}
Builds a GoCardlessClient.Client from application config merged with opts.
Returns {:ok, client} or {:error, %NimbleOptions.ValidationError{}}.
@spec client!(keyword()) :: GoCardlessClient.Client.t()
Like client/1 but raises ArgumentError on invalid options.
@spec new_idempotency_key() :: String.t()
Returns a new idempotency key (32 random hex chars).
@spec rate_limit_state(GoCardlessClient.Client.t()) :: map()
Returns the current rate-limit state from the last observed API response.