Encodes and decodes the x402 PAYMENT-RESPONSE header value.
The header is Base64-encoded JSON and is typically returned by a server after settlement.
Summary
Header Encoding
Decodes a Base64 PAYMENT-RESPONSE value to a map.
Encodes a settlement response payload to a Base64 header value.
Returns the canonical x402 header name.
Header Encoding
@spec decode(String.t()) :: {:ok, map()} | {:error, decode_error()}
Decodes a Base64 PAYMENT-RESPONSE value to a map.
Returns {:error, :payload_too_large} when the encoded value exceeds 8 KB.
Returns {:error, :invalid_base64} when the value cannot be Base64-decoded.
Returns {:error, :invalid_json} when JSON cannot be decoded to a map.
Examples
iex> {:ok, value} = X402.PaymentResponse.encode(%{"settled" => true})
iex> X402.PaymentResponse.decode(value)
{:ok, %{"settled" => true}}
iex> X402.PaymentResponse.decode("%%%")
{:error, :invalid_base64}
@spec encode(map()) :: {:ok, String.t()} | {:error, encode_error()}
Encodes a settlement response payload to a Base64 header value.
Examples
iex> {:ok, value} = X402.PaymentResponse.encode(%{"settled" => true})
iex> X402.PaymentResponse.decode(value)
{:ok, %{"settled" => true}}
@spec header_name() :: String.t()
Returns the canonical x402 header name.
Examples
iex> X402.PaymentResponse.header_name()
"PAYMENT-RESPONSE"