Record Class PaymentRequirement

java.lang.Object
java.lang.Record
com.tnsai.payment.x402.PaymentRequirement
Record Components:
scheme - payment scheme — only "exact" is handled in P3; future schemes (e.g. "upTo") will land as separate cases
network - x402 canonical network id — must match one of Network.canonicalId()
maxAmountRequired - token's smallest unit (USDC has 6 decimals, so "1000" is $0.001)
resource - the resource URL being paid for; used as a cross-check against the request the client made
description - human-readable label for logging
mimeType - expected response media type
payTo - recipient address (0x... hex)
asset - token contract address (0x... hex); the verifyingContract in the EIP-712 domain
maxTimeoutSeconds - quote validity window in seconds
extra - token-specific extras — for EIP-3009 USDC, carries name + version for the EIP-712 domain

public record PaymentRequirement(String scheme, String network, String maxAmountRequired, String resource, String description, String mimeType, String payTo, String asset, int maxTimeoutSeconds, Map<String,String> extra) extends Record
One entry in the accepts array of an x402 HTTP 402 response.

Each entry describes one way a server is willing to be paid for the resource the client just asked for. A typical payment requirement on Base mainnet looks like:

 {
   "scheme": "exact",
   "network": "base-mainnet",
   "maxAmountRequired": "1000",
   "resource": "https://api.example.com/embed",
   "description": "Embedding service",
   "mimeType": "application/json",
   "payTo": "0xRecipient...",
   "asset": "0xUSDC...",
   "maxTimeoutSeconds": 60,
   "extra": { "name": "USD Coin", "version": "2" }
 }
 

The X402PaymentBroker parses the 402 body into a list of these, picks the first compatible one (matching scheme + network + EVM family), and uses it to build the EIP-712 typed data.

Since:
0.10.5 (TNS-449 P3)
  • Field Details

  • Constructor Details

    • PaymentRequirement

      public PaymentRequirement(String scheme, String network, String maxAmountRequired, String resource, String description, String mimeType, String payTo, String asset, int maxTimeoutSeconds, Map<String,String> extra)
      Creates an instance of a PaymentRequirement record class.
      Parameters:
      scheme - the value for the scheme record component
      network - the value for the network record component
      maxAmountRequired - the value for the maxAmountRequired record component
      resource - the value for the resource record component
      description - the value for the description record component
      mimeType - the value for the mimeType record component
      payTo - the value for the payTo record component
      asset - the value for the asset record component
      maxTimeoutSeconds - the value for the maxTimeoutSeconds record component
      extra - the value for the extra record component
  • Method Details

    • isHandled

      public boolean isHandled(Network targetNetwork)
      true when this entry is something the P3 broker knows how to settle.
    • tokenName

      public String tokenName()
      Token name from extra.name; falls back to "USD Coin".
    • tokenVersion

      public String tokenVersion()
      Token EIP-712 domain version from extra.version; falls back to "2".
    • maxAmountAsBigInteger

      public BigInteger maxAmountAsBigInteger()
      Parse maxAmountRequired into a BigInteger.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scheme

      public String scheme()
      Returns the value of the scheme record component.
      Returns:
      the value of the scheme record component
    • network

      public String network()
      Returns the value of the network record component.
      Returns:
      the value of the network record component
    • maxAmountRequired

      public String maxAmountRequired()
      Returns the value of the maxAmountRequired record component.
      Returns:
      the value of the maxAmountRequired record component
    • resource

      public String resource()
      Returns the value of the resource record component.
      Returns:
      the value of the resource record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • mimeType

      public String mimeType()
      Returns the value of the mimeType record component.
      Returns:
      the value of the mimeType record component
    • payTo

      public String payTo()
      Returns the value of the payTo record component.
      Returns:
      the value of the payTo record component
    • asset

      public String asset()
      Returns the value of the asset record component.
      Returns:
      the value of the asset record component
    • maxTimeoutSeconds

      public int maxTimeoutSeconds()
      Returns the value of the maxTimeoutSeconds record component.
      Returns:
      the value of the maxTimeoutSeconds record component
    • extra

      public Map<String,String> extra()
      Returns the value of the extra record component.
      Returns:
      the value of the extra record component