OpenPayments.Client (open_payments_elixir v1.0.0)

Copy Markdown View Source

Immutable configuration for Open Payments operations.

new_public/1 constructs a client without keys or tokens and makes no requests. Use it with OpenPayments.WalletAddress.get/2, OpenPayments.WalletAddress.get_keys/2, or OpenPayments.IncomingPayment.get_public/2 for public reads.

new_authenticated/1 adds a wallet identity and an Ed25519 signing key. Use it with OpenPayments.Grant.request/3, OpenPayments.Grant.continue/2 and OpenPayments.Grant.cancel/2 for signed grant operations. OpenPayments.Token.rotate/2 and OpenPayments.Token.revoke/2 manage issued access tokens. OpenPayments.IncomingPayment.get/3 reads authenticated incoming-payment data. OpenPayments.IncomingPayment.create/4 creates incoming payments. OpenPayments.IncomingPayment.complete/3 marks them complete. OpenPayments.IncomingPayment.list/4 fetches one page of incoming payments. OpenPayments.Quote.get/3 reads a quote. OpenPayments.Quote.create/4 creates a quote. OpenPayments.OutgoingPayment.get/3 reads an outgoing payment. OpenPayments.OutgoingPayment.create/4 creates an outgoing payment. OpenPayments.OutgoingPayment.list/4 fetches one page of outgoing payments. OpenPayments.OutgoingPayment.get_grant_spent_amounts/3 reads current grant spending. Existing public operations remain unsigned with either client type.

Summary

Functions

Reports whether HTTP was explicitly enabled for local development.

Reports whether the client was constructed with a signing identity.

Creates a client with a validated wallet identity and Ed25519 signing key.

Creates an unsigned client with validated configuration.

Returns the normalized wallet identity, or nil for a public client.

Types

t()

@opaque t()

Functions

allow_http?(client)

@spec allow_http?(t()) :: boolean()

Reports whether HTTP was explicitly enabled for local development.

authenticated?(client)

@spec authenticated?(t()) :: boolean()

Reports whether the client was constructed with a signing identity.

new_authenticated(opts)

@spec new_authenticated(keyword()) :: {:ok, t()} | {:error, OpenPayments.Error.t()}

Creates a client with a validated wallet identity and Ed25519 signing key.

Accepts the same HTTP options as new_public/1, plus required wallet_address and either key: key from OpenPayments.Key, or key_id with an explicit private_key source: {:pem, text}, {:file, path}, {:base64_pem, text}, {:jwk, map}, or {:seed, bytes}. These two key configurations are mutually exclusive. Sources are not guessed and invalid keys are never replaced.

Wallet identity follows discovery's URL/payment-pointer rules. Construction makes no network requests and does not verify registration of the public key. Public operations remain unsigned. Tokens belong to individual operations and are not stored on the client. Grants use OpenPayments.Grant.request/3 and OpenPayments.Grant.continue/2, with OpenPayments.Grant.cancel/2 for cancellation; Token management uses OpenPayments.Token.rotate/2 and OpenPayments.Token.revoke/2. Authenticated incoming-payment operations use OpenPayments.IncomingPayment.get/3, OpenPayments.IncomingPayment.create/4, OpenPayments.IncomingPayment.complete/3 and OpenPayments.IncomingPayment.list/4. Quotes use OpenPayments.Quote.get/3 and OpenPayments.Quote.create/4. Outgoing payments use OpenPayments.OutgoingPayment.get/3 and OpenPayments.OutgoingPayment.create/4. OpenPayments.OutgoingPayment.list/4 lists them with per-call pagination. OpenPayments.OutgoingPayment.get_grant_spent_amounts/3 reads the token's current grant spent amounts.

new_public(opts \\ [])

@spec new_public(keyword()) :: {:ok, t()} | {:error, OpenPayments.Error.t()}

Creates an unsigned client with validated configuration.

Supports allow_http (default false), a custom headers map, positive millisecond connect_timeout, receive_timeout, request_timeout, and pool_timeout values, and a Req adapter module for tests. Transport defaults are 5 seconds for connect and pool waits, and 15 seconds for receive and complete-response waits.

Accept and Accept-Encoding are managed by the client: public API responses are requested as JSON with identity encoding. Signing/transport headers cannot be supplied through custom headers. No redirects or automatic retries are enabled.

wallet_address(client)

@spec wallet_address(t()) :: String.t() | nil

Returns the normalized wallet identity, or nil for a public client.