OpenPayments.OutgoingPayment (open_payments_elixir v1.0.0)

Copy Markdown View Source

Authenticated outgoing-payment operations on an Open Payments resource server.

Reads sign a GET to a complete resource URL with the client's key and a per-call access token. Paths and queries are opaque; no provider layout or wallet/receiver lookup is inferred. HTTPS is required unless HTTP was explicitly enabled on the client. Redirects and automatic retries are disabled. Creation signs a POST to the outgoing-payments collection using either supported request form and returns typed payment data with optional grant spent amounts. Listing signs a GET with wallet/pagination query arguments and returns one typed page, applying the same payment consistency rules to each item. Grant-spent reads return the presented token's current grant/interval amounts from the resource server, independently of any individual payment.

Summary

Functions

Creates an outgoing payment using one signed POST and a validated request form.

Fetches an outgoing payment using a signed GET and a per-call access token.

Reads the current outgoing-grant spent amounts with a signed bodyless GET.

Lists one page of outgoing payments using a signed GET.

Functions

create(client, base_url, payload, opts)

Creates an outgoing payment using one signed POST and a validated request form.

Supply the resource-server base, a CreateOutgoingPayment struct or protocol map, and the required per-call access_token option accepted by get/3. Appends /outgoing-payments, preserving tenant paths and reusing a trailing slash. Base queries, including an empty marker, are rejected. URL/token policies apply.

Both typed/map inputs are validated before HTTP. Supply quote_id, or both incoming_payment and debit_amount; metadata is optional. No quote/wallet/receiver is fetched and no amount is inferred. The server checks quote validity, wallet asset compatibility, grant permissions and key binding.

HTTP 201 returns OutgoingPaymentWithSpentAmounts. Either, both or neither grant spent amount may appear; permitted JSON extensions are retained. Shared debit/sent consistency checks match get/3, including original-string equality for the failed rule. No zero-sent, failed-false, request/response identity or amount equality, grant-budget or grant-asset rule is added. Creation responses may already reflect payment progress. Invalid success schemas or consistency return decoding/invalid_response/status201; all errors carry :create_outgoing_payment.

Creating an outgoing payment authorizes processing by the server. This call does not make a second send request, retry, follow redirects, refresh a token, poll or read back the resource. A timeout, lost response or invalid response may occur after the server has created/started the payment. The caller decides how to reconcile that outcome; automatic replay could duplicate the payment.

get(client, url, opts)

Fetches an outgoing payment using a signed GET and a per-call access token.

Supply an authenticated client and the full resource URL; no path is appended. Queries and nondefault HTTPS ports are supported. The required access_token option accepts a raw string or a typed AccessToken, revalidated before using its value. Duplicate/unsupported options and continuation credentials are rejected. Request URL/token68 policies apply. The server checks permission, token expiry and key binding; no token metadata inference is performed locally.

HTTP 200 returns OpenPayments.Types.OutgoingPayment with three typed amounts. Following Node, debit and sent assets must match, sent value cannot exceed debit using exact integer arithmetic, and identical debit/sent value strings cannot accompany failed true. The last check deliberately compares original strings: differently padded decimal spellings are preserved, matching Node's behavior. Receive assets can differ. No positivity, fee/FX, completion-state inference or requested URL/wallet/receiver equality check is added.

Schema and consistency failures return decoding/invalid_response with status 200 and safe field paths; all errors carry :get_outgoing_payment. Optional failed remains nil when omitted. Inspection hides amounts, metadata and related references; explicit exports include them. This call makes no payment, caches no state, fetches no related resource and does not refresh tokens or poll.

get_grant_spent_amounts(client, base_url, opts)

@spec get_grant_spent_amounts(OpenPayments.Client.t(), String.t(), [
  {:access_token, String.t() | OpenPayments.Types.AccessToken.t()}
]) ::
  {:ok, OpenPayments.Types.OutgoingPaymentGrantSpentAmounts.t()}
  | {:error, OpenPayments.Error.t()}

Reads the current outgoing-grant spent amounts with a signed bodyless GET.

Supply the resource-server base and required per-call access_token option accepted by get/3, as a raw string or typed issued token. Appends /outgoing-payment-grant, preserving tenant paths and trailing slashes. Base queries, including an empty marker, are rejected. No wallet filter, grant ID or pagination is sent. Request URL/token policies apply; no management URL is used.

HTTP 200 returns OutgoingPaymentGrantSpentAmounts with both required fields, each typed Amount or nil for explicit null. Root/nested JSON extensions and decimal spelling are preserved. The server selects the grant and current recurring interval associated with the token. No asset/value/budget comparison, interval computation, null-to-zero default, token expiry/permission inference or grant-state conclusion is added, following Node's operation.

Schema failures return decoding/invalid_response/status200 with safe field paths; all errors carry :get_outgoing_payment_grant. Inspection hides payloads; explicit exports include amounts, extensions and both required nulls. This call does not create payments, fetch related resources, cache, poll, refresh tokens, follow redirects or retry. The caller supplies the current token on each call.

list(client, base_url, wallet_address, opts)

Lists one page of outgoing payments using a signed GET.

Supply the resource-server base and a separate wallet filter. The required access_token option accepts the same raw string or typed token as get/3. Optional pagination accepts a typed Pagination or protocol map; omission sends no count/cursor defaults, while explicit nil is invalid. Duplicate or unsupported options and per-call key/header overrides are rejected.

The wallet filter follows the pinned required-string query schema, without URI validation, pointer resolution or substitution of client identity. Every UTF-8 string, including empty, is encoded and sent. Unlike Node's truthy filtering, an empty wallet string is not silently omitted; server meaning/permission checks still apply. Usually supply the discovered wallet ID.

Appends /outgoing-payments while preserving tenant paths and trailing slashes; base queries are rejected. Uses the same Node URLSearchParams-compatible form encoding and wallet-first/sorted pagination order as incoming-payment listing. The entire query is encoded before signing the bodyless GNAP GET.

HTTP 200 returns OutgoingPaymentPaginationResult with strict detailed items. Each item must pass the same ordered debit/sent consistency checks as get/3. Schema/consistency failures return decoding/invalid_response/status200 with safe indexed paths such as result[1].sent_amount; errors carry :list_outgoing_payments. Creation spent-amount fields are not list item data.

This call does not compare filter/result identities, page sizes, flags/cursors or ordering, cache state, traverse pages, follow links/redirects, retry, refresh tokens or poll. Choose direction/cursor and credentials for each subsequent call. Explicit exports include cursors, references, amounts, metadata and extensions.