X402.Client.Hooks.Context (X402 v0.9.0)

Copy Markdown View Source

Context passed between X402.Client.Hooks callbacks.

  • :payment_required — the decoded PaymentRequired map the payment is built for, or nil when X402.Client.build_payment/3 was given a bare requirements map.
  • :requirements — the selected accepts entry. before_payment/2 may replace it; the replacement is what gets signed.
  • :opts — the validated build options.
  • :payload — the assembled PaymentPayload, set for after_payment/2, which may replace it.
  • :error — the failure reason, set for on_payment_failure/2, which may replace it.

Summary

Functions

Builds a new client hook context.

Types

t()

@type t() :: %X402.Client.Hooks.Context{
  error: term() | nil,
  opts: keyword(),
  payload: map() | nil,
  payment_required: map() | nil,
  requirements: map()
}

Functions

new(payment_required, requirements, opts)

(since 0.9.0)
@spec new(map() | nil, map(), keyword()) :: t()

Builds a new client hook context.

Examples

iex> requirements = %{"scheme" => "exact", "network" => "eip155:8453"}
iex> context = X402.Client.Hooks.Context.new(%{"accepts" => [requirements]}, requirements, [])
iex> context.requirements["scheme"]
"exact"
iex> {context.payload, context.error}
{nil, nil}