Payment Adapters

Integrate x402 payments with PEAC Protocol. Add cryptographic payment verification to any HTTP response.

Adapter Status

Stable

Production-ready with comprehensive testing and documentation

Preview

Beta functionality with active development and testing

Experimental

Early-stage development with potential breaking changes

x402

Stable

HTTP 402 payment adapter for web-native settlement with cryptographic verification

Quick Example

// 1. Client receives 402 Payment Required
fetch('/api/premium-content')
  .then(res => {
    if (res.status === 402) {
      const paymentUrl = res.headers.get('Location')
      // Redirect to x402 payment flow
      window.location.href = paymentUrl
    }
  })

// 2. After payment, retry with receipt
fetch('/api/premium-content', {
  headers: { 'PEAC-Receipt': paymentReceipt }
})
  .then(res => res.json())
  .then(data => console.log('Content received'))

Setup Steps

  1. 1Install x402 payment processor SDK
  2. 2Configure payment endpoints in your API
  3. 3Set up receipt verification middleware
  4. 4Test payment flow in sandbox environment
  5. 5Deploy with production x402 provider

Integration Guide

Server-Side Setup

// Express middleware for x402 payment verification
import { verifyReceipt } from '@peac/core'

app.use('/api/premium', async (req, res, next) => {
  const receipt = req.header('PEAC-Receipt')

  if (!receipt) {
    return res.status(402).json({
      type: 'payment-required',
      payment_url: 'https://x402.example.com/pay',
      amount: '0.01',
      currency: 'USD'
    })
  }

  try {
    const claims = await verifyReceipt(receipt)
    if (!claims.payment?.scheme === 'x402') {
      throw new Error('Invalid payment scheme')
    }
    req.paymentClaims = claims
    next()
  } catch (error) {
    return res.status(402).json({
      error: 'invalid_payment',
      message: error.message
    })
  }
})

Client-Side Integration

// Client payment flow handler
async function fetchWithPayment(url, options = {}) {
  let response = await fetch(url, options)

  if (response.status === 402) {
    const paymentInfo = await response.json()

    // Handle x402 payment
    const paymentResponse = await fetch(paymentInfo.payment_url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        amount: paymentInfo.amount,
        currency: paymentInfo.currency,
        return_url: window.location.href
      })
    })

    const { receipt } = await paymentResponse.json()

    // Retry with payment receipt
    response = await fetch(url, {
      ...options,
      headers: {
        ...options.headers,
        'PEAC-Receipt': receipt
      }
    })
  }

  return response
}

Next Steps

Try x402 Integration

Follow our step-by-step guide to add payments

Quickstart Guide →

Test Your Setup

Verify payment receipts in browser

Receipt Playground →

API Documentation

Complete field reference and examples

API Reference →