oak-pay-business 2.2.5 → 2.2.7
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/components/AbstractComponents.d.ts +22 -10
- package/es/components/AbstractComponents.js +0 -1
- package/es/components/account/detail/index.js +8 -1
- package/es/components/account/detail/index.less +10 -1
- package/es/components/account/detail/index.xml +11 -5
- package/es/components/account/detail/web.pc.module.less +68 -68
- package/es/components/deposit/new/index.d.ts +1 -0
- package/es/components/deposit/new/index.js +1 -0
- package/es/components/deposit/new/index.xml +15 -2
- package/es/components/order/pay/info.js +6 -6
- package/es/components/order/pay/info.module.less +24 -24
- package/es/components/order/pay/web.mobile.module.less +35 -35
- package/es/components/order/pay/web.pc.module.less +35 -35
- package/es/components/payConfig/upsert/offline/web.pc.module.less +4 -4
- package/es/components/payConfig/upsert/web.pc.module.less +10 -10
- package/es/components/wpAccount/upsert/web.pc.js +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 +1 -1
- package/es/types/Exception.js +3 -3
- package/es/types/PayClazz.d.ts +8 -2
- package/es/utils/pay.d.ts +1 -0
- package/es/utils/pay.js +52 -0
- 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/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/triggers/refund.js +1 -1
- package/lib/types/Exception.d.ts +1 -1
- package/lib/types/Exception.js +5 -5
- package/lib/types/PayClazz.d.ts +8 -2
- package/lib/utils/pay.d.ts +1 -0
- package/lib/utils/pay.js +54 -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
package/lib/types/PayClazz.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EntityDict } from '../oak-app-domain';
|
|
2
2
|
import { BRC } from '../types/RuntimeCxt';
|
|
3
3
|
type IState = EntityDict['pay']['OpSchema']['iState'];
|
|
4
|
+
type RefundIState = EntityDict['refund']['OpSchema']['iState'];
|
|
4
5
|
export default interface PayClazz {
|
|
5
6
|
getAccountEntity(): [string, string];
|
|
6
7
|
getAccountAmount(context: BRC): Promise<number>;
|
|
@@ -16,8 +17,13 @@ export default interface PayClazz {
|
|
|
16
17
|
extra?: EntityDict['pay']['Update']['data'];
|
|
17
18
|
price?: number;
|
|
18
19
|
}>;
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
decodeRefundNotification(params: Record<string, any>, body: any): Promise<{
|
|
21
|
+
refundId: string;
|
|
22
|
+
iState: RefundIState;
|
|
23
|
+
extra?: EntityDict['refund']['Update']['data'];
|
|
24
|
+
price?: number;
|
|
25
|
+
}>;
|
|
26
|
+
refund(refund: EntityDict['refund']['Schema'], context: BRC): Promise<EntityDict['refund']['Update']['data'] | undefined>;
|
|
21
27
|
getRefundableAt(successAt: number): number;
|
|
22
28
|
getRefundState(refund: EntityDict['refund']['OpSchema']): Promise<[EntityDict['refund']['OpSchema']['iState'], EntityDict['refund']['Update']['data'] | undefined]>;
|
|
23
29
|
}
|
package/lib/utils/pay.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ import BackendRuntimeContext from '../context/BackendRuntimeContext';
|
|
|
5
5
|
import { IncomingHttpHeaders } from 'http';
|
|
6
6
|
export declare const fullPayProjection: EntityDict['pay']['Selection']['data'];
|
|
7
7
|
export declare function payNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, payId: string, headers: IncomingHttpHeaders): Promise<void>;
|
|
8
|
+
export declare function refundNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, refundId: string, headers: IncomingHttpHeaders): Promise<void>;
|
package/lib/utils/pay.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.payNotify = exports.fullPayProjection = void 0;
|
|
3
|
+
exports.refundNotify = exports.payNotify = exports.fullPayProjection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const payClazz_1 = require("./payClazz");
|
|
6
6
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
@@ -88,3 +88,56 @@ async function payNotify(context, body, payId, headers) {
|
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
exports.payNotify = payNotify;
|
|
91
|
+
async function refundNotify(context, body, refundId, headers) {
|
|
92
|
+
const [refund] = await context.select('refund', {
|
|
93
|
+
data: {
|
|
94
|
+
id: 1,
|
|
95
|
+
price: 1,
|
|
96
|
+
iState: 1,
|
|
97
|
+
pay: {
|
|
98
|
+
entity: 1,
|
|
99
|
+
entityId: 1,
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
filter: {
|
|
103
|
+
id: refundId,
|
|
104
|
+
}
|
|
105
|
+
}, {});
|
|
106
|
+
if (!refund) {
|
|
107
|
+
console.error('接受到无效的refundId', refundId);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const { entity, entityId } = refund.pay;
|
|
111
|
+
const payClazz = await (0, payClazz_1.getPayClazz)(entity, entityId, context);
|
|
112
|
+
const { refundId: refundId2, extra, iState, } = await payClazz.decodeRefundNotification({ headers }, body);
|
|
113
|
+
(0, assert_1.default)(refundId2 === refundId);
|
|
114
|
+
if (iState !== refund.iState) {
|
|
115
|
+
let action = 'succeed';
|
|
116
|
+
const updateData = {};
|
|
117
|
+
switch (iState) {
|
|
118
|
+
case 'successful': {
|
|
119
|
+
// action = 'close';
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'failed': {
|
|
123
|
+
action = 'fail';
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
default: {
|
|
127
|
+
(0, assert_1.default)(false);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (extra) {
|
|
131
|
+
Object.assign(updateData, extra);
|
|
132
|
+
}
|
|
133
|
+
await context.operate('refund', {
|
|
134
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
135
|
+
action,
|
|
136
|
+
data: updateData,
|
|
137
|
+
filter: {
|
|
138
|
+
id: refundId,
|
|
139
|
+
}
|
|
140
|
+
}, {});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.refundNotify = refundNotify;
|
|
@@ -9,13 +9,18 @@ export default class Account implements PayClazz {
|
|
|
9
9
|
calcPayTax(): [number, string, string];
|
|
10
10
|
getRefundableAt(successAt: number): number;
|
|
11
11
|
refund(refund: EntityDict['refund']['Schema']): Promise<undefined>;
|
|
12
|
-
closeRefund(refund: EntityDict['refund']['Schema']): Promise<void>;
|
|
13
12
|
getRefundState(refund: EntityDict['refund']['Schema']): Promise<[EntityDict['refund']['Schema']['iState'], undefined]>;
|
|
14
13
|
decodePayNotification(params: Record<string, any>, body: any): Promise<{
|
|
15
14
|
payId: string;
|
|
16
15
|
iState: string | null | undefined;
|
|
17
16
|
extra?: EntityDict['pay']['Update']['data'] | undefined;
|
|
18
17
|
}>;
|
|
18
|
+
decodeRefundNotification(params: Record<string, any>, body: any): Promise<{
|
|
19
|
+
refundId: string;
|
|
20
|
+
iState: string | null | undefined;
|
|
21
|
+
extra?: EntityDict['refund']['Update']['data'] | undefined;
|
|
22
|
+
price?: number | undefined;
|
|
23
|
+
}>;
|
|
19
24
|
prepay(pay: EntityDict['pay']['Schema'], data: EntityDict['pay']['Update']['data'], context: BRC): Promise<void>;
|
|
20
25
|
getState(pay: EntityDict['pay']['Schema']): Promise<[string, EntityDict['pay']['Update']['data']]>;
|
|
21
26
|
close(pay: EntityDict['pay']['Schema']): Promise<void>;
|
|
@@ -26,15 +26,15 @@ class Account {
|
|
|
26
26
|
async refund(refund) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
async closeRefund(refund) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
29
|
async getRefundState(refund) {
|
|
33
30
|
return ['refuding', undefined];
|
|
34
31
|
}
|
|
35
32
|
decodePayNotification(params, body) {
|
|
36
33
|
throw new Error("account类型的pay不需调用此接口");
|
|
37
34
|
}
|
|
35
|
+
decodeRefundNotification(params, body) {
|
|
36
|
+
throw new Error("account类型的pay不需调用此接口");
|
|
37
|
+
}
|
|
38
38
|
async prepay(pay, data, context) {
|
|
39
39
|
const { entity, entityId, price } = pay;
|
|
40
40
|
(0, assert_1.default)(entity === 'account' && entityId);
|
|
@@ -13,13 +13,18 @@ export default class Offline implements PayClazz {
|
|
|
13
13
|
calcPayTax(price: number): [number, string, string];
|
|
14
14
|
getRefundableAt(successTime: number): number;
|
|
15
15
|
refund(refund: RefundOpSchema): Promise<UpdateOperationData | undefined>;
|
|
16
|
-
closeRefund(refund: RefundOpSchema): Promise<void>;
|
|
17
16
|
getRefundState(refund: RefundOpSchema): Promise<[PayOpSchema['iState'], PayUpdateData | undefined]>;
|
|
18
17
|
decodePayNotification(params: Record<string, any>, body: any): Promise<{
|
|
19
18
|
payId: string;
|
|
20
19
|
iState: string | null | undefined;
|
|
21
20
|
extra?: PayUpdateData | undefined;
|
|
22
21
|
}>;
|
|
22
|
+
decodeRefundNotification(params: Record<string, any>, body: any): Promise<{
|
|
23
|
+
refundId: string;
|
|
24
|
+
iState: string | null | undefined;
|
|
25
|
+
extra?: EntityDict['refund']['Update']['data'] | undefined;
|
|
26
|
+
price?: number | undefined;
|
|
27
|
+
}>;
|
|
23
28
|
prepay(pay: PayOpSchema, data: PayUpdateData, context: BRC): Promise<void>;
|
|
24
29
|
getState(pay: PayOpSchema): Promise<[string, PayUpdateData]>;
|
|
25
30
|
close(pay: PayOpSchema): Promise<void>;
|
|
@@ -52,10 +52,6 @@ class Offline {
|
|
|
52
52
|
// 啥也不做
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
async closeRefund(refund) {
|
|
56
|
-
// 啥也不做
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
55
|
async getRefundState(refund) {
|
|
60
56
|
const { iState } = refund;
|
|
61
57
|
(0, assert_1.default)(iState === 'refunding');
|
|
@@ -64,6 +60,9 @@ class Offline {
|
|
|
64
60
|
decodePayNotification(params, body) {
|
|
65
61
|
throw new Error("offline类型的pay不需调用此接口");
|
|
66
62
|
}
|
|
63
|
+
decodeRefundNotification(params, body) {
|
|
64
|
+
throw new Error("offline类型的pay不需调用此接口");
|
|
65
|
+
}
|
|
67
66
|
async prepay(pay, data, context) {
|
|
68
67
|
data.phantom3 = Math.ceil(Math.random() * 1000000);
|
|
69
68
|
return;
|
|
@@ -3,7 +3,7 @@ import PayClazz from "../../../types/PayClazz";
|
|
|
3
3
|
import { BRC } from "../../../types/RuntimeCxt";
|
|
4
4
|
import { WechatPay as WechatPaySDK } from 'wechat-pay-nodejs';
|
|
5
5
|
import { EntityDict } from "../../../oak-app-domain";
|
|
6
|
-
import { OpSchema as OpRefund, UpdateOperationData as RefundUpdateData } from "../../../oak-app-domain/Refund/Schema";
|
|
6
|
+
import { OpSchema as OpRefund, UpdateOperationData as RefundUpdateData, Schema as Refund } from "../../../oak-app-domain/Refund/Schema";
|
|
7
7
|
import { Schema as WpProduct } from '../../../oak-app-domain/WpProduct/Schema';
|
|
8
8
|
import WechatPayDebug from './WechatPay.debug';
|
|
9
9
|
export default class WechatPay extends WechatPayDebug implements PayClazz {
|
|
@@ -19,10 +19,9 @@ export default class WechatPay extends WechatPayDebug implements PayClazz {
|
|
|
19
19
|
static MIN_REFUND_DAYS_GAP: number;
|
|
20
20
|
static DEFAULT_REFUND_DAYS_GAP: number;
|
|
21
21
|
constructor(wpProduct: WpProduct, appId: string);
|
|
22
|
-
refund(refund:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
private analyzePrepayResult;
|
|
22
|
+
refund(refund: Refund, context: BRC): Promise<RefundUpdateData | undefined>;
|
|
23
|
+
getRefundState(refund: OpRefund): Promise<[string | null | undefined, RefundUpdateData | undefined]>;
|
|
24
|
+
private analyzeResult;
|
|
26
25
|
private caclRefundDeadline;
|
|
27
26
|
prepay(pay: Pay, data: PayUpdateData, context: BRC): Promise<void>;
|
|
28
27
|
getState(pay: OpPay): Promise<[EntityDict['pay']['OpSchema']['iState'], PayUpdateData]>;
|
|
@@ -32,5 +31,11 @@ export default class WechatPay extends WechatPayDebug implements PayClazz {
|
|
|
32
31
|
iState: EntityDict['pay']['OpSchema']['iState'];
|
|
33
32
|
extra?: PayUpdateData;
|
|
34
33
|
}>;
|
|
34
|
+
decodeRefundNotification(params: Record<string, any>, body: any): Promise<{
|
|
35
|
+
refundId: string;
|
|
36
|
+
iState: string | null | undefined;
|
|
37
|
+
extra?: RefundUpdateData | undefined;
|
|
38
|
+
price?: number | undefined;
|
|
39
|
+
}>;
|
|
35
40
|
getRefundableAt(successAt: number): number;
|
|
36
41
|
}
|
|
@@ -8,13 +8,18 @@ export declare function registerGetPayStateResult(payState: NonNullable<EntityDi
|
|
|
8
8
|
export default class WechatPay implements PayClazz {
|
|
9
9
|
wpProduct: WpProduct;
|
|
10
10
|
constructor(wpProduct: WpProduct);
|
|
11
|
+
decodeRefundNotification(params: Record<string, any>, body: any): Promise<{
|
|
12
|
+
refundId: string;
|
|
13
|
+
iState: string | null | undefined;
|
|
14
|
+
extra?: RefundUpdateData | undefined;
|
|
15
|
+
price?: number | undefined;
|
|
16
|
+
}>;
|
|
11
17
|
getAccountEntity(): [string, string];
|
|
12
18
|
getAccountAmount(context: BRC): Promise<number>;
|
|
13
19
|
calcTransferTax(price: number): [number, string, string];
|
|
14
20
|
calcRefundTax(price: number): [number, string, string];
|
|
15
21
|
calcPayTax(price: number): [number, string, string];
|
|
16
|
-
refund(refund: Refund): Promise<RefundUpdateData | undefined>;
|
|
17
|
-
closeRefund(refund: Refund): Promise<void>;
|
|
22
|
+
refund(refund: Refund, context: BRC): Promise<RefundUpdateData | undefined>;
|
|
18
23
|
getRefundState(refund: Refund): Promise<[string | null | undefined, PayUpdateData | undefined]>;
|
|
19
24
|
decodePayNotification(params: Record<string, any>, body: any): Promise<{
|
|
20
25
|
payId: string;
|
|
@@ -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.7",
|
|
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": "
|
|
34
|
-
"oak-general-business": "~5.2.
|
|
32
|
+
"oak-domain": "~5.0.15",
|
|
33
|
+
"oak-frontend-base": "5.2.10",
|
|
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: '退款成功',
|