{"_id":"@0xinfrax/payments","_rev":"8-f96d9aed5a364e9be470aebaa35e36c5","name":"@0xinfrax/payments","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"@0xinfrax/payments","version":"0.1.0","keywords":["infrax","payments","x402","payment-channel","mpp","a2a","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.1.0","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"fbb9b390c092b0283e23d8cedda5633eb8292671","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.1.0.tgz","fileCount":39,"integrity":"sha512-nzA/L7COc6oIKsgFklw5Rz+OmiCfGC2QrtKl5HZQqg8WVmJ4Smcan49byYx4gDcQM2fIGhRRqDsnmX70HiswhQ==","signatures":[{"sig":"MEQCIB40eUfU53CsWUu3CoRow8YToU8hPq9piY4438ZhTMkJAiB8RJa5szWpASPadF2YyomCCZgZ5FThMW+c7GXqCb+AkQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":181292},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"da48e4240d4ebfca8f74512a174e81f0da680ce3","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"10.8.2","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / a2a). Embedded service or standalone library.","directories":{},"_nodeVersion":"20.20.2","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.1.0_1786216151794_0.2292372612165443","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@0xinfrax/payments","version":"0.1.1","keywords":["infrax","payments","x402","payment-channel","mpp","a2a","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.1.1","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"b9245fc8d2a1a4b0a22ab75c168c4594f39d3183","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.1.1.tgz","fileCount":41,"integrity":"sha512-Q5RZLecb3UWLoyv1G5hPbIGn6SlkEKnDZ+SYHb00yuDgwj75Q9ymI3L3aTgtwEZArbs9/TZbVzXbAz21tzXFew==","signatures":[{"sig":"MEUCIQDSRc0/hXoUpSjs6T7vn5BeleUDhgC5AqXTpIpDAw00mAIgMtHPmGMfYL8Jio+UR6RhBUnZLsV/uvCjvBiXcMtdccU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":187783},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"ac5b6e62120194b2ab21aff37a191a844a40ea1c","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"10.8.2","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / a2a). Embedded service or standalone library.","directories":{},"_nodeVersion":"20.20.2","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.1.1_1786316691200_0.05516247054931389","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@0xinfrax/payments","version":"0.1.2","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.1.2","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"98045dcaac7d6938fceb48452a591f7799c3a60a","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.1.2.tgz","fileCount":40,"integrity":"sha512-6I3GZ+CLr738BJISW2H9acnCm7TrlWmb81SDfze0KwRnZxHwkCfY6wj77JCndyJIQNHJfIEiSUTo5j7FtTa6Qw==","signatures":[{"sig":"MEQCIHAcHFwQNTFXS/VEOt0bwTXvQIY1nfderLiOx9G/OC1xAiAyYQmRfLzNduwwtxUQMUeHwa1u3VvsCeueZuaAG7h8xw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":165131},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"bd8711833b84826b7458e9516247adeeb9d461fc","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"10.8.2","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"_nodeVersion":"20.20.2","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.1.2_1786319947343_0.025682479152577598","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@0xinfrax/payments","version":"0.1.3","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.1.3","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"5a259644663c351204033fd10a9e3e9f6e46ce9e","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.1.3.tgz","fileCount":44,"integrity":"sha512-X6v/IC08P2w/FzZ89jLdpknnVH+aVylwsp7MidJgF4QNOGrEsK+vbosaPHH4Z/JAIBhW90DZ3HVYga73xCeeqA==","signatures":[{"sig":"MEUCIGltwDnGpygPp1i3Xvo9N2/ZPpANMpGAiRYRNILneAayAiEAzXug5vAlZAbUim/nYH3DW61zWcFAJVsIT8oV59qx524=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":241653},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"f25f84d4e987bc1b78d38c05e37028b033db6678","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"10.8.2","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"_nodeVersion":"20.20.2","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.1.3_1786374809894_0.9663913587504132","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@0xinfrax/payments","version":"0.1.4","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.1.4","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"31a3445a2b3f6481106bf37fb0360b9bde4f3c42","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.1.4.tgz","fileCount":45,"integrity":"sha512-7nvmlpNZD8drZSiiwPTi1/nReftGT4yP5CEUDjqftJzItreYG7WDrzc/OZtisXJ33rIMewjawKcrjS9jLZ1S8w==","signatures":[{"sig":"MEUCIQCpN6rrnL7DW8+slvgyd0hVNRnB8Gkka8cmOztKC9UfGAIgIpWGMXEysI4zV4/kPXm6IrxKAxfBdlSMO/ODHB/sV58=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":275229},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"a7c3c83051bb35b35fb4b896fa5a11c4ddc09138","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"11.17.0","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"_nodeVersion":"24.19.0","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.1.4_1787007456062_0.3920332055347746","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@0xinfrax/payments","version":"0.2.0","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.2.0","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"8e3cac28b2edf87456f66b97f4db62cb55610122","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.2.0.tgz","fileCount":47,"integrity":"sha512-tW4+euPL5Y/ole/f/wR+9U/1COja84wtmVRNYX28VTHi2TX3l3/3MIEzTbHG/A/xyg5Kx1oyYOsa2j+VZ7nQQg==","signatures":[{"sig":"MEQCIH/39pr7tITnTAgjBQFShnUdZOtXGIkUroGJBwzRlJkFAiBxZE/R+ACbOWvWGrGzpr0yWWsGAVJzupJbw3Apcenuug==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDvD+SjLSvlS4MffP8EfCZ+jqCow+2XtEqEC0W3ztH1JQIhANOousgIhS+A4+8TwQUMqZYCOHsiKGaFAFPVB3uEDNzJ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":296920},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"2a3c91d4aff389327770aa2154f906cb9c6c9e21","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit","test:anvil":"tsx scripts/anvil-multicoin.ts"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"11.17.0","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"_nodeVersion":"24.19.0","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.2.0_1789603677540_0.16438584966153957","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@0xinfrax/payments","version":"0.2.1","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","_id":"@0xinfrax/payments@0.2.1","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"6ef0ca4ba2c23fad099a687cb5dda2ee06930de5","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.2.1.tgz","fileCount":47,"integrity":"sha512-i5AAFF4Ekb7vHIRsuLyLOdJK2UFr58s9kdDszH/VELFJcOGUrfntH2dVCjn8OIa766HUEPKcCwEmx1o8wabjgA==","signatures":[{"sig":"MEUCIBb/V9g9ohQhk/J09sfecPMuWlFGp99dEjW+q8JyfLI1AiEAzA6jjMHCc5I48a0Wei8Y3VYU+sDrhVrxLEVPEe29Ra4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDnQjduKFfwLluHMs2818qCxjyo+qwmBIiDJ7IntGAHXAIgUL2QUC9sd2PxX7HBAM3P5qFc4QNMfuYpq7dm9QBf0As=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":316336},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"0daabef4cd70db2ddf5fac6df33cc5cce8862094","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit","test:anvil":"tsx scripts/anvil-multicoin.ts"},"_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"11.17.0","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"_nodeVersion":"24.19.0","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/payments_0.2.1_1789687316099_0.1293068894972218","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"_id":"@0xinfrax/payments@0.2.2","bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"dist":{"shasum":"54900f53e127ef924f47b371be0089fa265ff97c","tarball":"https://registry.npmjs.org/@0xinfrax/payments/-/payments-0.2.2.tgz","fileCount":47,"integrity":"sha512-eWFB1ZZdIFiu3n50wZIABqFWBsPDlV7DmU7rBLT1m555+xtyesFuO/x2dTKJGXTjhmdZEtLX7RTiGvudkANylA==","signatures":[{"sig":"MEUCIFLB+SH13wwbISKYj+RtkMa8aEe7gZ/AsZm5zJcgnPo2AiEA0illhXAwwlatc2OIDmwWuHeTj/7TfF+sMjV1Yn5Fqak=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICNhXiniL3ygxnWmKMwjBjWrL1ksjrrIcK5SQzj97+sDAiBoLVq8F0ILWr5BsNFkgWH+Iv0+8YCiVwIyGmVe/1kWmQ=="}],"unpackedSize":316653},"main":"dist/index.js","name":"@0xinfrax/payments","types":"dist/index.d.ts","author":{"url":"sftgroup","name":"InfraX"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./db/*":"./db/*","./router":{"types":"./dist/router.d.ts","import":"./dist/router.js","require":"./dist/router.js"},"./package.json":"./package.json"},"gitHead":"5e6e07f812d6b80d2ef2c0c3b8fe656bd7e98f6e","license":"MIT","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit","test:anvil":"tsx scripts/anvil-multicoin.ts"},"version":"0.2.2","_npmUser":{"name":"stevenwang000x","email":"apply.wang@hotmail.com"},"homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"_npmVersion":"11.17.0","description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","directories":{},"maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"_nodeVersion":"24.19.0","dependencies":{"pg":"^8.13.0","viem":"^2.55.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","cors":"^2.8.5","vitest":"^2.1.9","express":"^4.19.2","@types/pg":"^8.11.10","typescript":"^5.5.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/express":"^4.17.21"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/payments_0.2.2_1789689637101_0.5288790425392627"}}},"time":{"created":"2026-08-08T19:09:11.636Z","modified":"2026-09-18T00:00:37.429Z","0.1.0":"2026-08-08T19:09:11.933Z","0.1.1":"2026-08-09T23:04:51.334Z","0.1.2":"2026-08-09T23:59:07.514Z","0.1.3":"2026-08-10T15:13:30.041Z","0.1.4":"2026-08-17T22:57:36.206Z","0.2.0":"2026-09-17T00:07:57.641Z","0.2.1":"2026-09-17T23:21:56.200Z","0.2.2":"2026-09-18T00:00:37.249Z"},"bugs":{"url":"https://github.com/sftgroup/infraX/issues"},"author":{"url":"sftgroup","name":"InfraX"},"license":"MIT","homepage":"https://github.com/sftgroup/infraX/tree/main/projects/payments","keywords":["infrax","payments","x402","payment-channel","mpp","stablecoin","stripe","web3"],"repository":{"url":"git+https://github.com/sftgroup/infraX.git","type":"git"},"description":"0xinfrax Payments — zero-business-coupling payment engine (chain / Stripe / x402 / MPP / stablecoin). Embedded service or standalone library.","maintainers":[{"name":"stevenwang000x","email":"apply.wang@hotmail.com"}],"readme":"# @0xinfrax/payments\n\n零业务耦合的通用支付引擎（chain / Stripe / x402 / MPP 支付通道 / 稳定币 / a2a / period 订阅周期 / batch 批量收款 / invite 自动收费邀请 / transfer 账本内转账）。\n\n> **维护**：由 **InfraX**（GitHub [sftgroup/infraX](https://github.com/sftgroup/infraX)）团队维护；源码位于仓库 [`projects/payments/`](https://github.com/sftgroup/infraX/tree/main/projects/payments) 目录，npm 包 `@0xinfrax/payments` 由 InfraX 账号发布与维护。集成方可作为独立库使用，但问题的修复与演进统一由 InfraX 负责。\n\n> **集成到独立项目**：完整部署步骤（安装 / 数据库 / 合约 / 代码接入 / 验证 / 生产注意）见 [`DEPLOY.md`](./DEPLOY.md)。\n>\n> **调用方自配收款**：想配置「自己的收款」（自部署 SubscriptionManager / 自己 Stripe 账号 / 自配 x402 钱包 / MPP payee），见 [`CALLER_SETUP.md`](./CALLER_SETUP.md)。\n\n- **嵌入式服务**：作为宿主 Gateway 的内部引擎（AgentX 即此形态的参考实现，见 `gateway/src/services/payments.ts`）\n- **独立库**：可被任意项目依赖，以「调用方自持 store」的形态独立运行\n- **独立服务（微服务形态）**：仓库内置部署入口 [`server.ts`](server.ts)（tsx 直跑）——Express + 统一鉴权（auth-express，Bearer/X-API-Key/X-Service-Key）+ `PgPaymentStore`（`infrax_payments` 独立库，启动自动跑 4 迁移）+ `/health` + `createPaymentsRouter`（挂 `/payments`）；链上读可配 `CHAIN_RPC_READ_KEY` 走 chain-rpc 网关（DC-10）；`WEBHOOK_FORWARD_URL` 时事件出站转发（`createWebhookForwarder`，**MQ-16 起支持逗号分隔多目标**——如 `http://127.0.0.1:9109/api/v2/subscription/payment-callback,http://127.0.0.1:9102/api/v2/data/payment-callback`，每个业务方独立收事件、独立重试，按 reference 幂等对账）。systemd 模板见 `deploy/systemd/infrax-payments.service`（:9132）\n\n核心设计：**模块只懂钱**（方法 / 资产 / 金额 / 凭证）。业务上下文（如 `agentId`、订单号）一律经 `metadata` 透传；持久化走注入的 `PaymentStore` 接缝；宿主业务（订阅注册、发货）只通过 `onWebhookEvent` / `onCredit` 回调接入。模块不解释、不校验、不消费任何业务参数。\n\n依赖仅有 `pg`（账本/凭证）与 `viem`（链上读写）。\n\n---\n\n## 目录\n\n- [依赖配置（迁移到其他项目）](#依赖配置迁移到其他项目)\n- [数据库迁移](#数据库迁移)\n- [快速开始（独立库形态）](#快速开始独立库形态)\n- [调用方自配收款模板](#依赖配置迁移到其他项目)（[`CALLER_SETUP.md`](./CALLER_SETUP.md)）\n- [嵌入式形态（宿主自带 store / 回调）](#嵌入式形态宿主自带-store--回调)\n- [业务上下文透传规则](#业务上下文透传规则)\n- [API 参考](#api-参考)\n- [本地验证](#本地验证)\n- [目录结构](#目录结构)\n- [参考实现：套餐支付（waas）](#参考实现套餐支付waas)\n\n---\n\n## 依赖配置（迁移到其他项目）\n\n### 1. package.json\n\n```jsonc\n{\n  \"dependencies\": {\n    \"@0xinfrax/payments\": \"^0.1.0\" // 公开 npm registry 安装（推荐）；或 file:/git/私有 registry，见下\n    // pg / viem 是模块的传递依赖，npm install 会自动安装，宿主无需显式声明\n  }\n}\n```\n\n> 若宿主自身也要用 `viem` 发交易（链上 / x402 付款），可另行声明自己版本的 `viem`——模块会从自身 `node_modules` 解析，互不冲突。\n\n### 2. 四种安装来源\n\n| 场景 | package.json 写法 |\n| --- | --- |\n| **公开 npm registry（推荐，已发布）** | `\"@0xinfrax/payments\": \"^0.1.0\"`（`npm view @0xinfrax/payments version` → 当前 latest） |\n| Monorepo / 本地开发 | `\"@0xinfrax/payments\": \"file:../payments\"` |\n| Git 仓库（打 tag 固定版本） | `\"@0xinfrax/payments\": \"git+https://github.com/<org>/payments.git#v0.2.0\"` |\n| 私有 npm registry | `\"@0xinfrax/payments\": \"^0.2.0\"`（配合 `.npmrc` 指向 registry） |\n\n### 3. 使用前构建\n\n发布物是 `tsc` 产物（`dist/`）。`file:` 引用前需确保已构建：\n\n```bash\ncd payments && npm install && npm run build\n```\n\n---\n\n## 数据库迁移\n\n模块拥有自己的 `payment_*` 表（8 个迁移文件，随包发布在 `db/migrations/`）：\n\n| 迁移 | 表 | 用途 |\n| --- | --- | --- |\n| `001_payment_intents.sql` | `payment_intents` | 统一支付意图（chain / fiat / x402 / mpp / a2a） |\n| `002_payment_credits.sql` | `payment_credits` / `payment_balances` / `payment_access` | 入账台账、余额、通用访问登记表 |\n| `003_payment_sessions.sql` | `payment_sessions` / `payment_vouchers` | MPP 通道会话 / 凭证 |\n| `004_payment_events.sql` | `payment_events` | 归一化 webhook 事件回放 |\n| `005_payment_authorizations.sql` | `payment_authorizations`（+ `payment_intents.payee`） | period 授权（订阅周期计费） |\n| `006_payment_batches.sql` | `payment_batches` | batch 批量收款（一次 N 个 a2a 意图） |\n| `007_payment_invites.sql` | `payment_invites` | invite 收费邀请（payer/payee/amount/due_at/memo + 状态机） |\n| `008_payment_transfers.sql` | `payment_transfers` | transfer 账本内原子划转（reference 幂等键） |\n\n在**新项目自己的数据库**中执行（不要复用其他项目的表）：\n\n```bash\nfor f in node_modules/@0xinfrax/payments/db/migrations/*.sql; do\n  psql \"$DATABASE_URL\" -f \"$f\"\ndone\n```\n\n通用形态使用 `PgPaymentStore`（读这些表）。如果宿主已有自己的订阅/余额表，可自定义实现 `PaymentStore` 注入（见[嵌入式形态](#嵌入式形态宿主自带-store--回调)），此时可不执行模块迁移。\n\n---\n\n## 快速开始（独立库形态）\n\n```ts\nimport { Pool } from 'pg'\nimport { PaymentsService, PgPaymentStore } from '@0xinfrax/payments'\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL })\n\nconst payments = new PaymentsService({\n  store: new PgPaymentStore(pool),\n\n  // 链上：每个 slot 一条（可读链上套餐价 / 订阅状态）\n  chains: {\n    sepolia: {\n      rpcUrl: process.env.RPC_URL,\n      chainId: 11155111,\n      subscriptionManager: process.env.SUBSCRIPTION_MANAGER, // 部署好的 SubscriptionManager\n    },\n  },\n\n  // 法币：不配则 fiat 轨返回「未配置」（503）\n  stripe: {\n    secretKey: process.env.STRIPE_SECRET_KEY,\n    webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,\n    apiBase: process.env.STRIPE_API_BASE,   // 可选，默认 https://api.stripe.com/v1；本地 mock 用 http://127.0.0.1:8777/v1\n    tokenUsdPrice: 1,                        // 可选，默认 1：native 单价 → 用于套餐自动定价\n  },\n\n  // x402：不配则 verify 返回「未配置」\n  // 顶层 payTo/priceWei/escrow 描述**默认链**（chain）；其它链写在 collectors 里，\n  // 多币写在 stablecoins[]（各币独立定价，不换算）。见 CALLER_SETUP.md §1/§2。\n  x402: {\n    enabled: true,\n    payTo: process.env.X402_PAY_TO,          // 默认链的收款钱包\n    priceWei: process.env.X402_PRICE_WEI,    // 默认链的单次价格\n    chain: 'sepolia',\n    // AX-1/OE-1：Escrow 金库托管（可选）。配置后 verify 自动走 escrow 判定\n    // （解析 InfraXEscrow.deposit() 的 Deposited 事件入账，资金进金库而非 payTo 直收）。\n    // 部署指引见 projects/escrow（InfraXEscrow）与 docs/INFRAX_ESCROW_GUIDE.md。\n    escrow: { address: process.env.X402_ESCROW_ADDRESS },\n    // 按链收款人（可选）：未声明的非默认链不可收款（402/verify → 409 NOT_CONFIGURED）\n    // collectors: { ethereum: { payTo, priceWei, maxAmountWei?, escrow? } },\n    // 稳定币（可多币并存；USDT 无 EIP-3009 → 只能直转入账或 Permit2）\n    // stablecoins: [{ enabled, chain, asset, symbol, decimals, priceWei, domainName? }],\n  },\n\n  // ── 宿主业务只写在这里 ──────────────────────────────────────────────\n  // webhook 事件（Stripe）→ 你的业务：开订阅、发凭证、写订单\n  onWebhookEvent: async (event) => {\n    if (event.type === 'checkout.session.completed') {\n      const [subscriber, resourceId] = String(event.object.client_reference_id ?? '').split('|')\n      await grantAccess(subscriber, resourceId) // 例如写 payment_access 或你自己的表\n    }\n  },\n  // 链上付款验证成功入账后（x402 轨）→ 你的业务\n  onCredit: async (credit) => {\n    await notifyUser(credit.payer, credit.amountWei)\n  },\n})\n```\n\n### 通道的典型用法\n\n```ts\n// ① 链上：用户先在链上调用 SubscriptionManager.subscribe(planId)，然后：\nconst active = await payments.chain.hasActiveSubscription('sepolia', subscriber, agentId)\nconst plan = await payments.chain.getPlan('sepolia', planId) // 定价、套餐详情（含计费周期）\nconst feeBps = await payments.chain.platformFeeBps('sepolia')\n\n// ② 法币：创建 Stripe Checkout Session（可自动定价，period 为计费周期）\nconst checkout = await payments.createPayment({\n  method: 'fiat',\n  subscriber,\n  period: 'month',\n  pricing: { planId },                    // 省略 amountCents → 按链上套餐价换算\n  metadata: { agentId, planId },          // 业务参数原样透传\n  clientReference: `${subscriber}|${agentId}|${planId}`, // 由你构造，webhook 原样回显\n})\n// → { method:'fiat', sessionUrl, sessionId, clientReference, redirect:true }\n\n// ②b 法币一次性支付（0.2.1）：mode:'payment' → Stripe 非 recurring charge\nconst oneOff = await payments.createPayment({\n  method: 'fiat',\n  subscriber,\n  amountCents: 1900,                      // 一次性商品通常直接给价\n  mode: 'payment',                        // 缺省 'subscription'（行为与 0.2.0 完全一致）\n  metadata: { type: 'token_pack' },       // → Stripe metadata[...] + 出站事件\n})\n\n// ③ x402：用户向 payTo 转账后验证入账（幂等）\nconst verified = await payments.verifyPayment(txHash, 'sepolia')\n// → { reference, payer, creditedWei, asset, chain } 或 null（非有效支付）\nconst balance = await payments.balanceOf(subscriber) // 模块账本余额\n```\n\n### 一次性支付（fiat `mode`，0.2.1）\n\nStripe Checkout 有「订阅模式」与「一次性支付模式」两种，0.2.0 只发订阅模式；0.2.1 起由入参决定：\n\n| `mode` | 请求体差异 | 商品名（`<label>` = `metadata.resourceLabel`，缺省 `resource`） |\n| --- | --- | --- |\n| `subscription`（**缺省**） | 写 `mode=subscription` + `line_items[0][price_data][recurring][interval]=<period>` | `Subscription — <label>` |\n| `payment` | 写 `mode=payment`，**不写** `recurring[interval]` | `<label>`（不带前缀） |\n\n- **不传 `mode` 的调用方（waas / dc 等）请求体与 0.2.0 逐字节一致**，无需改动。\n- 非法 `mode` → `POST /checkout` 返回 **400**（白名单 `subscription | payment`）。\n- 一次性商品仍走 `amountCents`（或链上套餐价换算）；`period` 在 `payment` 模式下被忽略。\n- 一次性支付**不会**产生 Stripe 订阅对象，故没有 `invoice.paid` 续费事件，只有 `checkout.session.completed`。\n\n### 链上订阅详情（0.2.1）\n\n`/subscription` 只回答「有没有效」，不足以支撑「付的是不是目标套餐」这类反作弊校验；`getSubscriptionDetail` 两步读合约（`getSubscription(subscriber, agentId)` → `getSubscriptionDetail(subscriptionId)`）补齐金额与币种：\n\n```ts\nconst sub = await payments.chain.getSubscriptionDetail('oxachain', subscriber, planId)\n// → {\n//     active: true,              // ← 唯一有效性判据（内部复用 hasActiveSubscription）\n//     subscriptionId: 12,\n//     status: 1,                 // 合约枚举透传（1 = active），仅供展示\n//     startedAt, expiresAt, period,\n//     payToken: '0x…',           // 实付币种（大小写与合约一致，比对自己 toLowerCase()）\n//     amountPaid: '20000000',    // 实付金额，payToken 的原子单位（字符串，非浮点）\n//     trialActive, trialEndsAt, fundsReleased,\n//   }\n```\n\n- **无订阅 → `{ active: false, subscriptionId: 0 }`**（HTTP 200，不抛错、不 404），调用方统一处理。\n- 该链槽未配 `subscriptionManager` → **409 `chain rail not configured`**（与 `/price`、`/subscription` 一致）。\n- HTTP 端点：`GET /subscription-detail/:chain/:subscriber/:resourceId`（`subscriber` 统一小写、`resourceId` 为数字，缺失 → 400）。\n- **`status` 不得当作有效性判据**（有效性一律看 `active`），否则调用方各判一套、口径分叉。\n\n### Webhook 路由（需要 rawBody）\n\n```ts\napp.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf } }))\n\napp.post('/webhooks/stripe', async (req, res) => {\n  try {\n    await payments.handleWebhook(req.rawBody.toString(), req.headers['stripe-signature'])\n    res.json({ received: true })\n  } catch (err) {\n    res.status(400).json({ error: err.message }) // 签名无效 → 'Invalid signature'\n  }\n})\n```\n\n### 访问检查\n\n```ts\n// 通用 store 只查 payment_access 登记表；「链上 OR 链下」的统一策略由你的 store 实现决定\nconst access = await payments.resolveAccess(subscriber, { agentId }, { chain: 'sepolia' })\n```\n\n### 可选：现成 Express router（版本 A 推荐）\n\n`@0xinfrax/payments/router` 提供了覆盖全部端点（`/info` `/price` `/chain-info` `/subscription` `/subscription-detail` `/checkout` `/verify` `/webhook` `/balance` `/access` `/capabilities` `/orders/:paymentId/status` `/mpp/*` `/a2a/*` `/period/*` `/batch/*` `/invites/*` `/transfers/*`）的现成 router，挂载即用：\n\n```ts\nimport { createPaymentsRouter } from '@0xinfrax/payments/router'\n\napp.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf } })) // webhook 需要 rawBody\napp.use('/payments', createPaymentsRouter(payments))\n```\n\n`express` 是 optional peer 依赖：不调用 `createPaymentsRouter` 就不需要它。\n\n### 能力层（可插拔 rail）\n\n每个通道是一个**可插拔能力**（chain / fiat / x402 / mpp / a2a / period / batch / invite / transfer），由构造参数（+ ENV 开关）决定启用与否：\n\n- `GET /capabilities` 返回能力清单（`enabled` / `endpoints` / `config`），调用者先探测再使用：\n  ```json\n  { \"capabilities\": { \"a2a\": { \"enabled\": true, \"endpoints\": [\"POST /a2a\", \"POST /a2a/settle\"], \"config\": { \"defaultPayee\": \"0x...\" } }, \"...\": {} } }\n  ```\n- 未启用能力的端点仍存在但返回 **503**（显式 \"not enabled\" 而非 404），便于调用方识别配置缺失。\n- 新增能力不破坏旧调用：`createPayment(method)` 增加 `a2a`（两阶段意图）与 `batch`（一次向 N 个 payee 收款）；`chargePeriod` / `getAuthorization` 走 period 授权；`createInvite` / `payInviteByBalance` 走 invite（agent 自动发收费邀请）；`createTransfer` / `confirmTransfer` 走 transfer（账本内原子划转）。\n- `POST /a2a/settle` 支持两种结算模式（AX-8/A2A-1）：`mode: 'tx'`（默认，校验链上 tx 入账）与 `mode: 'balance'`（从 payer 预存余额直接 `deduct` 结算，无新链上 tx，适用于服务端→服务端 A2A 编排；结算原子、ref 幂等，金额默认取 intent 记录，可被 `amountWei` 覆盖）。\n- 独立开关：`a2a` 默认随 `x402` 开启（可 `A2A_ENABLED=false` 关闭）；`period` / `batch` / `invite` / `transfer` 需注入对应 store seam 才启用（微服务形态另需 `PERIOD_ENABLED` / `BATCH_ENABLED` / `INVITE_ENABLED` / `TRANSFER_ENABLED=true`）。\n\n---\n\n## 参考实现：套餐支付（waas）\n\n> 仓库内**最早跑通独立服务形态的调用方**：waas 用户套餐支付（MQ-12，代码见 [`projects/waas/routes/subscriptionRoutes.ts`](../../waas/routes/subscriptionRoutes.ts) + [`projects/waas/services/paymentsClient.ts`](../../waas/services/paymentsClient.ts)）。以下以其真实用法为准的端到端样例。\n\n### ① 轻量 HTTP 客户端\n\n独立服务 router 挂载在 `/payments`（区别于 SDK 自带 `PaymentsClient` 的 gateway 前缀 `/api/v1/payments`），鉴权用统一契约 `X-Service-Key`。waas 即采用此轻量封装：\n\n```ts\nimport { config } from '../config' // PAYMENTS_URL / PAYMENTS_API_KEY\n\nasync function call<T = any>(path: string, init?: RequestInit): Promise<T> {\n  const base = config.payments.baseUrl.replace(/\\/$/, '')\n  const resp = await fetch(`${base}${path}`, {\n    ...init,\n    headers: {\n      'Content-Type': 'application/json',\n      'X-Service-Key': config.payments.apiKey,   // 统一服务间鉴权\n      ...(init?.headers ?? {}),\n    },\n    signal: AbortSignal.timeout(10_000),\n  })\n  if (!resp.ok) {\n    const body = await resp.json().catch(() => null)\n    throw new Error(body?.error ?? `payments ${path} failed (${resp.status})`)\n  }\n  return resp.json()\n}\n\nexport const paymentsApi = {\n  /** 链上套餐定价（GET /price?planId=&chain=） */\n  price: (planId: number, chain: string) => call(`/payments/price?planId=${planId}&chain=${chain}`),\n  /** 链槽信息：chainId + SubscriptionManager（GET /chain-info/:chain） */\n  chainInfo: (chain: string) => call(`/payments/chain-info/${chain}`),\n  /** 链上 escrow 订阅状态（GET /subscription/:chain/:subscriber/:resourceId） */\n  hasActiveSubscription: (chain: string, subscriber: string, resourceId: number) =>\n    call(`/payments/subscription/${chain}/${subscriber.toLowerCase()}/${resourceId}`),\n  /** fiat checkout（POST /checkout），metadata 透传业务上下文 */\n  checkout: (body: {\n    subscriber: string; planId: number; period: string;\n    metadata: Record<string, unknown>; clientReference: string;\n    successUrl?: string; cancelUrl?: string;\n  }) => call('/payments/checkout', { method: 'POST', body: JSON.stringify(body) }),\n  /** 验证链上支付 tx 并入账（POST /verify，幂等） */\n  verify: (txHash: string, chain?: string) =>\n    call('/payments/verify', { method: 'POST', body: JSON.stringify({ txHash, chain }) }),\n  /** x402 rail 探测（GET /info）：payTo / priceWei / network */\n  info: () => call('/payments/info'),\n}\n```\n\n### ② 订阅创建（pending）——按 rail 取支付信息\n\n```ts\nif (plan.price === 0) { /* free 直通 active，无支付意图 */ return }\nconst inserted = await pool.query(\n  `INSERT INTO subscriptions (user_id, plan_id, plan_name, price, billing_cycle, status, payment_method, payment_status)\n   VALUES ($1,$2,$3,$4,'monthly','pending',$5,'pending') RETURNING *`,\n  [userId, planId, plan.name, plan.price, rail]      // rail: chain | fiat | x402\n)\nconst subscriptionId = inserted.rows[0].id\nconst payment: any = { rail, chain }\n\nif (rail === 'chain') {\n  const [planInfo, info] = await Promise.all([\n    paymentsApi.price(resourceId, chain),\n    paymentsApi.chainInfo(chain),\n  ])\n  payment.price = planInfo.price          // 链上套餐价（wei）\n  payment.period = planInfo.period\n  payment.payToken = planInfo.payToken\n  payment.subscriptionManager = info.subscriptionManager  // 前端链上 subscribe 用\n  payment.chainId = info.chainId\n} else if (rail === 'fiat') {\n  const checkout = await paymentsApi.checkout({\n    subscriber: walletAddress || subscriptionId,\n    planId: resourceId,\n    period: 'month',\n    metadata: { product: 'subscription', planId, userId, subscriptionId },  // 业务上下文透传\n    clientReference: `sub:${subscriptionId}`,      // 回调里按此引用激活\n    successUrl: `${origin}/#/waas?sub=success`,\n    cancelUrl: `${origin}/#/waas?sub=cancelled`,\n  })\n  payment.sessionUrl = checkout.sessionUrl\n  payment.paymentId = checkout.paymentId\n} else if (rail === 'x402') {\n  const info = await paymentsApi.info()\n  payment.payTo = info.x402.payTo          // 前端向此地址转账\n  payment.priceWei = info.x402.priceWei\n  payment.network = info.x402.network\n}\n// → 前端：chain 引导用户链上 subscribe；fiat 跳 sessionUrl；x402 向 payTo 转账后提交 txHash\n```\n\n### ③ 支付确认——三种 rail 统一落到 `pending → active`（幂等）\n\n```ts\n// chain：轮询链上 escrow（SubscriptionManager.hasActiveSubscription）→ active 则激活\nconst { active } = await paymentsApi.hasActiveSubscription(chain, wallet, resourceId)\nif (active) await activateSubscription(subscriptionId)  // cancel 旧 active + pending→active\n\n// fiat：infrax-payments WEBHOOK_FORWARD_URL 出站事件 → 本服务 POST /payment-callback\n//   验签：x-payments-signature = HMAC-SHA256(JSON.stringify(body), PAYMENTS_WEBHOOK_SECRET)\n//   激活：event.object.client_reference_id = `sub:<id>` → activateSubscription(id)\n\n// x402：前端提交 txHash → POST /payments/verify（幂等入账）→ payer 匹配当前钱包 → 激活\nconst { verified, payer } = await paymentsApi.verify(txHash)\nif (verified && payer.toLowerCase() === wallet.toLowerCase()) await activateSubscription(subscriptionId)\n```\n\n> 状态机约定：`pending`（支付意图，模块已记 `payment_intents`）→ `active`（任一 rail 确认支付）→ `cancelled / failed`。业务激活逻辑（`activateSubscription`：cancel 旧订阅 → 置 active + 续期）完全在调用方，支付引擎只负责「钱」与出站事件。\n\n---\n\n## 嵌入式形态（宿主自带 store / 回调）\n\n模块的所有持久化都走 `PaymentStore` 接口，宿主可注入自己的表：\n\n```ts\nimport { PaymentsService } from '@0xinfrax/payments'\nimport type { PaymentStore, PaymentCredit } from '@0xinfrax/payments'\n\nclass MyStore implements PaymentStore {\n  balanceOf(address, asset) { /* 读你的余额表 */ }\n  credit(credit: PaymentCredit) { /* 幂等入账 */ }\n  isCreditRecorded(reference) { /* 幂等探针 */ }\n  deduct(address, amount, asset) { /* 扣减，返回是否充足 */ }\n  resolveAccess(subscriber, resource, opts) { /* 你的统一访问策略 */ }\n}\n\nconst payments = new PaymentsService({ store: new MyStore(), chains, stripe, x402, ... })\n```\n\nAgentX 自身即此形态的参考实现：\n\n- 组装：`gateway/src/services/payments.ts`（env → 模块配置）\n- 自定义 store + 事件桥：`gateway/src/services/payments-bridge.ts`（`AgentxPaymentStore` 覆盖 `fiat_subscriptions` / `x402_*` 表，`PaymentsBridge` 把模块 webhook 事件落到业务订阅表）\n\n---\n\n## 业务上下文透传规则\n\n1. **`metadata`**：业务参数（`agentId` / `planId` / 订单号…）放这里，模块原样落 `payment_intents.metadata`（JSONB），不解释、不校验、不消费。**0.2.1 起出站也会带上它**：fiat 入站把 `metadata` 展平写进 Stripe `metadata[<key>]`（key ≤ 40 / value ≤ 500 / 最多 50 对，超出丢弃并 warn，`checkout.session.completed` 原样带回），链上 `onCredit` 事件补 `metadata`（能关联到 intent 才带，取不到为 `undefined`，不新增失败路径）；`onWebhookEvent` 保持 Stripe 原始事件、不注入字段。\n2. **`clientReference`**（fiat）：由调用方构造的透明引用（如 `subscriber|agentId|planId`），模块转发给 Stripe 并在结果与 webhook 事件中原样回显；解析它属于宿主业务。\n3. **访问策略**：`resolveAccess` 的语义由注入的 store 决定（通用 `PgPaymentStore` 只查 `payment_access`；AgentX 的 store 是「链上 OR fiat/x402」）。模块不感知。\n\n---\n\n## API 参考\n\n| 成员 | 说明 |\n| --- | --- |\n| `PaymentsService.createPayment(input)` | 创建支付意图（fiat checkout / MPP open） |\n| `PaymentsService.verifyPayment(txHash, chain?)` | 验证链上付款并幂等入账（原生优先，失败回退 stablecoin EIP-3009） |\n| `PaymentsService.handleWebhook(payload, signature)` | 校验 Stripe 签名 → 归一化事件 → 调 `onWebhookEvent` |\n| `PaymentsService.resolveAccess(subscriber, resource, opts?)` | 委托 store 的访问检查 |\n| `PaymentsService.balanceOf / deduct` | 余额查询 / 原子扣减（委托 store） |\n| `PaymentsService.chain` | `ChainAdapter`：`getPlan` / `hasActiveSubscription` / `getSubscriptionDetail`（0.2.1，两步读：金额 + 实付币种）/ `platformFeeBps` |\n| `PaymentsService.stripe` | `StripeAdapter`：`createCheckoutSession` / `verifyWebhookSignature` / `parseEvent` |\n| `PaymentsService.x402` | `X402Adapter`：`verifyAndCredit` / `balanceOf` / `deduct` / `paymentRequiredHeaders` |\n| `PaymentsService.mpp` | `MPPAdapter`：`open` / `voucher` / `topUp` / `settle` / `close` / `session`（支付通道） |\n| `PaymentsService.mppVoucher / mppTopUp / mppSettle / mppClose / mppSession` | MPP 通道操作（服务层薄封装） |\n| `PgPaymentStore` | 通用 Postgres store（`payment_*` 表） |\n| `PgMPPSessionStore` | MPP 通道 Pg 实现（可选，注入到 Options） |\n| `updateIntentStatus(paymentId, status, opts?)` | 推进 intent 生命周期（`created→paid/failed/closed`、`paid→closed`）；x402 由 verifyPayment 自动置 `paid`，fiat 由宿主在回调里驱动。`opts.requireExisting`（0.2.1）为 opt-in：开启且 store 提供 `getIntent` 时，未知 id → 404、同值重复写幂等静默返回（HTTP 端点 `POST /orders/:paymentId/status` 即用此开关；不注入 `getIntent` 的嵌入宿主跳过判空，行为与旧版一致） |\n| `PaymentError` / `isPaymentError` | 带 `code` + 建议 `status` 的类型化错误（宿主按码映射 HTTP） |\n| `createPaymentsRouter` | 现成 Express router（`@0xinfrax/payments/router`） |\n| `X402Client` / `PaymentsClient` / `MPPClient` | 面向任意部署点的 HTTP 客户端 |\n| `buildVoucherMessage` / `recoverEIP3009Signer` / `recoverPermit2Signer` | EIP-712 协议 helper（MPP voucher / 稳定币双机制） |\n| `buildPaymentMessage` / `encodeHeader` / `decodeHeader` | x402 v2 协议 helper（PaymentRequired / PaymentPayload / PaymentResponse） |\n\n类型集中在 `types.ts`：`PaymentMethod`、`CreatePaymentInput / CreatePaymentResult`、`CheckoutMode`（0.2.1）、`SubscriptionDetail`（0.2.1）、`PaymentCredit`、`VerifiedPayment`、`WebhookEvent`、`PlanInfo`、`X402Info`、`MPPSessionRow` 等。\n\n---\n\n## 本地验证\n\n仓库内置两套本地 harness（需 docker，无需 Stripe 账号、无需真实链）：\n\n| 脚本 | 验证对象 | 说明 |\n| --- | --- | --- |\n| `scripts/local-payments/run.sh` | 嵌入式形态（B） | 起 postgres+anvil → 部署合约（含 MockUSDC）→ 起 gateway → `FLOWS=\"f1 f4 f5 f6\"` 全绿（F1-3 三轨订阅 / F4 x402 v2 / F5 MPP / F6 稳定币 EIP-3009） |\n| `scripts/local-payments/run-decouple.sh` | 独立库形态（A） | 只 import 模块自身 + 独立 `agentx_payments` 库，证明零 AgentX 耦合，19 项断言 |\n| `npm test` | 单测 | 13 个文件 209 项断言（协议 / 适配器 / service / router / 错误码 / 能力层 / invite+transfer 状态机与原子划转 / 0.2.1 的 `mode`+metadata 透传+订阅详情+intent 状态回写） |\n\n解耦验证断言示例：模块入口必须从自身 `dist/` 解析、依赖仅 `pg,viem`、src/dist 无 `fiat_subscriptions` / `x402_*` / `@agentxv2/sdk` 等业务 token、DB 仅 `payment_*` 表。\n\n---\n\n## 目录结构\n\n```\npayments/\n├── package.json            # @0xinfrax/payments, deps: pg + viem\n├── tsconfig.json\n├── db/migrations/          # 001-008（模块自有 payment_* 表）\n├── src/\n│   ├── index.ts            # 公共入口\n│   ├── types.ts            # 通用类型（metadata 透传约定）\n│   ├── errors.ts           # PaymentError{code,status}\n│   ├── service.ts          # PaymentsService（引擎 + 回调接缝）\n│   ├── store.ts            # PaymentStore 接口 + PgPaymentStore + PgMPPSessionStore + PgAuthorizationStore + PgBatchStore + PgInviteStore + PgTransferStore\n│   ├── client.ts           # X402Client / PaymentsClient / MPPClient\n│   ├── router.ts           # createPaymentsRouter（express 为 optional peer）\n│   ├── protocol/\n│   │   ├── x402-v2.ts      # PaymentRequired / PaymentPayload / PaymentResponse（EIP-712）\n│   │   ├── mpp-voucher.ts  # MPP voucher（EIP-712，channelId 确定性公式）\n│   │   └── stablecoin.ts   # EIP-3009 + Permit2 验签 helper\n│   └── adapters/\n│       ├── chain.ts        # 链上只读（getPlan / hasActiveSubscription）\n│       ├── stripe.ts       # Stripe 协议层（可配 apiBase 指向 mock）\n│       ├── x402.ts         # 原生代币付款验证 + 入账（stablecoin fallback）\n│       ├── mpp.ts          # MPP 通道（open/voucher/topUp/settle/close/session）\n│       └── stablecoin.ts   # EIP-3009 Transfer 事件入账验证\n```\n","readmeFilename":"README.md"}