Client Integration
Choosing a Client
Client
Best For
Peer Deps
Axios Integration
Installation
pnpm add @stripe402/client-axios axiosSetup
import axios from 'axios'
import { createStripe402Axios } from '@stripe402/client-axios'
const client = createStripe402Axios(
axios.create({ baseURL: 'https://api.example.com' }),
{
// Optional: restore a saved client ID from a previous session
clientId: loadSavedClientId() ?? undefined,
onPaymentRequired: async (requirements) => {
// requirements contains: amount, currency, minTopUp, publishableKey, description
console.log(`Payment required: ${requirements.amount} units`)
// Get a PaymentMethod ID (see "Getting a PaymentMethod" below)
const paymentMethodId = await getPaymentMethod(requirements)
if (!paymentMethodId) return null // User declined
return {
paymentMethodId,
topUpAmount: requirements.minTopUp, // Or let the user choose
}
},
}
)
// Use like a normal Axios instance
const response = await client.get('/api/weather')
console.log(response.data)How It Works
Fetch Integration
Installation
Setup
Key Difference from Axios
Getting a PaymentMethod ID
Headless / Node.js Client
Browser (Stripe.js)
Complete Agent Example
Persisting Client IDs
Custom Top-Up Amounts
Last updated