Skip to content

feat: x402 server-side middleware for automatic 402 payment handling#19

Open
abhicris wants to merge 1 commit intomainfrom
feat/x402-middleware
Open

feat: x402 server-side middleware for automatic 402 payment handling#19
abhicris wants to merge 1 commit intomainfrom
feat/x402-middleware

Conversation

@abhicris
Copy link
Copy Markdown
Contributor

Summary

  • Adds X402Middleware that intercepts HTTP 402 responses and automatically pays on-chain
  • Supports exact (direct transfer) and escrow payment schemes via PaymentClient
  • Policy enforcement: max payment cap, recipient allowlist, gas budget integration
  • Payment proof sent via X-Payment-Proof header on retry
  • 15 tests covering offer parsing, validation, payment execution, spend tracking

Closes #16

Test plan

  • Unit tests pass (pytest)
  • Integration test with a mock 402 server
  • End-to-end with real USDC on Base Sepolia

🤖 Generated with Claude Code

Adds X402Middleware that intercepts HTTP 402 responses and automatically
pays on-chain via PaymentClient, then retries with X-Payment-Proof header.

- Supports exact (direct transfer) and escrow payment schemes
- Policy enforcement: max payment cap, recipient allowlist, gas budget
- Payment history tracking and spend summaries
- 15 tests covering offer parsing, validation, payment execution

Closes #16

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x402 server-side middleware: respond to 402 with switchboard-managed payments

1 participant