A Java implementation of Google's Agent Payments Protocol (AP2) built on top of a2ajava.
ap2java is an early-stage Java project in the AI payments / x402 ecosystem. It currently has 7 GitHub stars and 0 forks.
A Java implementation of Google's Agent Payments Protocol (AP2) built on top of a2ajava.
⚠️ Disclaimer: The AP2 protocol is new and still evolving. I have made every effort to validate the implementation details presented here and build a sample java implementation on top of a2ajava; however, some of the technical examples (such as Java code snippets or JSON-RPC message formats) are illustrative and not taken directly from Google’s codebase. The core concepts, goals, and partnerships of AP2 are captured accurately, but developers should always cross-check the latest specifications and the official AP2 GitHub repository for up-to-date implementation details.
AP2Java provides a complete implementation of Google's Agent Payments Protocol (AP2) in Java, allowing Java applications to participate in agent-based payment ecosystems. The project extends the a2ajava library to support payment operations between agents.
This implementation closely follows the patterns in Google's AP2 samples repository:
Domain Models: Similar to the Python and Android samples, this Java implementation defines core payment entities like Payment, PaymentRequest, and PaymentResponse.
Payment Processing Flow: Follows the same flow as Google's samples:
Agent Integration: Extends a2ajava's AgentCard to add payment capabilities through PaymentEnabledAgentCard.
Payment Processor Interface: Provides a standardized interface (PaymentProcessor) that can be implemented for different payment providers.
Message Processing: Integrates with a2ajava's messaging system to process payment-related messages between agents.
mvn clean install
# Simple payment example
mvn exec:java -Dexec.mainClass="io.github.ap2java.examples.SimplePaymentExample"
# Integration with a2ajava example
mvn exec:java -Dexec.mainClass="io.github.ap2java.examples.AP2IntegrationExample"
// Create payment-enabled agent card
PaymentEnabledAgentCard agentCard = new PaymentEnabledAgentCard();
// ... configure agent card ...
// Create payment processor
PaymentProcessor paymentProcessor = new SamplePaymentProcessor();
// Create AP2 client
AP2Client ap2Client = new AP2Client(paymentProcessor, agentCard);
// Create payment request
PaymentRequest paymentRequest = PaymentRequest.builder()
.amount(new BigDecimal("50.00"))
.currencyCode("USD")
.requestingAgentId("agent-123")
.receivingAgentId("merchant-456")
.description("Service payment")
.build();
// Create payment
PaymentResponse response = ap2Client.createPayment(paymentRequest).get();
Lucid Agents Commerce SDK. Bootstrap AI agents in 60 seconds that can pay, sell, and participate in agentic commerce supply chains. Our protocol agnostic SDK provides CLI-generated templates and drop-in adapters for Hono, Express, Next.js, and TanStack, giving you instant access to crypto/fiat payment rails (AP2, A2A, x402, ERC8004).
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Skills & plugins for agentic commerce : UCP, ACP, AP2, A2A, WebMCP, Magento 2, BigCommerce, WooCommerce
Trust infrastructure for million-agent economies on Solana - identity, reputation, and validation designed for continuous feedback at scale.
A chain-agnostic AI-native payment infrastructure, authz layer for x402