Skip to main content

Overview

ChaosChain SDK supports 5 W3C-compliant payment methods for comprehensive payment processing. From traditional cards to crypto payments, handle all payment types with a unified API.

Live Crypto Payments

A2A-x402 with real USDC transfers on Base Sepolia

Traditional Methods

Cards, Google Pay, Apple Pay, PayPal with real API integrations

Supported Payment Methods

βœ… LIVE & WORKING (Out-of-the-Box)

MethodW3C IdentifierStatusSettlement
A2A-x402 Cryptohttps://a2a.org/x402βœ… LIVEReal USDC Transfers on Base Sepolia

πŸ”§ REAL API INTEGRATIONS (Add Your Credentials)

MethodW3C IdentifierStatusWhat You Need
Basic Cardsbasic-cardβœ… REAL Stripe APIAdd STRIPE_SECRET_KEY
PayPalhttps://paypal.comβœ… REAL PayPal APIAdd PAYPAL_CLIENT_ID + PAYPAL_CLIENT_SECRET
Google Payhttps://google.com/payβœ… REAL Token ValidationAdd GOOGLE_PAY_MERCHANT_ID
Apple Payhttps://apple.com/apple-payβœ… REAL Token ValidationAdd APPLE_PAY_MERCHANT_ID

A2A-x402 Crypto Payments

The A2A-x402 protocol enables real USDC transfers between agents with automatic protocol fees.

Features

  • βœ… Real USDC Transfers on Base Sepolia
  • βœ… Automatic Protocol Fees (2.5% to ChaosChain treasury)
  • βœ… Multi-Network Support (Base, Ethereum, Optimism Sepolia)
  • βœ… Instant Settlement with transaction proofs

Usage Example

# Create A2A-x402 payment request
payment_request = sdk.create_x402_payment_request(
    cart_id="service_001",
    total_amount=10.0,
    currency="USDC",
    items=[
        {"name": "AI Analysis Service", "price": 8.0},
        {"name": "Data Processing", "price": 2.0}
    ],
    settlement_address=sdk.wallet_address  # Optional, defaults to agent wallet
)

print(f"πŸ’° Payment Request ID: {payment_request['id']}")
print(f"🏦 Settlement Address: {payment_request['settlement_address']}")

Payment Flow

1

Create Request

Agent creates A2A-x402 payment request with items and total amount
2

Generate Settlement

SDK generates settlement address and calculates protocol fees
3

Execute Transfer

USDC is transferred from payer to settlement address
4

Fee Collection

Protocol fee (2.5%) is automatically sent to ChaosChain treasury

Traditional Payment Methods

All traditional payment methods use real API integrations with production payment processors.

Basic Card Payments (Stripe)

Process credit and debit cards through Stripe’s API:
import os

# Add your Stripe credentials
os.environ['STRIPE_SECRET_KEY'] = 'sk_live_your_stripe_secret_key'
os.environ['STRIPE_PUBLISHABLE_KEY'] = 'pk_live_your_stripe_publishable_key'

Google Pay Integration

Process Google Pay payments with token validation:
import os

# Add your Google Pay merchant ID
os.environ['GOOGLE_PAY_MERCHANT_ID'] = 'merchant.your-domain.com'
os.environ['GOOGLE_PAY_ENVIRONMENT'] = 'PRODUCTION'  # or 'TEST'

Apple Pay Integration

Process Apple Pay payments with certificate validation:
import os

# Add your Apple Pay credentials
os.environ['APPLE_PAY_MERCHANT_ID'] = 'merchant.your-domain.com'
os.environ['APPLE_PAY_CERTIFICATE_PATH'] = '/path/to/apple-pay-cert.pem'

PayPal Integration

Process PayPal payments through their REST API:
import os

# Add your PayPal credentials
os.environ['PAYPAL_CLIENT_ID'] = 'your_paypal_client_id'
os.environ['PAYPAL_CLIENT_SECRET'] = 'your_paypal_client_secret'
os.environ['PAYPAL_ENVIRONMENT'] = 'live'  # or 'sandbox'

Multi-Payment Example

Handle multiple payment methods in a single application:
multi_payment_agent.py
import os
from chaoschain_sdk import ChaosChainAgentSDK

# Setup environment variables for all payment methods
os.environ.update({
    'BASE_SEPOLIA_RPC_URL': 'https://sepolia.base.org',
    'STRIPE_SECRET_KEY': 'sk_live_your_stripe_key',
    'GOOGLE_PAY_MERCHANT_ID': 'merchant.your-domain.com',
    'APPLE_PAY_MERCHANT_ID': 'merchant.your-domain.com',
    'PAYPAL_CLIENT_ID': 'your_paypal_client_id',
    'PAYPAL_CLIENT_SECRET': 'your_paypal_client_secret'
})

# Initialize SDK with all payment methods
sdk = ChaosChainAgentSDK(
    agent_name="PaymentAgent",
    agent_domain="payments.example.com",
    agent_role="server",
    network="base-sepolia",
    enable_payments=True
)

# Get all supported payment methods
methods = sdk.get_supported_payment_methods()
print(f"πŸ’³ Supported Methods: {methods}")

# Process different payment types based on user preference
def process_payment(method: str, amount: float, payment_data: dict):
    if method == "https://a2a.org/x402":
        # Crypto payment
        payment_request = sdk.create_x402_payment_request(
            cart_id=f"order_{int(time.time())}",
            total_amount=amount,
            currency="USDC",
            items=[{"name": "Service", "price": amount}]
        )
        return sdk.execute_x402_crypto_payment(
            payment_request=payment_request,
            payer_agent="ClientAgent"
        )
    else:
        # Traditional payment
        return sdk.execute_traditional_payment(
            payment_method=method,
            amount=amount,
            currency="USD",
            payment_data=payment_data
        )

# Example usage
crypto_result = process_payment(
    "https://a2a.org/x402", 
    10.0, 
    {}
)

card_result = process_payment(
    "basic-card",
    25.99,
    {
        "cardNumber": "4111111111111111",
        "cardType": "visa",
        "expiryMonth": "12",
        "expiryYear": "2025",
        "cvv": "123"
    }
)

print(f"πŸš€ Crypto: {crypto_result['status']}")
print(f"πŸ’³ Card: {card_result['status']}")

Payment Configuration

Environment Variables

Set up your payment processor credentials:
.env
# Network Configuration
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org

# Stripe (for basic-card payments)
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_live_your_stripe_publishable_key

# Google Pay
GOOGLE_PAY_MERCHANT_ID=merchant.your-domain.com
GOOGLE_PAY_ENVIRONMENT=PRODUCTION

# Apple Pay
APPLE_PAY_MERCHANT_ID=merchant.your-domain.com
APPLE_PAY_CERTIFICATE_PATH=/path/to/apple-pay-cert.pem

# PayPal
PAYPAL_CLIENT_ID=your_paypal_client_id
PAYPAL_CLIENT_SECRET=your_paypal_client_secret
PAYPAL_ENVIRONMENT=live

Demo Mode Fallback

If credentials aren’t provided, the SDK automatically falls back to demo mode:
# Without credentials - uses demo mode
sdk = ChaosChainAgentSDK(
    agent_name="DemoAgent",
    agent_domain="demo.example.com",
    agent_role="server"
)

# This will work in demo mode
demo_result = sdk.execute_traditional_payment(
    payment_method="basic-card",
    amount=10.0,
    currency="USD",
    payment_data={"demo": True}
)

print(f"🎭 Demo Payment: {demo_result['status']}")
# Output: Demo Payment: demo_success

Protocol Fees

ChaosChain automatically collects protocol fees on crypto payments:
  • Fee Rate: 2.5% of transaction amount
  • Collection: Automatic on A2A-x402 payments
  • Destination: ChaosChain treasury address
  • Traditional Payments: No protocol fees (handled by payment processors)

Fee Calculation Example

# For a $10 USDC payment:
total_amount = 10.0
protocol_fee = total_amount * 0.025  # 2.5%
agent_receives = total_amount - protocol_fee

print(f"πŸ’° Total: ${total_amount} USDC")
print(f"πŸ›οΈ Protocol Fee: ${protocol_fee} USDC")
print(f"πŸ‘€ Agent Receives: ${agent_receives} USDC")

# Output:
# πŸ’° Total: $10.0 USDC
# πŸ›οΈ Protocol Fee: $0.25 USDC  
# πŸ‘€ Agent Receives: $9.75 USDC

Error Handling

Handle payment errors gracefully:
from chaoschain_sdk.exceptions import PaymentError

try:
    result = sdk.execute_traditional_payment(
        payment_method="basic-card",
        amount=100.0,
        currency="USD",
        payment_data={"invalid": "data"}
    )
except PaymentError as e:
    print(f"πŸ’₯ Payment failed: {e}")
    # Handle specific error cases
    if "insufficient funds" in str(e).lower():
        print("πŸ’³ Card declined - insufficient funds")
    elif "invalid card" in str(e).lower():
        print("🚫 Invalid card details")
    else:
        print("⚠️ General payment error")

Best Practices

  • Never log payment credentials or sensitive data
  • Use HTTPS for all payment communications
  • Validate payment data before processing
  • Store credentials in environment variables, not code
  • Implement retries for network failures
  • Provide clear feedback to users on payment status
  • Log errors for debugging (without sensitive data)
  • Handle timeouts gracefully
  • Show supported methods to users
  • Provide payment status updates
  • Handle demo mode transparently
  • Offer multiple options for payment flexibility

Next Steps