Package com.tnsai.payment
Interface PaymentBroker
- All Known Implementing Classes:
NoOpPaymentBroker
public interface PaymentBroker
Settlement bus for agent-to-agent payments (TNS-298). Brokers wrap
an underlying payment rail (x402, Stripe, Lightning Network, an
internal credit ledger) and expose the same two-phase contract:
quote prices the work, settle actually moves funds.
Why a broker
Inside a single trust boundary (one tenant, one process group) agents don't need to settle in real money — aNoOpPaymentBroker
lets the framework's accountability machinery thread through
untouched. Across trust boundaries (cross-tenant, cross-org,
decentralized agent economy) the same SPI plugs into a real rail.
Implementations
NoOpPaymentBroker— quotes at0.00 USD, all settlements succeed instantly. Default for internal multi-agent.X402PaymentBroker(follow-up) — HTTP 402-based micropayment over the agent economy stack.StripePaymentBroker(follow-up) — credit-card-backed settlement for human-paid agent services.
Idempotency
Callers MUST supply aService.metadata-derived idempotency
key when they construct the Quote via quote(com.tnsai.identity.AgentPrincipal, com.tnsai.identity.AgentPrincipal, com.tnsai.payment.Service); the
broker echoes it on Quote.idempotencyKey so retried
settle(com.tnsai.payment.Quote) calls land on the same payment instead of
double-charging.- Since:
- 0.10.0 (TNS-298)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classThrown byquote(com.tnsai.identity.AgentPrincipal, com.tnsai.identity.AgentPrincipal, com.tnsai.payment.Service)when broker policy refuses to price. -
Method Summary
Modifier and TypeMethodDescriptionstatic PaymentBrokernoOp()Returns the null-object broker: quotes at0.00 USD, settlements succeed instantly.quote(AgentPrincipal payer, AgentPrincipal payee, Service service) Compute the price forservicebetweenpayerandpayee, returning aQuotethe caller can later settle (withinQuote.expiresAt).Move funds forquote.
-
Method Details
-
noOp
Returns the null-object broker: quotes at0.00 USD, settlements succeed instantly. Used whentnsai-paymentsis off the classpath — same shape asContextManagerHandle.noOp()andFeedbackCollector.noOp().- Returns:
- a no-op PaymentBroker (singleton)
-
quote
Compute the price forservicebetweenpayerandpayee, returning aQuotethe caller can later settle (withinQuote.expiresAt).- Throws:
NullPointerException- if any arg is nullPaymentBroker.QuoteRejectedException- when broker policy refuses to quote (payer blocked, payee unverified, …); message is operator-actionable
-
settle
Move funds forquote. Idempotent: a second call with the sameQuote.idempotencyKeyreturnsSettlement.AlreadySettledinstead of double-charging.- Throws:
NullPointerException- ifquoteis null
-