Skip to content

donghanji/koa-wxpay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-wxpay

weixin pay for node koa

npm version

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

//KoaHandle
//create order
createUnifiedOrder(data={},opts={}){
    let wxpay=new WxPay(data);
    //
    return new Promise(function(resolve,reject){
        //
        //TODO
        //
        wxpay.createUnifiedOrder(data,function(err,result){
            if(err){
                //
                return reject(result);
            }
            //
            return resolve(result);
        });
    });
}
//change order status
changeUnifiedOrder(data={},opts={}){
    //TODO
}

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 ^_^

About

weixin pay for koa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published