koa-wxpay
weixin pay for node koa
Installation
npm install koa-wxpay --save
Usage
Thanks tvrcgo/weixin-pay
to see
https://github.com/tvrcgo/weixin-pay
Add Other methods
//WxPay
static getClientIp(ctx)
static getServerHttp(ctx.req,page)
static success
static fail
let WxPay = require('koa-wxpay');
let wxpay=new WxPay({
appid: 'xxxxxxxx',
mch_id: '',
partner_key: '',
pfx: '',
});
wxpay.createUnifiedOrder({
body: '',
out_trade_no: '',
total_fee: 1,
spbill_create_ip: WxPay.getClientIp(ctx),
notify_url: WxPay.getServerHttp(opts.req,'/your/wxpay/notify'),
trade_type: 'NATIVE',
product_id: ''
}, function(err, result){
console.log(result);
});
Koa Handle
createUnifiedOrder(data={},opts={}){
let wxpay=new WxPay(data);
return new Promise(function(resolve,reject){
wxpay.createUnifiedOrder(data,function(err,result){
if(err){
return reject(result);
}
return resolve(result);
});
});
}
changeUnifiedOrder(data={},opts={}){
}
Koa Middleware Router
router.post('/xx/xx', async function(ctx,next){
let handler = new KoaHandle();
let res = await handler.createUnifiedOrder(data,opts).then(function(result){
return result;
}).catch(function(result){
return result;
});
ctx.body=res;
});
router.post('/your/wxpay/notify', async function(ctx,next){
let handler = new KoaHandle();
let res = await handler.changeUnifiedOrder(data,opts).then(function(result){
return WxPay.success();
}).catch(function(result){
return WxPay.fail();
});
ctx.body=res;
})
Other Notices
Only createUnifiedOrder method was verified ,other todo ... ,you can help me to test ^_^