收款 SDK
在收款应用中创建、读取、列出和撤销 PaymentRef。
x402-paysdk/receive 保持精简,只管理支付引用并校验收款侧输入,不负责商户订单逻辑。
创建引用
TypeScriptimport { createPaymentRef } from 'x402-paysdk/receive';const ref = await createPaymentRef({ gateway: 'https://gateway.example', payTo: '0x1111111111111111111111111111111111111111', network: 'eip155:8453', asset: 'USDC', amount: '12500000', label: 'Studio subscription', description: 'July plan', expiresInSecs: 3600, apiKey: process.env.X402_API_KEY});console.log(ref.refUrl);
amount 使用 token 最小单位,12_500_000 表示 12.5 USDC。仅在展示层把返回的 refUrl 转成二维码。
生命周期操作
getRef(gateway, refId)读取公开引用元数据。listPaymentRefs(options)返回有边界的商户引用列表。revokePaymentRef(options)拒绝某个引用的后续支付。revokePayTo(options)按网关策略停用地址。
notifyUrl 需要商户认证,且必须是公开 HTTPS 地址。SDK 会在发起请求前拒绝本地、私有、携带凭据或格式错误的 URL。