{"_id":"@100pay-hq/pay402-axios","_rev":"2-eb1b6abb35ddb78e240a5bfc44ead15b","name":"@100pay-hq/pay402-axios","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@100pay-hq/pay402-axios","version":"1.0.0","keywords":["axios","pay402","x402","ai-agents","ai-wallet","payment","interceptor","wallet","crypto","100pay"],"author":{"name":"100Pay"},"license":"MIT","_id":"@100pay-hq/pay402-axios@1.0.0","maintainers":[{"name":"brainyjosh","email":"joshuabrendan5@gmail.com"},{"name":"miracleio","email":"miracleficient@gmail.com"}],"homepage":"https://github.com/shop100global","bugs":{"url":"https://github.com/shop100global/pay402-axios/issues"},"dist":{"shasum":"0eae4cea770eb7de064f437d7dd6a546b2bda1f6","tarball":"https://registry.npmjs.org/@100pay-hq/pay402-axios/-/pay402-axios-1.0.0.tgz","fileCount":10,"integrity":"sha512-zg2NJtd7wLdaXxbSObYlWwX7A5xSaD0Zo8IL36yYDYwlq0hA3xo5dU3V4R0+0Zx5Ixdm+gkfAsWslLPFZhs12A==","signatures":[{"sig":"MEUCIQCovabIAQZbbX4Fj2RnH7z/inHkdvQ+Ir7y7DvPXHGQPAIgQ5V2EQPeXvl8EoFRO1vbUT355ljOUNM6nbJO2dBr+lI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24332},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"fbc8c21c87472dbe3f79f8076ea9bc83aaaed1d7","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc","prepare":"npm run build"},"_npmUser":{"name":"brainyjosh","email":"joshuabrendan5@gmail.com"},"repository":{"url":"git+https://github.com/shop100global/pay402-axios.git","type":"git"},"_npmVersion":"11.6.2","description":"A powerful Axios interceptor for handling Pay402 payment requests with wallet integration.","directories":{},"_nodeVersion":"25.1.0","dependencies":{"viem":"^2.39.3","axios":"^1.13.2","ts-node":"^10.9.2","typescript":"^5.9.3","x402-axios":"^0.7.0","@types/node":"^24.10.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/pay402-axios_1.0.0_1763616952509_0.05887301122043187","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@100pay-hq/pay402-axios","version":"1.0.1","description":"A powerful Axios interceptor for handling Pay402 payment requests with wallet integration.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"echo \"Error: no test specified\" && exit 1","prepare":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/shop100global/pay402-axios.git"},"keywords":["axios","pay402","x402","ai-agents","ai-wallet","payment","interceptor","wallet","crypto","100pay"],"author":{"name":"100Pay"},"license":"MIT","homepage":"https://github.com/shop100global","publishConfig":{"access":"public"},"dependencies":{"@types/node":"^24.10.1","axios":"^1.13.2","ts-node":"^10.9.2","typescript":"^5.9.3","viem":"^2.39.3","x402-axios":"^0.7.0"},"gitHead":"485a3582f92e59947c220f8af4f430311776adb8","_id":"@100pay-hq/pay402-axios@1.0.1","bugs":{"url":"https://github.com/shop100global/pay402-axios/issues"},"_nodeVersion":"25.1.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-9XoXKmKiE33ZNMc+uCgLdsT+fpqaZJB6x4sgBkRdid/lYfnlSDTi7j3a4XlZFZ33GF68WPLYZPdbrbPoNRkbZw==","shasum":"11a417914c5a83b9904af99d32138fda2692c17d","tarball":"https://registry.npmjs.org/@100pay-hq/pay402-axios/-/pay402-axios-1.0.1.tgz","fileCount":10,"unpackedSize":24436,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCUTmEpbPEmeMT7JvrPASpwosYt3kFWd8LJ1rz1mUIZEgIhANl3NA7MeyjNWWVlI8tD7x8ZkQmYZvnd92dK3uBQA8ui"}]},"_npmUser":{"name":"brainyjosh","email":"joshuabrendan5@gmail.com"},"directories":{},"maintainers":[{"name":"brainyjosh","email":"joshuabrendan5@gmail.com"},{"name":"miracleio","email":"miracleficient@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pay402-axios_1.0.1_1763617546102_0.24474746794068536"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-20T05:35:52.389Z","modified":"2025-11-20T05:45:46.509Z","1.0.0":"2025-11-20T05:35:52.696Z","1.0.1":"2025-11-20T05:45:46.311Z"},"bugs":{"url":"https://github.com/shop100global/pay402-axios/issues"},"author":{"name":"100Pay"},"license":"MIT","homepage":"https://github.com/shop100global","keywords":["axios","pay402","x402","ai-agents","ai-wallet","payment","interceptor","wallet","crypto","100pay"],"repository":{"type":"git","url":"git+https://github.com/shop100global/pay402-axios.git"},"description":"A powerful Axios interceptor for handling Pay402 payment requests with wallet integration.","maintainers":[{"name":"brainyjosh","email":"joshuabrendan5@gmail.com"},{"name":"miracleio","email":"miracleficient@gmail.com"}],"readme":"# pay402-axios\n\nA powerful Axios interceptor for handling **[Pay402](https://402.finance)** payment requests. It seamlessly integrates with your wallet to handle `402 Payment Required` responses, supporting both custom Pay402 flows and standard [x402](https://github.com/x402/x402-axios) interactions.\n\n## Features\n\n*   **Smart Interception**: Automatically detects `402` responses.\n*   **Dual Mode**:\n    *   **With Pay402**: Handles specialized \"gas-free\" transfers with pay402 and built in support for multiple payment options including USDT, USDC, SOL, XRP, BNB, etc.\n    *   **With x402**: Falls back to `x402-axios` for standard payment requests.\n*   **Flexible Payments**: Provides multiple payment options and lets you choose your preferred currency.\n*   **Auto-Retry**: Automatically signs the transaction and retries the original request with the proof of payment.\n\n## Installation\n\n```bash\nnpm install @100pay-hq/pay402-axios viem axios @100pay-hq/100pay.js\n```\n\n> **Note**: `viem` is required for the wallet client integration.\n\n## Usage\n\n### 1. Setup your Wallet Client\n\nFirst, create a wallet client using `viem`. This is used to sign the payment transactions.\n\n```typescript\nimport { createWalletClient, http } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { baseSepolia } from 'viem/chains';\n\nconst account = privateKeyToAccount(\"0xYourPrivateKey\");\nconst walletClient = createWalletClient({\n  account,\n  transport: http(),\n  chain: baseSepolia,\n});\n```\n\n### 2. Configure the Interceptor\n\nAttach the `withPay402Interceptor` to your Axios instance. You need to provide a callback function to handle the transaction signing logic.\n\n```typescript\nimport axios from 'axios';\nimport { withPay402Interceptor, PaymentOption } from '@100pay-hq/pay402-axios';\nimport { Pay100 } from '@100pay-hq/100pay.js'; // Correct import\n\nconst client = axios.create({\n  baseURL: 'https://api.example.com'\n});\n\n// Initialize 100Pay Client\nconst _100PayClient = new Pay100({\n  publicKey: \"your_public_key\",\n  secretKey: \"your_secret_key\", // Required for server-side operations\n});\n\n// Callback to handle the actual payment\nconst signTransaction = async (pricing: PaymentOption[], resource: string) => {\n  console.log('Payment required for resource:', resource);\n  console.log('Available payment options:', pricing);\n  \n  // Example: Prefer 'PAY' token\n  // Supported currencies: USDC, USDT, SOL, XRP, BNB, etc.\n  const preferredOption = pricing.find(p => p.currency === 'PAY');\n\n  if (!preferredOption) {\n    throw new Error('No suitable payment option found');\n  }\n\n  console.log(`Paying ${preferredOption.amount} ${preferredOption.currency} to ${preferredOption.payTo}`);\n\n  // Execute an asset transfer using 100Pay.js\n  // See docs: https://www.npmjs.com/package/@100pay-hq/100pay.js#asset-transfers\n  const transfer = await _100PayClient.transfer.executeTransfer({\n    amount: Number(preferredOption.amount),\n    symbol: \"PAY\", // Use 'PAY' as requested\n    to: preferredOption.payTo,\n    transferType: \"internal\", // for onchain transfer, use \"external\" (standard gas fee applies - not recommended for micro payments)\n    note: `Payment for ${resource}`,\n  });\n  \n  // Return the transaction hash as proof of payment\n  return transfer.transactionHash;\n};\n\n// Attach the interceptor\nwithPay402Interceptor(client, signTransaction, walletClient);\n```\n\n### 3. Make Requests\n\nNow, just use Axios as normal. If an endpoint requires payment, the interceptor will handle the flow automatically.\n\n```typescript\ntry {\n  const response = await client.post('/paid-service', { data: 'foo' });\n  console.log('Success:', response.data);\n} catch (error) {\n  console.error('Payment failed:', error);\n}\n```\n\n## API Reference\n\n### `withPay402Interceptor(axiosInstance, signTransaction, walletClient)`\n\n*   `axiosInstance`: The Axios instance to wrap.\n*   `signTransaction`: A callback function that receives available payment options and the resource URL, returning a Promise resolving to the transaction ID (hash).\n*   `walletClient`: A `viem` Wallet Client used for the fallback `x402-axios` functionality.\n\n### `SignTransactionCallback`\n\nType: `(pricing: PaymentOption[], resource: string) => Promise<string>`\n\n### `PaymentOption`\n\n```typescript\ninterface PaymentOption {\n  amount: string;   // The amount required (e.g., \"0.066\")\n  currency: string; // The currency symbol or name (e.g., \"PAY\", \"USD Coin\")\n  payTo: string;    // The destination address\n}\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}