Agentic AI Payment Protocols
Java/Spring Boot Meets x402 Protocol
©Michael Kramarenko, November 2025
Tallinn Lviv
10111, Estonia, Harju county, 73 Heroiv UPA Str.
Tallinn city, Kai tn 1-5M, 79000
Top Nearshore Software
Development Companies Of
Top app development
company
KindGeek OÜ info@[Link]
2020 info@[Link]
1
Agentic AI Payment Ecosystem
Feature AP2 ACP TAP x402
Lead Proponent(s) Google & partners OpenAI & Stripe Visa & partners x402 Foundation
Primary Use Case Auditable agent‑led purchases with Agent‑ready checkout across Merchant‑side agent Micropayments/M2M for APIs,
explicit user authorization agent surfaces (often human verification & fraud control content, compute (stablecoins
confirm) today)
Core Mechanism Verifiable Mandates Intent → Cart → Checkout interaction model HTTP Message Signatures HTTP 402 challenge → pay →
Payment) using OpenAPI JSON RFC 9421 + agent registry /verify & /settle
Schema
Key Trustee Building Verifiable Mandate (user‑signed Standardized API contract Agent signature + registry/KYA Facilitator as source of truth
Block consent; auditable) (structured checkout objects) Know Your Agent)
Supported Rails Payment‑agnostic (cards, bank, Payment‑agnostic Payment‑agnostic (attestation Primarily stablecoins/crypto
stablecoins) layer) (design is rail‑agnostic)
End-User Touchpoint Explicit (user signs mandates) Semi‑visible (agent‑assisted Invisible (security/attestation) Mostly invisible (agent pays
checkout; confirm/controls) per request)
Relationships with Authorization layer; complements Checkout layer; complements Attestation layer; complements Payment rail; integrates with
Others A2A/MCP; can co‑exist with x402/ACP AP2 (mandates); hands off to AP2/ACP/x402 MCP/A2A; alongside AP2/ACP
x402 or cards
2
x402 Protocol Overview
Why x402 ?
x402 addresses key limitations of existing payment
systems:
● High fees and friction with traditional credit
cards and fiat payment processors
● Incompatibility with machine-to-machine
payments, such as AI agents, prevents the full
realization of autonomous digital economies
● Lack of support for micropayments, making it
difficult to monetize usage-based services
x402 enables AI agents to autonomously discover and
procure third-party cloud resources, contextual data,
and API tools, making it easier for them to achieve
their targeted optimization goals without
human-in-the-loop intervention
x402 designed to be rail-agnostic to be long term,
and removes account/session overhead for
machine-to-machine access.
Credit:
-[Link] [Link]
-[Link] 4
x402 Anatomy
Key Components:
● Client Buyer sends request and
retries with XPAYMENT
● Server enforces terms and uses a
Facilitator to verify and settle
onchain; then returns the resource
● Facilitator verifies payment
payloads submitted by clients.
Settles payments on the blockchain
on behalf of servers
By reviving the HTTP 402 Payment Required
status code, x402 lets services monetize APIs
and digital content onchain, allowing clients,
both human and machine, to programmatically
pay for access without accounts, sessions, or
complex authentication.
Credit:
-[Link] [Link]
-[Link] 5
x402 Payload Anatomy
Field Description Purpose & Analogy
network Blockchain network identifier The "Bank" : The specific
(e.g., "base") blockchain (e.g., Base Mainnet)
where the payment must occur.
resource The URL of the API being "What you're buying" : The
accessed specific API endpoint you are
trying to access (e.g.,
[Link]
maxAmountRequired The price in the token's smallest This is the "bill" the client must
unit (e.g., "10000" = 0.01 USDC, pay (e.g., 10000 0.01 USDC.
as USDC has 6 decimals)
payTo Recipientʼs wallet address The merchant's account where
the money must be sent.
maxTimeoutSeconds Timestamp or duration for validity Expiration Date: "the bill" is only
(e.g., 60 valid for a limited time (e.g., 60
seconds).
asset The asset's smart contract "Which currency" : The exact
address token contract address accepted
(e.g., Base Mainnet USDC.
[Link] Human-readable asset name Human-readable metadata to
(e.g., "USD Coin") confirm the asset.
6
Where to Find more x402?
7
Credit: [Link]
x402 for Java/Spring Boot
Fans
Mogami Approach
Mogami : What & Why?
● Mogami is an open-source, Java-first software stack
designed to implement the x402 Payment Protocol aimed to
fills a critical gap in the agentic commerce landscape: the lack
of a native, developer-friendly solution for Java/Spring Boot.
● Consists of several components, including a Spring Boot
Starter, a Java Client SDK, and a hosted Facilitator service.
● Java Client SDK makes it easy to bring x402 payments into
applications. It handles expiration, authorization, and
signature logic behind the scenes, so you can focus on
building features instead of managing payments.
● Java server SDK Spring boot starter) lets you transform any
API into a pay-per-call service powered by x402. The SDK
automatically verifies payment payloads and handles errors
gracefully, letting you stay focused on your business logic.
● Mogami Facilitator server acts as your payment gateway for
x402. You can run it within your own infrastructure, or use
our always-on hosted facilitator online. It verifies, authorizes,
and settles x402 transactions in real time, connecting your Credit:
-[Link]
services to the blockchain securely while keeping private -[Link]
keys safe. -[Link]
- [Link]
- [Link]
10
Preparation
● Create Metamask test wallet
● Generate USDC using [Link] in
Base Sepolia Testnet using Metamask test wallet
address
● Import tokens into Metamask test wallet by clicking
“Import tokensˮ. You should see your USDC balance in
Base Sepolia Testnet
● Export your Payer Address from Metamask test wallet.
We will use the same address for both sides: Merchant
& Buyers
● Export your Private Key from Metamask test wallet
● Never use real private keys in demos
● Never commit real private keys
11
E2E Example Overview
● Inspired by Mogami TipController example
● Covers E2E x402 flow:
○ Buyer side (aka TipGiverController)
○ Merchant side (aka TipReceiverController)
● Implemented as a single Spring Boot Tipping application
● TipReceiverController URL configuration:
[Link]-url =[Link]
● Mogami x402 facilitator configuration:
[Link]-url =[Link]
[Link] =x402-spring-mogami
[Link] =4021
[Link] =UTF-8
[Link] =true
[Link] =true
[Link]-url =[Link]
[Link]-network =base-sepolia
[Link]-payto =0x375605671ddA2d461E333Cfa51F5b53763E8C585
[Link]-url =[Link]
[Link] =Thank you for the tip!
[Link] =OFF
[Link] =DEBUG
[Link] =DEBUG
[Link].x402 =DEBUG
[Link] =/[Link]
12
Prerequisites
Key Maven dependencies:
● Spring Boot version: 3.5.5
● Mogami Spring Boot Starter version: 1.1.2
● Mogami Java Client version: 1.1.1
13
Buyer View
● First call to merchant
● Receive HTTP 402 status code with Payment
Requirement json
● Parse payment requirements:
X402PaymentHelper .getPaymentRequiredFromBody([Link]())
.orElseThrow(...);
● Build unsigned payload:
PaymentPayload unsigned =
[Link](null,
payerAddress, accept);
● Sign with MetaMask private key:
[Link](payerPrivateKey); PaymentPayload signed =
[Link](creds, accept, unsigned);
● Second call to merchant with XPAYMENT
<base64(signed payload)> header
14
Merchant View
● annotation X402PayUSDC implemented using
[Link], internally converted USDC to the
official assetAddress for USDC
("0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", base
address)
● The same merchant controller is invoked twice within the same
payment flow: without and with XPAYMENT <base64(signed
payload)> header.
● In the first case a 402 status code is returned
15
Coinbase Approach
Example Overview
● Inspired by Mogami TipController example
● Implemented as a single Spring Boot application
● Implement Merchant View only
● Key Maven dependencies:
○ Spring Boot version: 3.5.5
○ coinbase x402 version 0.10SNAPSHOT
17
Merchant View
● Filter-based implementation approach
● TipController logical flow is similar to TipReceiverController in
Mogami example
● PaymentFilter: the developer must manually instantiate a new
PaymentFilter(...) and wrap it in a FilterRegistrationBean
● PriceTable: the developer must manually construct a Map
(e.g., [Link]("tip", ...)) to tell the filter which paths cost how
much.
18
Mogami vs Coinbase Comparison
Category Dimension Mogami Java Stack Coinbase x402 Java Stack
Java first: SDKs, Spring starter, facilitator and tooling all Multi-language protocol implementation: Java is one of
Focus centered around Java/Spring projects. several language directories Go, Python, TS, Java).
Ecosystem
Overview Vendor lock-in risk Tighter coupling to Mogamiʼs starter and facilitator Closer to the protocol originator
Best fit scenarios Fits to all-Java, Spring Boot-centric stack Fits to align with Coinbase/CDP
Spring Boot Native Spring Boot starter with auto-configuration and Plain servlet Filter; integrated into Boot via
integration annotations. FilterRegistrationBean and manual config.
Configuration style Mix of [Link] and annotation (e.g., Central PaymentFilter: paths/prices configured via a price
X402PayUSDC) attributes (amount, asset, network, table Map<Path,Price>).Manual Bean config pulling values
timeout). from [Link] via
Merchant-side Value/ConfigurationProperties.
Hides most protocol details behind annotations and Very close to raw x402 spec: you see
Protocol exposure starter abstractions. PaymentRequirements, XPAYMENT, verify/settle flow.
Flexibility / Less boilerplate, but more opinionated; customization More boilerplate, but highly transparent and extensible;
extensibility often via annotation parameters or starter hooks. easy to fork/wrap PaymentFilter for custom behavior.
Mogami vs Coinbase Comparison
Category Dimension Mogami Java Stack Coinbase x402 Java Stack
Java buyer/client Mogami Java Client SDK for agents, bots, and Java No official Java buyer SDK; buyers are expected to use
SDK services calling x402 APIs. Node or Python helper packages or custom Java code.
Supported buyer Java first-class; can integrate with Spring Official helper libraries are for [Link] and Python; Java
Buyer-side
languages WebClient/RestTemplate as a service bean. must use sidecar or implement signing manually.
(client)
Effort to generate Low: SDK encapsulates 402 parsing, payment payload Medium–high: you must parse 402 JSON, implement
XPAYMENT in Java building, signing, and header encoding. EIP3009/EIP712 signing for USDC, and base64 the
payload yourself.
Protocol compatibility Implements x402 facilitator endpoints (/verify, /settle, Implements the canonical facilitator API used in Coinbase
/supported); can interoperate with other x402 docs; interoperable with any spec-compliant client/server.
components.
Facilitator
Coinbase-hosted facilitator; public [Link] facilitator
Operational model Self-host the facilitator, managed hosting. usable for testnets.
Key Takeaways
● For Java/Spring Boot developers, x402 is not just a theory.
● Mogami , an open-source Java-first platform, fills a gap in the agentic
commerce landscape.
● With just one annotation, you can require stablecoin payments before
granting access to your services - no accounts, no subscriptions, no
friction. It handles payment verification, expiration, and signatures
seamlessly, so you can focus on your business logic.
21
Let's Rock
Together!