wechat-pay-sdk
sdk for wechat developer
Last updated 3 years ago by mrkou47 .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install wechat-pay-sdk 
SYNC missed versions from official npm registry.

wechat-pay-sdk

npm version Build Status codecov sdk for wechat developer, build with typescript.

Install

npm install wechat-pay-sdk --save

Install definition if you need!

npm install "git+https://git@github.com/mrkou47/wechat-pay-sdk.d.ts.git"

Usage

const wechatPay = require('wechat-pay-sdk');
const customize = new wechatPay({
  appid: 'your appid',
  secret: 'your wechat secret',
  mch_id: 'your mch_id',
  key: 'your key',
});

customize.getUserOpenId(code).then((res) => {
  console.log(res); // receive opendid response
});

customize.payment({...options}).then((res) => {
  console.log(res); // receive payment response
});

ATTENTION: you should use import wechatPay = require('wechat-pay-sdk'); if you used in the Typescript file.

API

wechatPay.getUserOpenId();

return Promise;

wechatPay.payment(options);

return Promise;

Options object for constructor()

All params is required

var wechatPayOptions = {
  appid: 'your appid',
  secret: 'your wechat secret',
  mch_id: 'your mch_id',
  key: 'your key',
};

Options for getUserOpenId()

wechatPay.getUserOpenId('code');

This method need a string argument, which you can find on req.query. see an Example;

Options object for payment()

var paymentOptions = {
  attach: 'some detail',
  body: 'description',
  detail: 'description',
  notify_url: 'http://www.weixin.qq.com/wxpay/pay.php',
  openid: 'J892IK12e1A912309c',
  out_trade_no: '20150806125346',
  spbill_create_ip: '123.12.13.123',
  total_fee: 100,
};

You can find params descrption on 微信支付文档

Run example

$ git clone https://github.com/MrKou47/wechat-pay-sdk.git
$ cd wechat-pay-sdk

Before start example, you shou edit wechat-config.js with you config. And then:

$ npm run dev

How to use in wxml?

Example:

fetch(YOUR_SERVER_URL, { method: 'POST', body: YOUR_REQUEST_BODY }).then(res => {
  wx.requestPayment({
    ...res.wechatpay_data,
    success() {
      // success callback
    },
    fail() {
      // failed callback
    },
    complete() {
      // complete callback
    }
  });
});

DOC: https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-pay.html

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

7 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (4)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |