{"_id":"@alone88/payment-hub","name":"@alone88/payment-hub","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@alone88/payment-hub","version":"0.1.0","description":"Payment Hub Node.js SDK","type":"commonjs","main":"src/index.js","types":"src/index.d.ts","exports":{".":{"types":"./src/index.d.ts","import":"./src/index.mjs","require":"./src/index.js"}},"scripts":{"test":"node --test"},"license":"MIT","homepage":"https://github.com/anhao/payment-hub-node#readme","repository":{"type":"git","url":"git+https://github.com/anhao/payment-hub-node.git"},"bugs":{"url":"https://github.com/anhao/payment-hub-node/issues"},"engines":{"node":">=18"},"_id":"@alone88/payment-hub@0.1.0","gitHead":"f25e1d02486daaf7795565e70cc0c9e921dc7404","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-s5FrA94edo5kU7efMtuTo+sP3gFSHMcSwiGIVejCf7kqr0EL6UAMq2sTYuVxIdXBsdMS+qHlm8j6FpIQVjckFg==","shasum":"0f78975d781fe8590864e7a49e6880e486bda6ab","tarball":"https://registry.npmjs.org/@alone88/payment-hub/-/payment-hub-0.1.0.tgz","fileCount":8,"unpackedSize":18515,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@alone88%2fpayment-hub@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDdaLyn1DmUJM4fk3taEZUMpYgcCheHxxGai7C14eCJ7wIhANNeKFDB3Tobz48WBEcwLOfv+vCjSfUP+Cy0cMO/RCtA"}]},"_npmUser":{"name":"alone88","email":"im@alone88.cn"},"directories":{},"maintainers":[{"name":"alone88","email":"im@alone88.cn"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/payment-hub_0.1.0_1781974022525_0.23027206373850806"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-20T16:47:02.402Z","0.1.0":"2026-06-20T16:47:02.660Z","modified":"2026-06-20T16:47:03.159Z"},"maintainers":[{"name":"alone88","email":"im@alone88.cn"}],"description":"Payment Hub Node.js SDK","homepage":"https://github.com/anhao/payment-hub-node#readme","repository":{"type":"git","url":"git+https://github.com/anhao/payment-hub-node.git"},"bugs":{"url":"https://github.com/anhao/payment-hub-node/issues"},"license":"MIT","readme":"# Payment Hub Node.js SDK\n\nnpm 包名：`@alone88/payment-hub`\n\n开源仓库：`https://github.com/anhao/payment-hub-node`\n\n许可证：MIT\n\n## 安装\n\n```bash\nnpm install @alone88/payment-hub\n```\n\n本仓库内开发测试：\n\n```bash\nnpm test\n```\n\n## 创建收银台支付\n\n```js\nimport { PaymentHubClient, wechatPayContext } from '@alone88/payment-hub';\n\nconst client = new PaymentHubClient({\n  baseUrl: 'https://payhub.alapi.cn',\n  appKey: 'your_app_key',\n  appSecret: 'your_app_secret',\n});\n\nconst response = await client.createPayment({\n  out_order_no: 'WPUSH202606180001',\n  title: 'WPUSH 年费会员',\n  amount: 9900,\n  mode: 'CASHIER',\n  // 微信 JSAPI / 小程序收银台支付时传入；普通扫码支付可不传。\n  extra: wechatPayContext({\n    scene: 'MINI',\n    appid: 'wx-mini-appid',\n    openid: 'openid-from-miniapp',\n  }),\n});\n\nconsole.log(response.data.payment_url);\n```\n\nCommonJS 也支持：\n\n```js\nconst { PaymentHubClient } = require('@alone88/payment-hub');\n```\n\n`wechatPayContext()` 会生成 `extra.pay_context.wechat`，Hub 会用其中的 `appid` 过滤支付账户，并在微信 JSAPI / 小程序下单时传递 `openid`。\n\n## 查询和退款\n\n```js\nconst payment = await client.getPayment('PH20260618ABC123XYZ0');\n\nconst refund = await client.createRefund({\n  payment_no: 'PH20260618ABC123XYZ0',\n  out_refund_no: 'WPUSH_REFUND_001',\n  amount: 9900,\n  reason: '用户申请退款',\n});\n```\n\n## Webhook 验签\n\n```js\nconst { verifyWebhookSignature } = require('@alone88/payment-hub');\n\nconst ok = verifyWebhookSignature(req.headers, rawBody, 'your_app_secret');\nif (!ok) {\n  res.statusCode = 401;\n  res.end('invalid signature');\n  return;\n}\n\n// 幂等处理 payment.success / refund.success ...\nres.setHeader('content-type', 'application/json');\nres.end(JSON.stringify({ code: 0 }));\n```\n\n## 支付完成跳转验签\n\n```js\nimport { verifyReturnUrl } from '@alone88/payment-hub';\n\nconst query = Object.fromEntries(new URL(req.url, 'https://merchant.example').searchParams);\n\nif (!verifyReturnUrl(query, 'your_app_secret')) {\n  res.statusCode = 401;\n  res.end('invalid signature');\n  return;\n}\n\n// 仅用于页面展示或定位订单；最终发货仍以 Webhook / 主动查询为准。\nconst paymentNo = query.payment_no;\n```\n","readmeFilename":"README.md","_rev":"1-77ad511e15740ad9a1917e087bdc879d"}