@nevermined-io/payments
    Preparing search index...

    Class X402A2AUtils

    Utilities for managing x402 payment state in A2A messages and tasks.

    Provides methods to extract payment status / requirements / payload from incoming A2A messages and tasks, and to stamp payment-required, verified, completed and failed state onto outgoing tasks — all via the spec-defined x402.payment.* metadata keys.

    Index

    Constructors

    Properties

    ERROR_KEY: "x402.payment.error" = X402A2AMetadata.ERROR_KEY
    PAYLOAD_KEY: "x402.payment.payload" = X402A2AMetadata.PAYLOAD_KEY
    RECEIPTS_KEY: "x402.payment.receipts" = X402A2AMetadata.RECEIPTS_KEY
    REQUIRED_KEY: "x402.payment.required" = X402A2AMetadata.REQUIRED_KEY
    STATUS_KEY: "x402.payment.status" = X402A2AMetadata.STATUS_KEY

    Methods

    • Set a Task to the payment-required state (input-required) with the X402PaymentRequired object in x402.payment.required metadata.

      Mutates and returns task (in place), per the x402 v2 A2A transport.

      Parameters

      Returns Task

    • Extract the in-band PaymentPayload object from a Task's status message metadata.

      Parameters

      • Optionaltask: Task | null

      Returns Record<string, any> | undefined

    • Extract the in-band PaymentPayload object from a Message's metadata.

      The payload is untrusted client input that the server re-encodes into an access token, so this rejects null, arrays and oversized payloads (defense-in-depth, parity with the MCP readPaymentPayload).

      Parameters

      • Optionalmessage: Message | null

      Returns Record<string, any> | undefined

      The PaymentPayload object, or undefined when absent/invalid.

    • Extract the X402PaymentRequired object from a Message's metadata.

      Returns the raw object (already spec-shaped JSON). Returns undefined when absent or not a plain object.

      Parameters

      • Optionalmessage: Message | null

      Returns X402PaymentRequired | undefined

    • Extract the payment status from a Task's status message metadata, or undefined.

      Parameters

      • Optionaltask: Task | null

      Returns string | undefined

    • Extract the payment status from a Message's metadata, or undefined.

      Parameters

      • Optionalmessage: Message | null

      Returns string | undefined

    • Record a deferred (batch) settlement on a Task: the payload was verified but on-chain settlement is deferred out-of-band (the handler never confirms it). Sets payment-verified PLUS the Nevermined x402.payment.settlement: 'deferred' marker, so a client can tell it will be charged out-of-band — distinct from a plain verify where nothing is owed.

      Parameters

      Returns Task

    • Record a payment failure on a Task: x402.payment.status = payment-failed, the error code under x402.payment.error, and (when available) the failed SettleResponse under x402.payment.receipts.

      Parameters

      Returns Task

    • Record payment verification on a Task: sets the x402.payment.status metadata to payment-verified. Task state is left to the caller (the spec keeps it working).

      Parameters

      Returns Task