Skip to content

Commit

Permalink
bump to 0.8.13
Browse files Browse the repository at this point in the history
APIv3s responseVerifier no need verification anymore while the HTTP status is not 20X code.
  • Loading branch information
TheNorthMemory committed Mar 27, 2024
1 parent e2720c1 commit e3798e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 变更历史

## v0.8.13 (2024-03-27)
- 针对`APIv3`返回的HTTP status code非20x场景,不再尝试去验签,异常类型从`AssertionError`回退为`AxiosError`;

## v0.8.12 (2024-03-09)
- 修正 `Transformer.toObject` 类型标注错误;
- [动态`uri_template`参数](https://github.com/TheNorthMemory/wechatpay-axios-plugin/issues/57)类型标注,感谢 @taoliujun 报告此问题;
Expand Down
5 changes: 4 additions & 1 deletion lib/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ class Decorator {
* @return {function} Named as `verifier` function
*/
static responseVerifier(certs = {}) {
return function verifier(data, headers) {
return function verifier(data, headers, status) {
/** @since v0.8.13 no need verification anymore while the HTTP status is not 20X code. */
if (status && this.validateStatus && !this.validateStatus(status)) { return data; }

const {
'wechatpay-timestamp': timestamp, 'wechatpay-nonce': nonce, 'wechatpay-serial': serial, 'wechatpay-signature': signature,
} = headers;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechatpay-axios-plugin",
"version": "0.8.12",
"version": "0.8.13",
"description": "微信支付APIv2及v3 NodeJS SDK,支持CLI模式请求OpenAPI,支持v3证书下载,v2付款码支付、企业付款、退款,企业微信-企业支付-企业红包/向员工付款,v2&v3 Native支付、扫码支付、H5支付、JSAPI/小程序支付、合单支付...",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
16 changes: 9 additions & 7 deletions tests/openapi/issue-28-ERR_ASSERTION-SYSTEM_ERROR.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { readFileSync } = require('fs');
const { join } = require('path');
const { AssertionError } = require('assert');
const { AxiosError } = require('axios');

require('should');
const nock = require('nock');
Expand All @@ -11,10 +11,12 @@ describe('Issue #28 jsapi 请求路径有误', () => {
let scope;
let instance;

const mocks = () => JSON.stringify({
const message = {
code: 'SYSTEM_ERROR',
message: '系统繁忙,请稍后重试',
});
};

const mocks = () => JSON.stringify(message);

beforeEach(() => {
// {@link ../../fixtures/README.md}
Expand All @@ -40,10 +42,10 @@ describe('Issue #28 jsapi 请求路径有误', () => {
it('post onto the `/v3/combine-transactions/jsapi` got a `500` SYSTEM_ERROR', async () => {
scope.post('/v3/combine-transactions/jsapi').reply(500, mocks);
await instance.v3.combineTransactions.jsapi.post({}).catch((resp) => {
resp.should.instanceOf(AssertionError);
resp.should.instanceOf(AxiosError);
resp.response.should.be.Object().and.have.keys('headers', 'data');
resp.response.headers.should.be.Object().and.not.have.keys('Wechatpay-Timestamp');
resp.response.data.should.be.String().and.match(/"SYSTEM_ERROR"/);
resp.response.data.should.be.eql(message);
});
});
});
Expand All @@ -52,10 +54,10 @@ describe('Issue #28 jsapi 请求路径有误', () => {
it('post onto the `/v3/pay/transactions/jsapi` got a `500` SYSTEM_ERROR', async () => {
scope.post('/v3/pay/transactions/jsapi').reply(500, mocks);
await instance.v3.pay.transactions.jsapi.post({}).catch((resp) => {
resp.should.instanceOf(AssertionError);
resp.should.instanceOf(AxiosError);
resp.response.should.be.Object().and.have.keys('headers', 'data');
resp.response.headers.should.be.Object().and.not.have.keys('Wechatpay-Timestamp');
resp.response.data.should.be.String().and.match(/"SYSTEM_ERROR"/);
resp.response.data.should.be.eql(message);
});
});
});
Expand Down

0 comments on commit e3798e5

Please sign in to comment.