All Projects → perzy → co-wechat-payment

perzy / co-wechat-payment

Licence: MIT License
Wechat payment lib for node.js koa framework.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to co-wechat-payment

throwback
An asynchronous middleware pattern
Stars: ✭ 25 (+25%)
Mutual labels:  koa
koaton
Koaton is a CLI tool that provides a nice starting point for full stack JavaScript Web development with Koa, Ember, and Node.js along with CaminateJS and WebSockets.
Stars: ✭ 28 (+40%)
Mutual labels:  koa
dashboard
📺🐝OpenPitrix UI
Stars: ✭ 29 (+45%)
Mutual labels:  koa
ravel
Forge past a tangle of node.js modules. Make a cool app.
Stars: ✭ 19 (-5%)
Mutual labels:  koa
slides
No description or website provided.
Stars: ✭ 27 (+35%)
Mutual labels:  koa
secondhand-deal
A campus secondhand trading system based on the vue.js + stylus + koa2 + sequelize ORM + mysql, and typescript is still learning to migrate.🍌
Stars: ✭ 21 (+5%)
Mutual labels:  koa
kurier
TypeScript framework to create JSON:API compliant APIs
Stars: ✭ 30 (+50%)
Mutual labels:  koa
graphql-typeorm-koa-workshop
Demo GraphQL API server
Stars: ✭ 36 (+80%)
Mutual labels:  koa
vue-cms
VUE-CMS. Proudly Using ES7, Vue 2, Koa 2, Webpack 4, Babel 7 And Mocha
Stars: ✭ 16 (-20%)
Mutual labels:  koa
route-decorators
ES7 decorators that simplify Koa and Express route creation
Stars: ✭ 71 (+255%)
Mutual labels:  koa
redux-react-koa-isomorphic-counter-example
Isomorphic port of the redux counter app
Stars: ✭ 77 (+285%)
Mutual labels:  koa
Agile-Server
A simple, fast, complete Node.js server solution, based on KOA. 简单快速的 、性能强劲的、功能齐全的 node 服务器解决方案合集,基于 KOA。
Stars: ✭ 24 (+20%)
Mutual labels:  koa
giog
It's based on githud issues and built with Vue 2.x, vue-router & vuex with server-side rendering by koa
Stars: ✭ 14 (-30%)
Mutual labels:  koa
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (+175%)
Mutual labels:  koa
react-isomorphic-bundle
React Redux Universal (isomorphic) bundle
Stars: ✭ 53 (+165%)
Mutual labels:  koa
koa-yield-breakpoint
Add breakpoints around `yield` expression especially for koa@1.
Stars: ✭ 17 (-15%)
Mutual labels:  koa
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (+60%)
Mutual labels:  koa
koa-router-version
Semantic Versioning routing for Koa
Stars: ✭ 19 (-5%)
Mutual labels:  koa
leizm-web
现代的 Web 中间件基础框架,完美支持 TypeScript,构建可维护的大型 Web 项目
Stars: ✭ 40 (+100%)
Mutual labels:  koa
nfw
A jsonapi boilerplate for @nfw-core with mikro-orm
Stars: ✭ 23 (+15%)
Mutual labels:  koa

co-wechat-payment

微信支付 for node.js

npm version

Installation

npm install co-wechat-payment

Usage

创建统一支付订单

var WXPay = require('co-wechat-payment');

var wxpay = new WXPay({
	appId: 'xxxxxxxx',
	mchId: '1234567890',
	partnerKey: 'xxxxxxxxxxxxxxxxx', //微信商户平台API密钥
	pfx: fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书
});

var result = yield wxpay.unifiedOrder({
	body: 'js H5支付',
	out_trade_no: '20160701'+Math.random().toString().substr(2, 10),
	total_fee: 1, // 1分钱
	spbill_create_ip: '10.10.10.10',
	notify_url: 'http://xx.xx.xx/wxpay/notify/',
	trade_type: 'JSAPI',
	product_id: '1234567890'
});

查询订单 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2

// 通过微信订单号查
var result = yield wxpay.queryOrder({ transaction_id:"xxxxxx" });

// 通过商户订单号查
var result = yield wxpay.queryOrder({ out_trade_no:"xxxxxx" });

关闭订单 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3

var result = yield wxpay.closeOrder({ out_trade_no:"xxxxxx"});

退款接口

var params = {
	appid: 'xxxxxxxx',
	mch_id: '1234567890',
    op_user_id: '商户号即可',
    out_refund_no: '20140703'+Math.random().toString().substr(2, 10),
    total_fee: '1', //原支付金额
    refund_fee: '1', //退款金额
    transaction_id: '微信订单号'
};

var result = yield wxpay.refund(params);

原生支付 (NATIVE)

公众号支付 (JS API)

生成JS API支付参数,发给页面

var result = yield wxpay.getBrandWCPayRequestParams({
	openid: '微信用户 openid',
	body: '公众号支付测试',
    detail: '公众号支付测试',
	out_trade_no: '20150331'+Math.random().toString().substr(2, 10),
	total_fee: 1,
	spbill_create_ip: '192.168.2.210',
	notify_url: 'http://wxpay_notify_url'
});

yield this.render('/wechat/pay',{payArgs:result});

网页调用参数(以ejs为例)

WeixinJSBridge.invoke(
	"getBrandWCPayRequest", <%-JSON.stringify(payArgs)%>, function(res){
		if(res.err_msg == "get_brand_wcpay_request:ok" ) {
    		// success
    	}
});

根据之前预创建订单接口返回的prepare_id参数,生成JS API支付参数,发给页面

var result = yield wxpay.getJsPayRequestParams('xxxxx');

yield this.render('/wechat/pay',{payArgs:result});

中间件

商户服务端处理微信的回调(koa为例)

var wechatBodyParser = require('co-wechat-body');
app.use(wechatBodyParser(options));

// 支付结果异步通知
router.post('/wechat/payment/notify', wechatPayment.middleware(), function* (){
  var message = this.request.body;
  // 处理你的订单状态更新逻辑. [warn] 注意,分布式并发情况下需要加锁处理.
  // do something...

  // 向微信返回处理成功信息
  this.body = 'OK';

  // 如果业务逻辑处理异常, 向微信返回错误信息,微信服务器会继续通知.
  // this.body =  new Error('server error');
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].