MPP.X402.Headers (mpp v0.19.0)

Copy Markdown View Source

x402 v2 HTTP header codecs.

Wire encoding is standard Base64 JSON (PAYMENT-REQUIRED, PAYMENT-SIGNATURE, PAYMENT-RESPONSE). This is distinct from native Payment-auth base64url/JCS headers — a PAYMENT-* value is rejected by MPP.Headers as :invalid_scheme.

API Functions

FunctionArityDescriptionParam Kinds
decode_payment_response1Decode a PAYMENT-RESPONSE header into a SettlementResponse object.header: value
encode_payment_response1Encode a SettlementResponse object for PAYMENT-RESPONSE.value: value
decode_payment_signature1Decode a PAYMENT-SIGNATURE header into a PaymentPayload object.header: value
encode_payment_signature1Encode a PaymentPayload object for PAYMENT-SIGNATURE.value: value
decode_payment_required1Decode a PAYMENT-REQUIRED header into a PaymentRequired object.header: value
encode_payment_required1Encode a PaymentRequired object for PAYMENT-REQUIRED.value: value
payment_response_header0Return the x402 payment-response HTTP field name.-
payment_signature_header0Return the x402 payment-signature HTTP field name.-
payment_required_header0Return the x402 payment-required HTTP field name.-

Summary

Functions

Decode a PAYMENT-REQUIRED header into a PaymentRequired object.

Decode the PAYMENT-REQUIRED envelope without requiring every accept to be a supported exact EVM offer. Matches mppx decodePaymentRequiredEnvelope.

Decode a PAYMENT-RESPONSE header into a SettlementResponse object.

Decode a PAYMENT-SIGNATURE header into a PaymentPayload object.

Encode a PaymentRequired object for PAYMENT-REQUIRED.

Encode a SettlementResponse object for PAYMENT-RESPONSE.

Encode a PaymentPayload object for PAYMENT-SIGNATURE.

Parse exact EVM payment requirements. Permit2 extras are left for reject_permit2/1.

Parse a facilitator settle / PAYMENT-RESPONSE JSON body.

Parse a facilitator verify JSON body.

Return the x402 payment-required HTTP field name.

Return the x402 payment-response HTTP field name.

Return the x402 payment-signature HTTP field name.

Reject an accept whose extra.assetTransferMethod is Permit2.

Functions

decode_payment_required(header)

@spec decode_payment_required(String.t()) :: {:ok, map()} | {:error, atom()}

Decode a PAYMENT-REQUIRED header into a PaymentRequired object.

Parameters

  • header - Base64 JSON header value (value)

Returns

{:ok, map} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{header: %{description: "Base64 JSON header value", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, map}` or `{:error, reason}`"
  }
}

decode_payment_required_envelope(header)

@spec decode_payment_required_envelope(String.t()) :: {:ok, map()} | {:error, atom()}

Decode the PAYMENT-REQUIRED envelope without requiring every accept to be a supported exact EVM offer. Matches mppx decodePaymentRequiredEnvelope.

decode_payment_response(header)

@spec decode_payment_response(String.t()) :: {:ok, map()} | {:error, atom()}

Decode a PAYMENT-RESPONSE header into a SettlementResponse object.

Parameters

  • header - Base64 JSON header value (value)

Returns

{:ok, map} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{header: %{description: "Base64 JSON header value", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, map}` or `{:error, reason}`"
  }
}

decode_payment_signature(header)

@spec decode_payment_signature(String.t()) :: {:ok, map()} | {:error, atom()}

Decode a PAYMENT-SIGNATURE header into a PaymentPayload object.

Parameters

  • header - Base64 JSON header value (value)

Returns

{:ok, map} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{header: %{description: "Base64 JSON header value", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, map}` or `{:error, reason}`"
  }
}

encode_payment_required(value)

@spec encode_payment_required(map()) :: {:ok, String.t()} | {:error, atom()}

Encode a PaymentRequired object for PAYMENT-REQUIRED.

Parameters

  • value - PaymentRequired map (value)

Returns

{:ok, header} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{value: %{description: "PaymentRequired map", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, header}` or `{:error, reason}`"
  }
}

encode_payment_response(value)

@spec encode_payment_response(map()) :: {:ok, String.t()} | {:error, atom()}

Encode a SettlementResponse object for PAYMENT-RESPONSE.

Parameters

  • value - SettlementResponse map (value)

Returns

{:ok, header} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{value: %{description: "SettlementResponse map", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, header}` or `{:error, reason}`"
  }
}

encode_payment_signature(value)

@spec encode_payment_signature(map()) :: {:ok, String.t()} | {:error, atom()}

Encode a PaymentPayload object for PAYMENT-SIGNATURE.

Parameters

  • value - PaymentPayload map (value)

Returns

{:ok, header} or {:error, reason} (tagged_tuple)

# descripex:contract
%{
  params: %{value: %{description: "PaymentPayload map", kind: :value}},
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, header}` or `{:error, reason}`"
  }
}

parse_requirements(value)

@spec parse_requirements(map()) :: {:ok, map()} | {:error, atom()}

Parse exact EVM payment requirements. Permit2 extras are left for reject_permit2/1.

parse_settle_response(value)

@spec parse_settle_response(map()) :: {:ok, map()} | {:error, atom()}

Parse a facilitator settle / PAYMENT-RESPONSE JSON body.

parse_verify_response(value)

@spec parse_verify_response(map()) :: {:ok, map()} | {:error, atom()}

Parse a facilitator verify JSON body.

payment_required_header()

@spec payment_required_header() :: String.t()

Return the x402 payment-required HTTP field name.

Returns

PAYMENT-REQUIRED (string)

# descripex:contract
%{returns: %{type: :string, description: "`PAYMENT-REQUIRED`"}}

payment_response_header()

@spec payment_response_header() :: String.t()

Return the x402 payment-response HTTP field name.

Returns

PAYMENT-RESPONSE (string)

# descripex:contract
%{returns: %{type: :string, description: "`PAYMENT-RESPONSE`"}}

payment_signature_header()

@spec payment_signature_header() :: String.t()

Return the x402 payment-signature HTTP field name.

Returns

PAYMENT-SIGNATURE (string)

# descripex:contract
%{returns: %{type: :string, description: "`PAYMENT-SIGNATURE`"}}

reject_permit2(arg1)

@spec reject_permit2(map()) :: :ok | {:error, atom()}

Reject an accept whose extra.assetTransferMethod is Permit2.