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
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
decode_payment_response | 1 | Decode a PAYMENT-RESPONSE header into a SettlementResponse object. | header: value |
encode_payment_response | 1 | Encode a SettlementResponse object for PAYMENT-RESPONSE. | value: value |
decode_payment_signature | 1 | Decode a PAYMENT-SIGNATURE header into a PaymentPayload object. | header: value |
encode_payment_signature | 1 | Encode a PaymentPayload object for PAYMENT-SIGNATURE. | value: value |
decode_payment_required | 1 | Decode a PAYMENT-REQUIRED header into a PaymentRequired object. | header: value |
encode_payment_required | 1 | Encode a PaymentRequired object for PAYMENT-REQUIRED. | value: value |
payment_response_header | 0 | Return the x402 payment-response HTTP field name. | - |
payment_signature_header | 0 | Return the x402 payment-signature HTTP field name. | - |
payment_required_header | 0 | Return 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 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 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.
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 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 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 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 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 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.
@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`"}}
@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`"}}
@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 an accept whose extra.assetTransferMethod is Permit2.