oak-pay-business 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/aspects/withdraw.d.ts +4 -4
- package/es/components/AbstractComponents.d.ts +5 -8
- package/es/components/account/detail/index.json +1 -0
- package/es/components/account/detail/index.less +1 -1
- package/es/components/account/detail/index.xml +6 -3
- package/es/components/accountOper/list/index.js +13 -1
- package/es/components/deposit/new/index.xml +0 -1
- package/es/components/order/list/web.pc.js +1 -1
- package/es/components/pay/list/web.pc.js +1 -1
- package/es/components/refund/list/web.pc.js +1 -1
- package/es/components/sysAccount/transferList/web.pc.js +1 -1
- package/es/components/withdrawTransfer/list/web.pc.js +2 -2
- package/es/context/BackendRuntimeContext.d.ts +1 -1
- package/es/entities/Refund.d.ts +2 -1
- package/es/entities/Refund.js +2 -1
- package/es/oak-app-domain/Refund/Schema.d.ts +7 -1
- package/es/oak-app-domain/Refund/Storage.js +3 -0
- package/es/oak-app-domain/Refund/locales/zh_CN.json +1 -1
- package/es/triggers/refund.js +1 -1
- package/es/types/Exception.d.ts +4 -1
- package/es/types/Exception.js +3 -3
- package/es/types/PayClazz.d.ts +8 -2
- package/es/utils/application.d.ts +1 -1
- package/es/utils/payClazz/Account.d.ts +6 -1
- package/es/utils/payClazz/Account.js +3 -3
- package/es/utils/payClazz/Offline.d.ts +6 -1
- package/es/utils/payClazz/Offline.js +3 -4
- package/es/utils/payClazz/WechatPay/WechatPay.d.ts +10 -5
- package/es/utils/payClazz/WechatPay/WechatPay.debug.d.ts +7 -2
- package/es/utils/payClazz/WechatPay/WechatPay.debug.js +4 -4
- package/es/utils/payClazz/WechatPay/WechatPay.js +98 -14
- package/es/utils/payClazz/WechatPay/index.d.ts +1 -1
- package/lib/aspects/withdraw.d.ts +8 -8
- package/lib/context/BackendRuntimeContext.d.ts +1 -1
- package/lib/entities/Refund.d.ts +2 -1
- package/lib/entities/Refund.js +2 -1
- package/lib/oak-app-domain/Refund/Schema.d.ts +7 -1
- package/lib/oak-app-domain/Refund/Storage.js +3 -0
- package/lib/oak-app-domain/Refund/locales/zh_CN.json +1 -1
- package/lib/oak-app-domain/System/Storage.js +2 -1
- package/lib/triggers/refund.js +1 -1
- package/lib/types/Exception.d.ts +4 -1
- package/lib/types/Exception.js +5 -5
- package/lib/types/PayClazz.d.ts +8 -2
- package/lib/utils/application.d.ts +1 -1
- package/lib/utils/payClazz/Account.d.ts +6 -1
- package/lib/utils/payClazz/Account.js +3 -3
- package/lib/utils/payClazz/Offline.d.ts +6 -1
- package/lib/utils/payClazz/Offline.js +3 -4
- package/lib/utils/payClazz/WechatPay/WechatPay.d.ts +10 -5
- package/lib/utils/payClazz/WechatPay/WechatPay.debug.d.ts +7 -2
- package/lib/utils/payClazz/WechatPay/WechatPay.debug.js +4 -4
- package/lib/utils/payClazz/WechatPay/WechatPay.js +97 -13
- package/package.json +4 -4
- package/src/entities/Refund.ts +3 -1
|
@@ -13,6 +13,9 @@ class WechatPay {
|
|
|
13
13
|
constructor(wpProduct) {
|
|
14
14
|
this.wpProduct = wpProduct;
|
|
15
15
|
}
|
|
16
|
+
decodeRefundNotification(params, body) {
|
|
17
|
+
throw new Error('Method not implemented.');
|
|
18
|
+
}
|
|
16
19
|
getAccountEntity() {
|
|
17
20
|
return ['wpAccount', this.wpProduct.wpAccountId];
|
|
18
21
|
}
|
|
@@ -54,14 +57,11 @@ class WechatPay {
|
|
|
54
57
|
(0, assert_1.default)(typeof taxLossRatio === 'number', '微信渠道的手续费率未配置');
|
|
55
58
|
return [Math.round(price * taxLossRatio / 100), 'wpAccount', wpProduct.wpAccountId];
|
|
56
59
|
}
|
|
57
|
-
async refund(refund) {
|
|
60
|
+
async refund(refund, context) {
|
|
58
61
|
return {
|
|
59
62
|
externalId: Math.random().toString(),
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
|
-
async closeRefund(refund) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
65
|
async getRefundState(refund) {
|
|
66
66
|
const r = Math.random();
|
|
67
67
|
if (r < 0.5) {
|
|
@@ -17,6 +17,12 @@ const TRADE_STATE_MATRIX = {
|
|
|
17
17
|
'PAYERROR': 'closed',
|
|
18
18
|
'REVOKED': 'closed',
|
|
19
19
|
};
|
|
20
|
+
const REFUND_STATE_MATRIX = {
|
|
21
|
+
'SUCCESS': "successful",
|
|
22
|
+
'CLOSED': "failed",
|
|
23
|
+
"ABNORMAL": "refunding",
|
|
24
|
+
"PROCESSING": 'refunding',
|
|
25
|
+
};
|
|
20
26
|
class WechatPay extends WechatPay_debug_1.default {
|
|
21
27
|
wechatPay;
|
|
22
28
|
refundGapDays;
|
|
@@ -48,20 +54,45 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
48
54
|
cert_public_content: fs_1.default.readFileSync(this.publicKeyFilePath),
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
|
-
refund(refund) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
async refund(refund, context) {
|
|
58
|
+
const { id, price, pay } = refund;
|
|
59
|
+
const serverUrl = context.composeAccessPath();
|
|
60
|
+
const endpoint = this.refundNotifyUrl;
|
|
61
|
+
const refundNotifyUrl = `${serverUrl}/endpoint/${endpoint}/${pay.id}`;
|
|
62
|
+
const result = await this.wechatPay.createRefund({
|
|
63
|
+
out_trade_no: (0, uuid_1.compressTo32)(pay.id),
|
|
64
|
+
out_refund_no: (0, uuid_1.compressTo32)(id),
|
|
65
|
+
notify_url: refundNotifyUrl,
|
|
66
|
+
amount: {
|
|
67
|
+
refund: price,
|
|
68
|
+
total: pay.price,
|
|
69
|
+
currency: 'CNY',
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const { refund_id } = this.analyzeResult(result);
|
|
73
|
+
return {
|
|
74
|
+
externalId: refund_id,
|
|
75
|
+
};
|
|
56
76
|
}
|
|
57
|
-
getRefundState(refund) {
|
|
58
|
-
|
|
77
|
+
async getRefundState(refund) {
|
|
78
|
+
const result = await this.wechatPay.queryRefundByOutRefundNo((0, uuid_1.compressTo32)(refund.id));
|
|
79
|
+
const { status, success_time } = this.analyzeResult(result);
|
|
80
|
+
/**
|
|
81
|
+
* 【退款状态】 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
|
|
82
|
+
可选取值:
|
|
83
|
+
SUCCESS: 退款成功
|
|
84
|
+
CLOSED: 退款关闭
|
|
85
|
+
PROCESSING: 退款处理中
|
|
86
|
+
ABNORMAL: 退款异常
|
|
87
|
+
*/
|
|
88
|
+
const iState = REFUND_STATE_MATRIX[status];
|
|
89
|
+
return [iState, success_time ? { successAt: (0, dayjs_1.default)(success_time).millisecond() } : undefined];
|
|
59
90
|
}
|
|
60
|
-
|
|
91
|
+
analyzeResult(result) {
|
|
61
92
|
const { success, data, } = result;
|
|
62
93
|
if (!success) {
|
|
63
94
|
console.error(JSON.stringify(result));
|
|
64
|
-
throw new Exception_1.
|
|
95
|
+
throw new Exception_1.ExternalPayUtilException(result);
|
|
65
96
|
}
|
|
66
97
|
return data;
|
|
67
98
|
}
|
|
@@ -91,7 +122,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
91
122
|
total: pay.price,
|
|
92
123
|
},
|
|
93
124
|
});
|
|
94
|
-
const { code_url } = this.
|
|
125
|
+
const { code_url } = this.analyzeResult(result);
|
|
95
126
|
data.externalId = code_url;
|
|
96
127
|
data.meta = {
|
|
97
128
|
codeUrl: code_url,
|
|
@@ -122,7 +153,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
122
153
|
openid: wechatUser.openId,
|
|
123
154
|
}
|
|
124
155
|
});
|
|
125
|
-
const prepayMeta = this.
|
|
156
|
+
const prepayMeta = this.analyzeResult(result);
|
|
126
157
|
const prepayId = prepayMeta.package.slice(11); // `prepay_id=${prepay_id}`
|
|
127
158
|
data.externalId = prepayId;
|
|
128
159
|
data.meta = {
|
|
@@ -155,7 +186,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
155
186
|
* USERPAYING:用户支付中(仅付款码支付会返回)
|
|
156
187
|
* PAYERROR:支付失败(仅付款码支付会返回)
|
|
157
188
|
*/
|
|
158
|
-
const { trade_state: tradeState, success_time } = this.
|
|
189
|
+
const { trade_state: tradeState, success_time } = this.analyzeResult(result);
|
|
159
190
|
const iState = TRADE_STATE_MATRIX[tradeState];
|
|
160
191
|
(0, assert_1.default)(iState);
|
|
161
192
|
const updateData = {
|
|
@@ -171,7 +202,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
171
202
|
async close(pay) {
|
|
172
203
|
const outTradeNo = (0, uuid_1.compressTo32)(pay.id);
|
|
173
204
|
const result = await this.wechatPay.closeOrder(outTradeNo);
|
|
174
|
-
this.
|
|
205
|
+
this.analyzeResult(result);
|
|
175
206
|
}
|
|
176
207
|
async decodePayNotification(params, body) {
|
|
177
208
|
const { resource } = body;
|
|
@@ -288,6 +319,59 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
288
319
|
extra,
|
|
289
320
|
};
|
|
290
321
|
}
|
|
322
|
+
async decodeRefundNotification(params, body) {
|
|
323
|
+
const { resource } = body;
|
|
324
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
325
|
+
console.log('decodeRefundNotification-resource', JSON.stringify(resource));
|
|
326
|
+
}
|
|
327
|
+
const { ciphertext, nonce, associated_data } = resource;
|
|
328
|
+
const result2 = this.wechatPay.decryptAesGcm({
|
|
329
|
+
ciphertext,
|
|
330
|
+
nonce,
|
|
331
|
+
apiV3Key: this.apiV3Key,
|
|
332
|
+
associatedData: associated_data,
|
|
333
|
+
});
|
|
334
|
+
const result = JSON.parse(result2);
|
|
335
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
336
|
+
console.log('decodeRefundNotification-decrypt', JSON.stringify(result));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 对resource对象进行解密后,得到的资源对象示例
|
|
340
|
+
* https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/refund-result-notice.html
|
|
341
|
+
* {
|
|
342
|
+
"mchid": "1900000100",
|
|
343
|
+
"transaction_id": "1008450740201411110005820873",
|
|
344
|
+
"out_trade_no": "20150806125346",
|
|
345
|
+
"refund_id": "50200207182018070300011301001",
|
|
346
|
+
"out_refund_no": "7752501201407033233368018",
|
|
347
|
+
"refund_status": "SUCCESS",
|
|
348
|
+
"success_time": "2018-06-08T10:34:56+08:00",
|
|
349
|
+
"user_received_account": "招商银行信用卡0403",
|
|
350
|
+
"amount" : {
|
|
351
|
+
"total": 999,
|
|
352
|
+
"refund": 999,
|
|
353
|
+
"payer_total": 999,
|
|
354
|
+
"payer_refund": 999
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
*/
|
|
358
|
+
const { out_refund_no, mchid, refund_status, success_time, } = result;
|
|
359
|
+
const refundId = (0, uuid_1.decompressFrom32)(out_refund_no);
|
|
360
|
+
(0, assert_1.default)(mchid === this.mchId);
|
|
361
|
+
const iState = REFUND_STATE_MATRIX[refund_status];
|
|
362
|
+
(0, assert_1.default)(iState);
|
|
363
|
+
const extra = {
|
|
364
|
+
meta: (0, lodash_1.omit)(result, ['mchid',]),
|
|
365
|
+
};
|
|
366
|
+
if (iState === 'successful') {
|
|
367
|
+
extra.successAt = success_time;
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
refundId,
|
|
371
|
+
iState,
|
|
372
|
+
extra,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
291
375
|
getRefundableAt(successAt) {
|
|
292
376
|
return this.caclRefundDeadline(successAt);
|
|
293
377
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-pay-business",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"classnames": "^2.3.1",
|
|
31
31
|
"dayjs": "^1.11.5",
|
|
32
|
-
"oak-domain": "~5.0.
|
|
33
|
-
"oak-frontend-base": "~5.2.
|
|
34
|
-
"oak-general-business": "~5.2.
|
|
32
|
+
"oak-domain": "~5.0.15",
|
|
33
|
+
"oak-frontend-base": "~5.2.9",
|
|
34
|
+
"oak-general-business": "~5.2.5",
|
|
35
35
|
"wechat-pay-nodejs": "^0.2.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
package/src/entities/Refund.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface Schema extends EntityShape {
|
|
|
22
22
|
price: Price;
|
|
23
23
|
creator: User;
|
|
24
24
|
reason?: Text;
|
|
25
|
+
successAt?: Datetime;
|
|
25
26
|
opers: AccountOper[];
|
|
26
27
|
};
|
|
27
28
|
|
|
@@ -53,7 +54,8 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
|
|
|
53
54
|
iState: '状态',
|
|
54
55
|
creator: '创建者',
|
|
55
56
|
reason: '原因',
|
|
56
|
-
opers: '相关账户操作'
|
|
57
|
+
opers: '相关账户操作',
|
|
58
|
+
successAt: '退款成功时间'
|
|
57
59
|
},
|
|
58
60
|
action: {
|
|
59
61
|
succeed: '退款成功',
|