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

ym-payment

v0.5.3

Published

include alipay, weixinpay

Downloads

6

Readme

USAGE

let payment = require('@ym/payment);
const pay = new payment({
  alipay: {
    APPID: 'appid',
    KEY: 'key',
    PARTNER: 'partner',
    EMAIL: 'email'
  },
  wxpay: {
    'APIKEY': 'apikey',
    'APPID': 'appid',
    'APPSECRET': 'appsecret',
    'MCHID': 'mchid'
  }
});

ALIPAY demo

pay.createPay({
  type:'alipay',
  opts:{
    method: pay.alipay.method.WAP,  // WAP | PC
    notify_url: encodeURIComponent(notify_url),
    redirect_url: encodeURIComponent(redirect_url),
    title: 'heiheihei',
    total_fee: 100,
  }
}).then(result=>{
  do somthing ...
});
/** result
{ subject: 'heiheihei',
  total_fee: 1,
  notify_url: 'http%3A%2F%2Fwxtest.tlifang.com%2Fredirect',
  return_url: 'http%3A%2F%2Fwxtest.tlifang.com%2Fredirect',
  method: 'wap',
  pay_expire: 21600,
  out_trade_no: 'ALI_97081479348948205',
  service: 'alipay.wap.trade.create.direct',
  _input_charset: 'utf-8',
  partner: '2088511420******',
  req_data: '<direct_trade_create_req><subject>heiheihei</subject><out_trade_no>ALI_97081479348948205</out_trade_no><total_fee>1</total_fee><seller_account_name>[email protected]</seller_account_name><call_bacl_url>http%3A%2F%2Fwxtest
.tlifang.com%2Fredirect</call_bacl_url><notify_url>http%3A%2F%2Fwxtest.tlifang.com%2Fredirect</notify_url></direct_trade_create_req>',
  format: 'xml',
  v: '2.0',
  req_id: 1479348948205,
  sec_id: 'MD5',
  signStr: '_input_charset=utf-8&format=xml&method=wap&notify_url=http%253A%252F%252Fwxtest.tlifang.com%252Fredirect&out_trade_no=ALI_97081479348948205&partner=2088511420574362&pay_expire=21600&req_data=%3Cdirect_trade_create_req%3E%3C
subject%3Eheiheihei%3C%2Fsubject%3E%3Cout_trade_no%3EALI_97081479348948205%3C%2Fout_trade_no%3E%3Ctotal_fee%3E1%3C%2Ftotal_fee%3E%3Cseller_account_name%3Edotnar%40hotmail.com%3C%2Fseller_account_name%3E%3Ccall_bacl_url%3Ehttp%253A%252F
%252Fwxtest.tlifang.com%252Fredirect%3C%2Fcall_bacl_url%3E%3Cnotify_url%3Ehttp%253A%252F%252Fwxtest.tlifang.com%252Fredirect%3C%2Fnotify_url%3E%3C%2Fdirect_trade_create_req%3E&req_id=1479348948205&return_url=http%253A%252F%252Fwxtest.t
lifang.com%252Fredirect&sec_id=MD5&service=alipay.wap.trade.create.direct&subject=heiheihei&total_fee=1&v=2.0&sign=be2aa95943419fb158e845410ebffc3b',
  url: 'http://wappaygw.alipay.com/service/rest.htm?_input_charset=utf-8&format=xml&method=wap&partner=2088511420574362&req_data=%3Cauth_and_execute_req%3E%3Crequest_token%3E20161117e3cae90e0c9e80abacdb277bca176eb6%3C%2Frequest_token%3
E%3C%2Fauth_and_execute_req%3E&req_id=1479348948205&sec_id=MD5&service=alipay.wap.auth.authAndExecute&v=2.0&sign=07942309c1b08393990e0098377e387c' }
**/

WXPAY demo

pay.createPay({
  type:'wxpay',
  opts:{
    method: pay.wxpay.trade_type.NATIVE, // NATIVE | APP | JSAPI
    notify_url: encodeURIComponent(notify_url),
    redirect_url: encodeURIComponent(redirect_url),
    title: 'heiheihei',
    total_fee: 100,
    spbill_create_ip:'110.84.35.141'
  }
}).then(result=>{
  do something ...
});
/** result
{ appid: 'wx80bb623*******',
  mch_id: '1348******',
  nonce_str: 'uKJZUSzetduXALVN',
  body: 'heiheihei',
  detail: '',
  out_trade_no: 'WX_14821479349944501',
  total_fee: '100',
  spbill_create_ip: '110.84.35.141',
  notify_url: 'http%253A%252F%252Fwxtest.tlifang.com%252Fredirect',
  trade_type: 'NATIVE',
  return_code: 'SUCCESS',
  return_msg: 'OK',
  sign: '34029ED1B0E5C044ADA5E61FA6BC8CA1',
  result_code: 'SUCCESS',
  prepay_id: 'wx20161117103224e888877af80382167652',
  code_url: 'weixin://wxpay/bizpayurl?pr=XpYtxsN',
  timestamp: 1479349944 }
**/

verify success pay

alipay -- PC

对账单 bill

// alipay


// weixin
pay.bill({
  type: 'wxpay',
  bill_type: 'ALL',
  bill_date: '2016-12-26'
}).then(result => do something ... );
// result is a binary buffer

订单查询 query

// alipay
pay.query({
  type: 'alipay',
  out_trade_no: 'ALI_04371*********'
}).then(result => console.log(result));
/** result
{ alipay_trade_query_response:
   { code: '10000',
     msg: 'Success',
     buyer_logon_id: '408***@qq.com',
     buyer_pay_amount: '0.00',
     buyer_user_id: '2088702392******',
     invoice_amount: '0.00',
     open_id: '2088107306227690694********',
     out_trade_no: 'ALI_0437148********',
     point_amount: '0.00',
     receipt_amount: '0.00',
     send_pay_date: '2016-12-23 14:18:27',
     total_amount: '0.01',
     trade_no: '2016122321001004******',
     trade_status: 'TRADE_SUCCESS' },
  sign: 'L7PsKj8hyavwu83k7FabiNLqD25j9+y+9***********ZdzHuogNAg24VPXEwhlDqjR72KRdL2jitpuWEHVih/yKArsoxV7xsQy4fxz0f6wVFGYnHXQ63R/tvzwDDlYwliTIMxuitXPn/aw6F0Orm+dRo='
}
*/


// wxpay
pay.query({
  type: 'wxpay',
  transaction_id: '4000532001201612264071709308', // 微信订单号
  // out_trade_no: 'WX_32251482746656924' // 商户订单号, 与微信订单号二选一,商户订单号是我们自己生成的,微信订单号是支付时微信发送到我们通知服务上带的
}).then(result => console.log(result)).catch(e => console.log(e));
/** result
{ return_code: 'SUCCESS',
  return_msg: 'OK',
  appid: 'wx7961afad7b487af1',
  mch_id: '1383371302',
  nonce_str: '1XqNJTpEZMyhHbyj',
  sign: '2496F6592C5130272042E00B40EA18CB',
  result_code: 'SUCCESS',
  openid: 'obRqWw90inZonl_lN8IyUgVKRbrg',
  is_subscribe: 'Y',
  trade_type: 'NATIVE',
  bank_type: 'CFT',
  total_fee: '1',
  fee_type: 'CNY',
  transaction_id: '4000532001201612264071709308',
  out_trade_no: 'WX_32251482746656924',
  attach: {},
  time_end: '20161226180448',
  trade_state: 'SUCCESS',
  cash_fee: '1' }
*/

关闭订单

pay.close({
  type: 'wxpay',
  out_trade_no: 'WX_3630148368*****'
}).then(result => {
  console.log(result);
}).catch(e => console.log(e));

退款

pay.refund({
  type: 'wxpay',
  out_trade_no: 'WX_123914836907*****'
}).then(result => console.log(result)).catch(e => console.log(e));

验签

//wxpay
pay.wxpay.verifySign({
  "appid": "wx7961afad******",
  "bank_type": "CFT",
  "cash_fee": "1",
  "fee_type": "CNY",
  "is_subscribe": "Y",
  "mch_id": "13833****",
  "nonce_str": "YjZiNWU4ZDE=",
  "openid": "obRqWw90inZonl_******",
  "out_trade_no": "WX_96451488******",
  "result_code": "SUCCESS",
  "return_code": "SUCCESS",
  "sign": "C6EC9C719C3B89D8F9250*******",
  "time_end": "20170304013731",
  "total_fee": "1",
  "trade_type": "NATIVE",
  "transaction_id": "400053200120170304213*****"
}).then(
  status=>{console.log(status); //true
}).catch(e=>{
  console.error(e); // wrong sign
});

发放微信红包

pay..sendWXRedPacket({
  send_name: 't立方',
  re_openid: 'obRqWw90inZonl_lN8IyUgVKRbrg',
  wishing: 'da ji da li',
  client_ip: '120.41.129.225',
  act_name: '抽奖送红包',
  scene_id: 'PRODUCT_2',
  total_amount: 210
}).then(console.log).catch(console.error);