Package com.tnsai.payment.x402
Class X402PaymentBroker
java.lang.Object
com.tnsai.payment.x402.X402PaymentBroker
- All Implemented Interfaces:
com.tnsai.payment.PaymentBroker
x402 implementation of
PaymentBroker.
Two-phase contract: quote(AgentPrincipal, AgentPrincipal, Service)
probes the payee's resource URL, parses the HTTP 402 response, picks
a compatible PaymentRequirement, and mints a priced
Quote. settle(Quote) builds an EIP-3009
transferWithAuthorization payload, signs it with the
configured Wallet, and replays the original HTTP request with
the signed payload in the X-PAYMENT header.
Scope of P3
- Networks: Base mainnet + Base Sepolia (EVM family). Solana stub is in the network enum but not wired here.
- Schemes: only
"exact"(single fixed-amount transfer). The protocol's"upTo"and stream variants are out of scope. - Idempotency: the
Quote.idempotencyKeymaps deterministically to the EIP-3009 nonce; the facilitator dedups on nonce reuse and the broker surfaces a prior settlement asSettlement.AlreadySettled.
Tracked under TNS-449.
- Since:
- 0.10.5 (TNS-449 P3)
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tnsai.payment.PaymentBroker
com.tnsai.payment.PaymentBroker.QuoteRejectedException -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringService.metadata key for the HTTP method to probe with (defaults to GET).static final StringService.metadata key the caller can supply to fix the nonce (test/idempotency replay).static final StringService.metadata key for the resource URL to probe. -
Method Summary
Modifier and TypeMethodDescriptionstatic X402PaymentBrokercreate(X402Config config) Build a broker fromconfig; uses a freshSecureRandomfor nonces.static X402PaymentBrokercreate(X402Config config, SecureRandom nonceSource) Build a broker with a caller-suppliedSecureRandom— tests use this for determinism.com.tnsai.payment.Quotequote(com.tnsai.identity.AgentPrincipal payer, com.tnsai.identity.AgentPrincipal payee, com.tnsai.payment.Service service) com.tnsai.payment.Settlementsettle(com.tnsai.payment.Quote quote)
-
Field Details
-
METADATA_RESOURCE_URL
Service.metadata key for the resource URL to probe.- See Also:
-
METADATA_HTTP_METHOD
Service.metadata key for the HTTP method to probe with (defaults to GET).- See Also:
-
METADATA_NONCE_HEX
Service.metadata key the caller can supply to fix the nonce (test/idempotency replay).- See Also:
-
-
Method Details
-
create
Build a broker fromconfig; uses a freshSecureRandomfor nonces. -
create
Build a broker with a caller-suppliedSecureRandom— tests use this for determinism. -
quote
public com.tnsai.payment.Quote quote(com.tnsai.identity.AgentPrincipal payer, com.tnsai.identity.AgentPrincipal payee, com.tnsai.payment.Service service) - Specified by:
quotein interfacecom.tnsai.payment.PaymentBroker
-
settle
public com.tnsai.payment.Settlement settle(com.tnsai.payment.Quote quote) - Specified by:
settlein interfacecom.tnsai.payment.PaymentBroker
-