From 6673cd8165d3c457c4baf407947bfa92ef07ef42 Mon Sep 17 00:00:00 2001 From: Lyman Lai Date: Sun, 6 Nov 2016 11:11:22 +0800 Subject: [PATCH 1/2] Update wxpay.js fixed #10 --- lib/wxpay.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/wxpay.js b/lib/wxpay.js index 969ac13..3ff7ef0 100644 --- a/lib/wxpay.js +++ b/lib/wxpay.js @@ -81,6 +81,10 @@ WXPay.mix('getBrandWCPayRequestParams', function(order, fn){ order.trade_type = "JSAPI"; var _this = this; this.createUnifiedOrder(order, function(err, data){ + if (data.return_code === 'FAIL') { + fn(data) + return + } var reqparam = { appId: _this.options.appid, timeStamp: Math.floor(Date.now()/1000)+"", From 75f61d27756aad58d3dec7f8dacb65ee43fbb2ca Mon Sep 17 00:00:00 2001 From: Lyman Lai Date: Tue, 29 Nov 2016 05:52:25 +0800 Subject: [PATCH 2/2] return the original nonce_str so we can store it and then validate it while wechat server make notify --- lib/wxpay.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/wxpay.js b/lib/wxpay.js index 3ff7ef0..ce094ed 100644 --- a/lib/wxpay.js +++ b/lib/wxpay.js @@ -72,7 +72,13 @@ WXPay.mix('createUnifiedOrder', function(opts, fn){ passphrase: this.options.mch_id } }, function(err, response, body){ - util.parseXML(body, fn); + util.parseXML(body, function(err, result){ + if (err) { + return fn(err) + } + result.nonce_str = opts.nonce_str + fn(null, result) + }); }); });