Package com.tnsai.payment.x402
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 casesnetwork- x402 canonical network id — must match one ofNetwork.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 madedescription- human-readable label for loggingmimeType- expected response media typepayTo- recipient address (0x...hex)asset- token contract address (0x...hex); the verifyingContract in the EIP-712 domainmaxTimeoutSeconds- quote validity window in secondsextra- token-specific extras — for EIP-3009 USDC, carriesname+versionfor 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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasset()Returns the value of theassetrecord component.Returns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.extra()Returns the value of theextrarecord component.final inthashCode()Returns a hash code value for this object.booleantruewhen this entry is something the P3 broker knows how to settle.ParsemaxAmountRequiredinto aBigInteger.Returns the value of themaxAmountRequiredrecord component.intReturns the value of themaxTimeoutSecondsrecord component.mimeType()Returns the value of themimeTyperecord component.network()Returns the value of thenetworkrecord component.payTo()Returns the value of thepayTorecord component.resource()Returns the value of theresourcerecord component.scheme()Returns the value of theschemerecord component.Token name fromextra.name; falls back to"USD Coin".Token EIP-712 domain version fromextra.version; falls back to"2".final StringtoString()Returns a string representation of this record class.
-
Field Details
-
SCHEME_EXACT
The only scheme P3 handles end-to-end.- See Also:
-
-
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 aPaymentRequirementrecord class.- Parameters:
scheme- the value for theschemerecord componentnetwork- the value for thenetworkrecord componentmaxAmountRequired- the value for themaxAmountRequiredrecord componentresource- the value for theresourcerecord componentdescription- the value for thedescriptionrecord componentmimeType- the value for themimeTyperecord componentpayTo- the value for thepayTorecord componentasset- the value for theassetrecord componentmaxTimeoutSeconds- the value for themaxTimeoutSecondsrecord componentextra- the value for theextrarecord component
-
-
Method Details
-
isHandled
truewhen this entry is something the P3 broker knows how to settle. -
tokenName
Token name fromextra.name; falls back to"USD Coin". -
tokenVersion
Token EIP-712 domain version fromextra.version; falls back to"2". -
maxAmountAsBigInteger
ParsemaxAmountRequiredinto aBigInteger. -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
scheme
Returns the value of theschemerecord component.- Returns:
- the value of the
schemerecord component
-
network
Returns the value of thenetworkrecord component.- Returns:
- the value of the
networkrecord component
-
maxAmountRequired
Returns the value of themaxAmountRequiredrecord component.- Returns:
- the value of the
maxAmountRequiredrecord component
-
resource
Returns the value of theresourcerecord component.- Returns:
- the value of the
resourcerecord component
-
description
Returns the value of thedescriptionrecord component.- Returns:
- the value of the
descriptionrecord component
-
mimeType
Returns the value of themimeTyperecord component.- Returns:
- the value of the
mimeTyperecord component
-
payTo
Returns the value of thepayTorecord component.- Returns:
- the value of the
payTorecord component
-
asset
Returns the value of theassetrecord component.- Returns:
- the value of the
assetrecord component
-
maxTimeoutSeconds
public int maxTimeoutSeconds()Returns the value of themaxTimeoutSecondsrecord component.- Returns:
- the value of the
maxTimeoutSecondsrecord component
-
extra
Returns the value of theextrarecord component.- Returns:
- the value of the
extrarecord component
-