npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xpay-nodejs

v3.0.4

Published

XPay API wrapper

Downloads

2

Readme

XPay Node.js SDK

简介

lib 文件夹下是 Node.js SDK 文件,
example 文件夹里面是一个简单的接入示例,该示例仅供参考。 docs 接口文档

版本要求

nodejs 版本 4 及以上

安装

npm install xpay-nodejs
或者
下载源码后,在项目目录下运行 npm install <path to xpay-nodejs>
<path to xpay-nodejs>xpay-nodejs 源码路径

初始化

var xpay = require('xpay-nodejs')('YOUR-KEY');

设置请求签名密钥

密钥需要你自己生成,公钥请填写到 XPay Dashboard
设置你的私钥路径

xpay.setPrivateKeyPath("/path/to/your_rsa_private_key.pem");

也可以设置私钥内容

xpay.setPrivateKey("你的 RSA 私钥内容字符串");

支付

xpay.payments.create({
  order_no:  "123456789",
  app:       { id: "APP_ID" },
  channel:   channel,
  amount:    100,
  client_ip: "127.0.0.1",
  currency:  "cny",
  subject:   "Your Subject",
  body:      "Your Body",
  extra:     extra
}, function(err, charge) {
  // YOUR CODE
});

查询

xpay.payments.retrieve(
  "CHARGE_ID",
  function(err, charge) {
    // YOUR CODE
  }
);
xpay.payments.list(
  { limit: 5 },
  function(err, payments) {
    // YOUR CODE
  }
);

退款

xpay.payments.createRefund(
  "CHARGE_ID",
  { amount: 100, description: "Refund Description" },
  function(err, refund) {
    // YOUR CODE
  }
);

退款查询

xpay.payments.retrieveRefund(
  "CHARGE_ID",
  "REFUND_ID",
  function(err, refund) {
    // YOUR CODE
  }
);
xpay.payments.listRefunds(
  "CHARGE_ID",
  { limit: 5 },
  function(err, refunds) {
    // YOUR CODE
  }
);

红包

xpay.redEnvelopes.create({
  order_no:    "123456789",
  app:         { id: "APP_ID" },
  channel:     "wx_pub",
  amount:      100,
  currency:    "cny",
  subject:     "Your Subject",
  body:        "Your Body",
  extra: {
    nick_name: "Nick Name",
    send_name: "Send Name"
  },
  recipient:   "Openid",
  description: "Your Description"
}, function(err, redEnvelope) {
  // YOUR CODE
});

微信公众号获取签名

如果使用微信 JS-SDK 来调起支付,需要在创建 charge 后,获取签名(signature),传给 HTML5 SDK。

xpay.wxOAuth.getJsapiTicket(wx_app_id, wx_app_secret, function(e, response){
  var ticket = response['ticket'];
});

正常情况下,jsapi_ticket 的有效期为 7200 秒。由于获取 jsapi_ticket 的 api 调用次数非常有限,频繁刷新 jsapi_ticket 会导致 api 调用受限,影响自身业务,开发者必须在自己的服务器全局缓存 jsapi_ticket

下面方法中 url 是当前网页的 URL,不包含#及其后面部分

var signature = xpay.wxOAuth.getSignature(charge, ticket, url);

然后在 HTML5 SDK 里调用

xpay.createPayment(charge, callback, signature, false);

Event 事件

xpay.events.retrieve(
  "EVENT_ID",
  function(err, event) {
    // YOUR CODE
  }
);

企业付款

xpay.transfers.create({
  order_no:    "123456789",
  app:         { id: "APP_ID" },
  channel:     "wx_pub",
  amount:      100,
  currency:    "cny",
  type:        "b2c",
  recipient:   "Openid",
  description: "Your Description"
}, function(err, transfer) {
  // YOUR CODE
});

企业付款取消

/* 企业付款取消 */
xpay.transfers.create({
  order_no:    "123456789",
  app:         { id: "APP_ID" },
  channel:     "unionpay",// 目前支持 wx(新渠道)、 wx_pub、 unionpay
  amount:      100,// 订单总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100,企业付款最小发送金额为 1 元)
  currency:    "cny",
  type:        "b2c",// 付款类型,当前仅支持 b2c 企业付款
  description: "Your Description",
  extra: {
    "user_name": "User Name",
    "card_number":"111111",
    "open_bank_code":"0100"
  }
}, function(err, transfer) {
  if (err) {
    console.log("xpay.transfers.create(unionpay) fail:",err)
    return
  }
  xpay.transfers.cancel(
    transfer.id,
    function(err, transfers) {
      if (err) {
        console.log("xpay.transfers.cancel fail:",err)
      }
      // YOUR CODE
    }
  );
});

企业付款查询

xpay.transfers.retrieve(
  "TRANSFER_ID",
  function(err, transfer) {
    // YOUR CODE
  }
);
xpay.transfers.list(
  { limit: 5 },
  function(err, transfers) {
    // YOUR CODE
  }
);

企业批量付款

xpay.batchTransfers.create({
  "app": "APP_ID" ,
  "batch_no": "123456789", // 批量付款批次号
  "channel": "alipay", // 目前只支持 alipay
  "amount": 8000, // 批量付款总金额
  "description": "Your Description",
  "recipients": [
    {
      "account": "[email protected]", // 接收者支付宝账号
      "amount": 5000, // 付款金额
      "name": "李狗" // 接收者姓名
    },
    {
      "account": "[email protected]", // 接收者支付宝账号
      "amount": 3000, // 付款金额
      "name": "伢子" // 接收者姓名
    }
  ],
  "type": "b2c" // 付款类型,当前仅支持 b2c 企业付款
}, function(err, transfer) {
  // YOUR CODE
});

企业批量付款查询

/* 查询 */
xpay.batchTransfers.retrieve(
  // 通过 Transfer 对象的 id 查询一个已创建的 Transfer 对象
  "181610181347533047",
  function(err, transfer) {
    // YOUR CODE
  }
);

/* 查询列表 */
xpay.batchTransfers.list(
  {page: 1},
  function(err, transfers) {
    // YOUR CODE
  }
);

身份证银行卡认证

xpay.identification.identify(
  {
    type: 'bank_card',
    app: 'APP_ID',
    data: {
      id_name: '张三',
      id_number: '320291198811110000',
      card_number: '6201111122223333'
    }
  },
  function(err, result) {
    // YOUR CODE
  }
);

接口列表

详细信息请参考 API 文档