Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

middleware支持动态config: req.wxpayconfig #56 #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Folked
orig from https://www.npmjs.com/package/wechat-pay

## 动态 config for middle
```js
router.all('*', function(req,res, next){
...
req.wxpayconfig = initConfig;
next();
})
```


# 微信支付 for Nodejs

## 初始化
Expand Down
7 changes: 7 additions & 0 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Basic.prototype.done = function (handler) {
var self = this;
var payment = self.payment;
return function (req, res, next) {
if(req.wxpayconfig){
payment = new Payment(req.wxpayconfig);
}
if (req.method !== 'POST') {
var error = new Error();
error.name = 'NotImplemented';
Expand Down Expand Up @@ -131,6 +134,10 @@ Refund.prototype.done = function (handler) {
var key = self.key;

return function (req, res, next) {
if(req.wxpayconfig){
payment = new Payment(req.wxpayconfig);
key = md5(req.wxpayconfig.partnerKey).toLowerCase();
}
if (req.method !== 'POST') {
var error = new Error();
error.name = 'NotImplemented';
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
{
"name": "wechat-pay",
"version": "0.3.2",
"name": "@jabawocky/wechat-pay",
"version": "0.3.4",
"description": "wechat payment api for document v3.3.5",
"main": "index.js",
"scripts":
{
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository":
{
"repository": {
"type": "git",
"url": "git://github.com/supersheep/wechat-pay.git"
"url": "git@github.com:jebberwocky/wechat-pay.git"
},
"keywords": [
"wechat",
"payment"
],
"author": "spud",
"license": "ISC",
"bugs":
{
"url": "https://github.com/supersheep/wechat-pay/issues"
"bugs": {
"url": "https://github.com/jebberwocky/wechat-pay/issues"
},
"homepage": "https://github.com/supersheep/wechat-pay",
"dependencies":
{
"homepage": "https://github.com/jebberwocky/wechat-pay",
"dependencies": {
"md5": "^2.0.0",
"request": "^2.45.0",
"sha1": "^1.1.0",
"underscore": "^1.7.0",
"xml2js": "^0.4.4"
},
"directories": {
"lib": "lib"
}
}