X402.Facilitator (X402 v0.3.3)

Copy Markdown View Source

Stateful client for x402 facilitator verify and settle operations.

Summary

Payment Verification

Settles a payment using the default facilitator process name.

Settles a payment using the given facilitator process.

Settles a payment using the given facilitator process and hook module.

Verifies a payment using the default facilitator process name.

Verifies a payment using the given facilitator process.

Verifies a payment using the given facilitator process and hook module.

Types

Facilitator response payload.

Facilitator server identifier accepted by GenServer.call/3.

Functions

Returns a child specification for X402.Facilitator.

Starts the facilitator client.

Payment Verification

settle(payment_payload, requirements)

(since 0.1.0)
@spec settle(map(), map()) :: response()

Settles a payment using the default facilitator process name.

settle(server, payment_payload, requirements)

(since 0.1.0)
@spec settle(server(), map(), map()) :: response()

Settles a payment using the given facilitator process.

settle(server, payment_payload, requirements, hooks_module)

(since 0.1.0)
@spec settle(server(), map(), map(), module()) :: response()

Settles a payment using the given facilitator process and hook module.

This overrides the hook module configured when the facilitator process started.

verify(payment_payload, requirements)

(since 0.1.0)
@spec verify(map(), map()) :: response()

Verifies a payment using the default facilitator process name.

verify(server, payment_payload, requirements)

(since 0.1.0)
@spec verify(server(), map(), map()) :: response()

Verifies a payment using the given facilitator process.

verify(server, payment_payload, requirements, hooks_module)

(since 0.1.0)
@spec verify(server(), map(), map(), module()) :: response()

Verifies a payment using the given facilitator process and hook module.

This overrides the hook module configured when the facilitator process started.

Types

operation_result()

@type operation_result() :: %{status: non_neg_integer(), body: map()}

Facilitator response payload.

response()

@type response() ::
  {:ok, operation_result()}
  | {:error, X402.Facilitator.Error.t() | X402.Hooks.hook_error() | term()}

server()

@type server() :: GenServer.server()

Facilitator server identifier accepted by GenServer.call/3.

state()

@type state() :: %{
  url: String.t(),
  finch: term(),
  hooks: module(),
  max_retries: non_neg_integer(),
  retry_backoff_ms: non_neg_integer(),
  receive_timeout_ms: non_neg_integer()
}

Functions

child_spec(init_arg)

(since 0.1.0)
@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child specification for X402.Facilitator.

start_link(opts)

(since 0.1.0)
@spec start_link(keyword()) ::
  GenServer.on_start() | {:error, NimbleOptions.ValidationError.t()}

Starts the facilitator client.

Options

  • :name (term/0) - Registered name of the facilitator client process. The default value is X402.Facilitator.

  • :url (String.t/0) - Facilitator base URL. The default value is "https://x402.org/facilitator".

  • :finch (term/0) - Required. Finch process name used for HTTP requests.

  • :hooks - Lifecycle hook module implementing X402.Hooks. The default value is X402.Hooks.Default.

  • :max_retries (non_neg_integer/0) - Maximum retry count for transient errors. The default value is 2.

  • :retry_backoff_ms (non_neg_integer/0) - Initial retry backoff in milliseconds. The default value is 100.

  • :receive_timeout_ms (non_neg_integer/0) - HTTP receive timeout in milliseconds. The default value is 5000.