Payments API (x402)
API endpoints for x402 payment protocol integration, including payment requests, verification, and settlement. Base Path:/api (x402 endpoints integrated in main routes)Code Reference:
app/services/x402_payment_service.py, app/api/routes.py (x402 endpoints)
Payment Request
Request Payment (HTTP 402)
Settle a trade with x402 payment. Returns HTTP 402 if payment required. Request Body (Optional):app/api/routes.py (settle_trade endpoint)
Payment Verification
Verify Payment
The x402 payment service automatically verifies payments on the blockchain:- Extract payment details from payload
- Query blockchain for transaction
- Verify transaction details match
- Confirm transaction status
- Return verification result
app/services/x402_payment_service.py (verify_payment)
Payment Types
Trade Settlement
Payment for executed trades:- Payment Type:
trade_settlement - Amount: Trade settlement amount
- Currency: Trade currency (USD)
- Network: Base network
- Token: USDC
Loan Disbursement
Initial loan funding:- Payment Type:
loan_disbursement - Amount: Loan principal amount
- Currency: Loan currency
- Network: Base network
- Token: USDC
Interest Payment
Periodic interest distributions:- Payment Type:
interest - Amount: Interest amount
- Currency: Loan currency
- Network: Base network
- Token: USDC
Penalty Payment
Late payment fees:- Payment Type:
penalty - Amount: Penalty amount
- Currency: Loan currency
- Network: Base network
- Token: USDC
Notarization Fee
Payment for blockchain notarization:- Payment Type:
notarization_fee - Amount: Notarization fee (default: $50.00)
- Currency: USD
- Network: Base network
- Token: USDC
app/services/x402_payment_service.py (payment_type parameter)
CDM Integration
All payments generate CDM-compliant payment events:app/models/cdm_payment.py (PaymentEvent model)
Error Responses
402 Payment Required
Payment payload not provided or invalid. Returns payment request structure.400 Bad Request
Invalid payment payload or missing required fields.401 Unauthorized
Invalid signature or wallet address verification failed.500 Internal Server Error
Payment verification failed or blockchain error.Configuration
Environment Variables
Enable x402 payment processing. Default:
truex402 facilitator service URL. Default:
https://facilitator.x402.orgBlockchain network. Default:
"base"Token symbol. Default:
"USDC"Base network RPC URL
Frontend Integration
useX402Payment Hook
Location:client/src/hooks/useX402Payment.ts
React hook for x402 payment processing:
client/src/hooks/useX402Payment.ts
Additional Resources
Last Updated: 2026-01-14
Code Reference:
app/services/x402_payment_service.py, app/api/routes.py