oak-pay-business 2.2.7 → 2.2.8
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/checkers/pay.js +1 -0
- package/es/checkers/refund.js +2 -2
- package/es/components/refund/list/index.js +2 -1
- package/es/components/refund/list/web.pc.d.ts +1 -0
- package/es/components/refund/list/web.pc.js +2 -2
- package/es/configuration/attrUpdateMatrix.js +3 -0
- package/es/triggers/pay.js +13 -0
- package/es/triggers/refund.js +1 -0
- package/es/utils/pay.d.ts +8 -0
- package/es/utils/pay.js +65 -1
- package/es/utils/payClazz/WechatPay/WechatPay.js +5 -5
- package/es/watchers/pay.js +3 -44
- package/es/watchers/refund.js +2 -1
- package/lib/aspects/withdraw.d.ts +8 -8
- package/lib/checkers/pay.js +1 -0
- package/lib/checkers/refund.js +2 -2
- package/lib/configuration/attrUpdateMatrix.js +3 -0
- package/lib/context/BackendRuntimeContext.d.ts +1 -1
- package/lib/triggers/pay.js +13 -0
- package/lib/triggers/refund.js +1 -0
- package/lib/utils/application.d.ts +1 -1
- package/lib/utils/pay.d.ts +8 -0
- package/lib/utils/pay.js +67 -2
- package/lib/utils/payClazz/WechatPay/WechatPay.js +5 -5
- package/lib/utils/payClazz/WechatPay/index.d.ts +1 -1
- package/lib/watchers/pay.js +2 -44
- package/lib/watchers/refund.js +2 -1
- package/package.json +2 -2
package/es/checkers/pay.js
CHANGED
package/es/checkers/refund.js
CHANGED
|
@@ -24,7 +24,7 @@ const checkers = [
|
|
|
24
24
|
checker(operation, context) {
|
|
25
25
|
const { data, filter } = operation;
|
|
26
26
|
const { externalId } = data;
|
|
27
|
-
//
|
|
27
|
+
// 当offline退款成功时,必须有ExternalId
|
|
28
28
|
if (!externalId) {
|
|
29
29
|
return pipeline(() => context.select('refund', {
|
|
30
30
|
data: {
|
|
@@ -39,7 +39,7 @@ const checkers = [
|
|
|
39
39
|
}
|
|
40
40
|
}, { dontCollect: true }), (refunds) => {
|
|
41
41
|
const [refund] = refunds;
|
|
42
|
-
if (refund.pay.entity
|
|
42
|
+
if (refund.pay.entity === 'offlineAcount') {
|
|
43
43
|
throw new OakAttrNotNullException('refund', ['externalId']);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
@@ -55,7 +55,7 @@ export default OakComponent({
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
|
-
formData({ data }) {
|
|
58
|
+
formData({ data, features }) {
|
|
59
59
|
return {
|
|
60
60
|
refunds: data?.map((ele) => {
|
|
61
61
|
const { creator, withdrawId, pay, ...rest } = ele;
|
|
@@ -70,6 +70,7 @@ export default OakComponent({
|
|
|
70
70
|
creatorMobile: creator?.mobile$user?.[0]?.mobile || '-',
|
|
71
71
|
};
|
|
72
72
|
}),
|
|
73
|
+
amIRoot: features.token.isRoot(),
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
});
|
|
@@ -6,7 +6,7 @@ import { FilterPanel } from '../../../components/AbstractComponents';
|
|
|
6
6
|
import { ToYuan, ThousandCont } from 'oak-domain/lib/utils/money';
|
|
7
7
|
import assert from 'assert';
|
|
8
8
|
export default function Render(props) {
|
|
9
|
-
const { refunds, oakFullpath, oakExecutable } = props.data;
|
|
9
|
+
const { refunds, oakFullpath, oakExecutable, amIRoot } = props.data;
|
|
10
10
|
const { t, updateItem, execute, clean, setMessage } = props.methods;
|
|
11
11
|
const [upsertId, setUpsertId] = useState('');
|
|
12
12
|
const [updateAction, setUpdateAction] = useState('');
|
|
@@ -100,7 +100,7 @@ export default function Render(props) {
|
|
|
100
100
|
]} onAction={(row, action) => {
|
|
101
101
|
const { entity } = row.pay;
|
|
102
102
|
assert(entity !== 'account');
|
|
103
|
-
if (entity !== 'offlineAccount') {
|
|
103
|
+
if (entity !== 'offlineAccount' || !amIRoot) {
|
|
104
104
|
setMessage({
|
|
105
105
|
type: 'error',
|
|
106
106
|
title: t('cantOperateOnline'),
|
package/es/triggers/pay.js
CHANGED
|
@@ -622,5 +622,18 @@ const triggers = [
|
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
},
|
|
625
|
+
/* 影响的地方有点多,先不做了
|
|
626
|
+
{
|
|
627
|
+
entity: 'pay',
|
|
628
|
+
name: '当选择pay并发现pay的状态是paying时,尝试刷新其状态',
|
|
629
|
+
action: 'select',
|
|
630
|
+
when: 'after',
|
|
631
|
+
fn: async ({ result }, context) => {
|
|
632
|
+
if (result.length === 1 && result[0].iState === 'paying') {
|
|
633
|
+
await refreshPayState(result[0] as EntityDict['pay']['OpSchema'], context);
|
|
634
|
+
}
|
|
635
|
+
return 0;
|
|
636
|
+
}
|
|
637
|
+
} as SelectTriggerAfter<EntityDict, 'pay', BRC>, */
|
|
625
638
|
];
|
|
626
639
|
export default triggers;
|
package/es/triggers/refund.js
CHANGED
package/es/utils/pay.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import { EntityDict } from '../oak-app-domain';
|
|
|
3
3
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity';
|
|
4
4
|
import BackendRuntimeContext from '../context/BackendRuntimeContext';
|
|
5
5
|
import { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import { BRC } from '../types/RuntimeCxt';
|
|
6
7
|
export declare const fullPayProjection: EntityDict['pay']['Selection']['data'];
|
|
7
8
|
export declare function payNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, payId: string, headers: IncomingHttpHeaders): Promise<void>;
|
|
8
9
|
export declare function refundNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, refundId: string, headers: IncomingHttpHeaders): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* 刷新paying状态的pay的真实支付状态
|
|
12
|
+
* @param pay
|
|
13
|
+
* @param context
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function refreshPayState(pay: EntityDict['pay']['OpSchema'], context: BRC): Promise<import("oak-domain/lib/types/Entity").OperationResult<EntityDict> | undefined>;
|
package/es/utils/pay.js
CHANGED
|
@@ -41,7 +41,7 @@ export async function payNotify(context, body, payId, headers) {
|
|
|
41
41
|
filter: {
|
|
42
42
|
id: payId,
|
|
43
43
|
}
|
|
44
|
-
}, {});
|
|
44
|
+
}, { blockTrigger: true });
|
|
45
45
|
if (!pay) {
|
|
46
46
|
console.error('接受到无效的payId', payId);
|
|
47
47
|
return;
|
|
@@ -135,3 +135,67 @@ export async function refundNotify(context, body, refundId, headers) {
|
|
|
135
135
|
}, {});
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* 刷新paying状态的pay的真实支付状态
|
|
140
|
+
* @param pay
|
|
141
|
+
* @param context
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
export async function refreshPayState(pay, context) {
|
|
145
|
+
let pay2 = pay;
|
|
146
|
+
if (!pay2.entity || !pay2.entityId || !pay2.timeoutAt || !pay2.price || !pay2.iState) {
|
|
147
|
+
const pays = await context.select('pay', {
|
|
148
|
+
data: {
|
|
149
|
+
id: 1,
|
|
150
|
+
entity: 1,
|
|
151
|
+
entityId: 1,
|
|
152
|
+
price: 1,
|
|
153
|
+
iState: 1,
|
|
154
|
+
},
|
|
155
|
+
filter: {
|
|
156
|
+
id: pay.id,
|
|
157
|
+
}
|
|
158
|
+
}, { blockTrigger: true });
|
|
159
|
+
pay2 = pays[0];
|
|
160
|
+
}
|
|
161
|
+
const { entity, entityId, timeoutAt, price } = pay2;
|
|
162
|
+
const clazz = await getPayClazz(entity, entityId, context);
|
|
163
|
+
const [iState, updateData] = await clazz.getState(pay);
|
|
164
|
+
if (iState !== pay.iState) {
|
|
165
|
+
let action = 'close';
|
|
166
|
+
switch (iState) {
|
|
167
|
+
case 'closed': {
|
|
168
|
+
// action = 'close';
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case 'paid': {
|
|
172
|
+
action = 'succeedPaying';
|
|
173
|
+
updateData.paid = price;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default: {
|
|
177
|
+
assert(false);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return await context.operate('pay', {
|
|
181
|
+
id: await generateNewIdAsync(),
|
|
182
|
+
action,
|
|
183
|
+
data: updateData,
|
|
184
|
+
filter: {
|
|
185
|
+
id: pay.id,
|
|
186
|
+
}
|
|
187
|
+
}, {});
|
|
188
|
+
}
|
|
189
|
+
else if (iState === 'paying' && timeoutAt < Date.now()) {
|
|
190
|
+
// 尝试关闭订单
|
|
191
|
+
// 理论上用户可能在上一个getState和这个close之间支付完成,此时关闭失败,下一个Watcher到来时就能处理成功了
|
|
192
|
+
return await context.operate('pay', {
|
|
193
|
+
id: await generateNewIdAsync(),
|
|
194
|
+
action: 'close',
|
|
195
|
+
data: updateData,
|
|
196
|
+
filter: {
|
|
197
|
+
id: pay.id,
|
|
198
|
+
}
|
|
199
|
+
}, {});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -83,7 +83,7 @@ export default class WechatPay extends WechatPayDebug {
|
|
|
83
83
|
ABNORMAL: 退款异常
|
|
84
84
|
*/
|
|
85
85
|
const iState = REFUND_STATE_MATRIX[status];
|
|
86
|
-
return [iState, success_time ? { successAt: dayJs(success_time).
|
|
86
|
+
return [iState, success_time ? { successAt: dayJs(success_time).valueOf() } : undefined];
|
|
87
87
|
}
|
|
88
88
|
analyzeResult(result) {
|
|
89
89
|
const { success, data, } = result;
|
|
@@ -189,10 +189,10 @@ export default class WechatPay extends WechatPayDebug {
|
|
|
189
189
|
const updateData = {
|
|
190
190
|
meta: {
|
|
191
191
|
getState: omit(result, ['mchid', 'appid', 'out_trade_no']),
|
|
192
|
-
}
|
|
192
|
+
},
|
|
193
193
|
};
|
|
194
194
|
if (iState === 'paid') {
|
|
195
|
-
updateData.
|
|
195
|
+
updateData.successAt = dayJs(success_time).valueOf();
|
|
196
196
|
}
|
|
197
197
|
return [iState, updateData];
|
|
198
198
|
}
|
|
@@ -308,7 +308,7 @@ export default class WechatPay extends WechatPayDebug {
|
|
|
308
308
|
meta: omit(result, ['mchid',]),
|
|
309
309
|
};
|
|
310
310
|
if (iState === 'paid') {
|
|
311
|
-
extra.successAt = success_time;
|
|
311
|
+
extra.successAt = dayJs(success_time).valueOf();
|
|
312
312
|
}
|
|
313
313
|
return {
|
|
314
314
|
payId,
|
|
@@ -361,7 +361,7 @@ export default class WechatPay extends WechatPayDebug {
|
|
|
361
361
|
meta: omit(result, ['mchid',]),
|
|
362
362
|
};
|
|
363
363
|
if (iState === 'successful') {
|
|
364
|
-
extra.successAt = success_time;
|
|
364
|
+
extra.successAt = dayJs(success_time).valueOf();
|
|
365
365
|
}
|
|
366
366
|
return {
|
|
367
367
|
refundId,
|
package/es/watchers/pay.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { fullPayProjection } from '../utils/pay';
|
|
2
|
-
import { getPayClazz } from '../utils/payClazz';
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|
1
|
+
import { fullPayProjection, refreshPayState } from '../utils/pay';
|
|
5
2
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
|
6
3
|
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
|
7
4
|
const watchers = [
|
|
@@ -24,46 +21,8 @@ const watchers = [
|
|
|
24
21
|
fn: async (context, data) => {
|
|
25
22
|
const results = [];
|
|
26
23
|
for (const pay of data) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const [iState, updateData] = await clazz.getState(pay);
|
|
30
|
-
if (iState !== pay.iState) {
|
|
31
|
-
let action = 'close';
|
|
32
|
-
switch (iState) {
|
|
33
|
-
case 'closed': {
|
|
34
|
-
// action = 'close';
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case 'paid': {
|
|
38
|
-
action = 'succeedPaying';
|
|
39
|
-
updateData.paid = price;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
default: {
|
|
43
|
-
assert(false);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const result = await context.operate('pay', {
|
|
47
|
-
id: await generateNewIdAsync(),
|
|
48
|
-
action,
|
|
49
|
-
data: updateData,
|
|
50
|
-
filter: {
|
|
51
|
-
id: pay.id,
|
|
52
|
-
}
|
|
53
|
-
}, {});
|
|
54
|
-
results.push(result);
|
|
55
|
-
}
|
|
56
|
-
else if (iState === 'paying' && timeoutAt < Date.now()) {
|
|
57
|
-
// 尝试关闭订单
|
|
58
|
-
// 理论上用户可能在上一个getState和这个close之间支付完成,此时关闭失败,下一个Watcher到来时就能处理成功了
|
|
59
|
-
const result = await context.operate('pay', {
|
|
60
|
-
id: await generateNewIdAsync(),
|
|
61
|
-
action: 'close',
|
|
62
|
-
data: updateData,
|
|
63
|
-
filter: {
|
|
64
|
-
id: pay.id,
|
|
65
|
-
}
|
|
66
|
-
}, {});
|
|
24
|
+
const result = await refreshPayState(pay, context);
|
|
25
|
+
if (result) {
|
|
67
26
|
results.push(result);
|
|
68
27
|
}
|
|
69
28
|
}
|
package/es/watchers/refund.js
CHANGED
|
@@ -12,8 +12,8 @@ export declare function getWithdrawCreateData(params: {
|
|
|
12
12
|
creatorId: string;
|
|
13
13
|
creator?: import("../oak-app-domain/User/Schema").UpdateOperation | undefined;
|
|
14
14
|
} & {
|
|
15
|
-
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "
|
|
16
|
-
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "
|
|
15
|
+
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
16
|
+
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
17
17
|
modiEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
18
18
|
operEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
19
19
|
accountOper$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
@@ -26,8 +26,8 @@ export declare function getWithdrawCreateData(params: {
|
|
|
26
26
|
creator?: undefined;
|
|
27
27
|
creatorId: string;
|
|
28
28
|
} & {
|
|
29
|
-
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "
|
|
30
|
-
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "
|
|
29
|
+
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
30
|
+
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
31
31
|
modiEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
32
32
|
operEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
33
33
|
accountOper$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
@@ -40,8 +40,8 @@ export declare function getWithdrawCreateData(params: {
|
|
|
40
40
|
creatorId: string;
|
|
41
41
|
creator?: import("../oak-app-domain/User/Schema").UpdateOperation | undefined;
|
|
42
42
|
} & {
|
|
43
|
-
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "
|
|
44
|
-
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "
|
|
43
|
+
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
44
|
+
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
45
45
|
modiEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
46
46
|
operEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
47
47
|
accountOper$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
@@ -54,8 +54,8 @@ export declare function getWithdrawCreateData(params: {
|
|
|
54
54
|
creator?: undefined;
|
|
55
55
|
creatorId: string;
|
|
56
56
|
} & {
|
|
57
|
-
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "
|
|
58
|
-
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "
|
|
57
|
+
refund$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/Refund/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/Refund/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/Refund/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
58
|
+
withdrawTransfer$withdraw?: import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">[]> | (import("oak-domain/lib/types").Operation<string, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").UpdateOperationData, "withdrawId" | "withdraw">, Omit<import("../oak-app-domain/WithdrawTransfer/Schema").Filter, "withdrawId" | "withdraw">> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/WithdrawTransfer/Schema").CreateOperationData, "withdrawId" | "withdraw">>)[] | undefined;
|
|
59
59
|
modiEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/ModiEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
60
60
|
operEntity$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/OperEntity/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
|
61
61
|
accountOper$entity?: import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">[]> | import("oak-domain/lib/types").Operation<"create", Omit<import("../oak-app-domain/AccountOper/Schema").CreateOperationData, "entity" | "entityId">>[] | undefined;
|
package/lib/checkers/pay.js
CHANGED
package/lib/checkers/refund.js
CHANGED
|
@@ -26,7 +26,7 @@ const checkers = [
|
|
|
26
26
|
checker(operation, context) {
|
|
27
27
|
const { data, filter } = operation;
|
|
28
28
|
const { externalId } = data;
|
|
29
|
-
//
|
|
29
|
+
// 当offline退款成功时,必须有ExternalId
|
|
30
30
|
if (!externalId) {
|
|
31
31
|
return (0, executor_1.pipeline)(() => context.select('refund', {
|
|
32
32
|
data: {
|
|
@@ -41,7 +41,7 @@ const checkers = [
|
|
|
41
41
|
}
|
|
42
42
|
}, { dontCollect: true }), (refunds) => {
|
|
43
43
|
const [refund] = refunds;
|
|
44
|
-
if (refund.pay.entity
|
|
44
|
+
if (refund.pay.entity === 'offlineAcount') {
|
|
45
45
|
throw new types_1.OakAttrNotNullException('refund', ['externalId']);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -15,7 +15,7 @@ export declare class BackendRuntimeContext<ED extends EntityDict & BaseEntityDic
|
|
|
15
15
|
type?: number | undefined;
|
|
16
16
|
systemId?: number | undefined;
|
|
17
17
|
system?: import("../oak-app-domain/System/Schema").Projection | undefined;
|
|
18
|
-
config?: number | import("oak-domain/lib/types").JsonProjection<import("../oak-app-domain/Application/Schema").
|
|
18
|
+
config?: number | import("oak-domain/lib/types").JsonProjection<import("../oak-app-domain/Application/Schema").WebConfig | import("../oak-app-domain/Application/Schema").WechatMpConfig | import("../oak-app-domain/Application/Schema").WechatPublicConfig | import("../oak-app-domain/Application/Schema").NativeConfig> | undefined;
|
|
19
19
|
style?: number | import("oak-domain/lib/types").JsonProjection<import("oak-general-business/lib/types/Style").Style> | undefined;
|
|
20
20
|
domainId?: number | undefined;
|
|
21
21
|
domain?: import("../oak-app-domain/Domain/Schema").Projection | undefined;
|
package/lib/triggers/pay.js
CHANGED
|
@@ -625,5 +625,18 @@ const triggers = [
|
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
},
|
|
628
|
+
/* 影响的地方有点多,先不做了
|
|
629
|
+
{
|
|
630
|
+
entity: 'pay',
|
|
631
|
+
name: '当选择pay并发现pay的状态是paying时,尝试刷新其状态',
|
|
632
|
+
action: 'select',
|
|
633
|
+
when: 'after',
|
|
634
|
+
fn: async ({ result }, context) => {
|
|
635
|
+
if (result.length === 1 && result[0].iState === 'paying') {
|
|
636
|
+
await refreshPayState(result[0] as EntityDict['pay']['OpSchema'], context);
|
|
637
|
+
}
|
|
638
|
+
return 0;
|
|
639
|
+
}
|
|
640
|
+
} as SelectTriggerAfter<EntityDict, 'pay', BRC>, */
|
|
628
641
|
];
|
|
629
642
|
exports.default = triggers;
|
package/lib/triggers/refund.js
CHANGED
|
@@ -14,7 +14,7 @@ export declare const mergedProjection: {
|
|
|
14
14
|
type?: number | undefined;
|
|
15
15
|
systemId?: number | undefined;
|
|
16
16
|
system?: import("../oak-app-domain/System/Schema").Projection | undefined;
|
|
17
|
-
config?: number | import("oak-domain/lib/types").JsonProjection<import("../oak-app-domain/Application/Schema").
|
|
17
|
+
config?: number | import("oak-domain/lib/types").JsonProjection<import("../oak-app-domain/Application/Schema").WebConfig | import("../oak-app-domain/Application/Schema").WechatMpConfig | import("../oak-app-domain/Application/Schema").WechatPublicConfig | import("../oak-app-domain/Application/Schema").NativeConfig> | undefined;
|
|
18
18
|
style?: number | import("oak-domain/lib/types").JsonProjection<import("oak-general-business/lib/types/Style").Style> | undefined;
|
|
19
19
|
domainId?: number | undefined;
|
|
20
20
|
domain?: import("../oak-app-domain/Domain/Schema").Projection | undefined;
|
package/lib/utils/pay.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import { EntityDict } from '../oak-app-domain';
|
|
|
3
3
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity';
|
|
4
4
|
import BackendRuntimeContext from '../context/BackendRuntimeContext';
|
|
5
5
|
import { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import { BRC } from '../types/RuntimeCxt';
|
|
6
7
|
export declare const fullPayProjection: EntityDict['pay']['Selection']['data'];
|
|
7
8
|
export declare function payNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, payId: string, headers: IncomingHttpHeaders): Promise<void>;
|
|
8
9
|
export declare function refundNotify<ED extends EntityDict & BaseEntityDict>(context: BackendRuntimeContext<ED>, body: any, refundId: string, headers: IncomingHttpHeaders): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* 刷新paying状态的pay的真实支付状态
|
|
12
|
+
* @param pay
|
|
13
|
+
* @param context
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function refreshPayState(pay: EntityDict['pay']['OpSchema'], context: BRC): Promise<import("oak-domain/lib/types/Entity").OperationResult<EntityDict> | undefined>;
|
package/lib/utils/pay.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refundNotify = exports.payNotify = exports.fullPayProjection = void 0;
|
|
3
|
+
exports.refreshPayState = 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"));
|
|
@@ -45,7 +45,7 @@ async function payNotify(context, body, payId, headers) {
|
|
|
45
45
|
filter: {
|
|
46
46
|
id: payId,
|
|
47
47
|
}
|
|
48
|
-
}, {});
|
|
48
|
+
}, { blockTrigger: true });
|
|
49
49
|
if (!pay) {
|
|
50
50
|
console.error('接受到无效的payId', payId);
|
|
51
51
|
return;
|
|
@@ -141,3 +141,68 @@ async function refundNotify(context, body, refundId, headers) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
exports.refundNotify = refundNotify;
|
|
144
|
+
/**
|
|
145
|
+
* 刷新paying状态的pay的真实支付状态
|
|
146
|
+
* @param pay
|
|
147
|
+
* @param context
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
async function refreshPayState(pay, context) {
|
|
151
|
+
let pay2 = pay;
|
|
152
|
+
if (!pay2.entity || !pay2.entityId || !pay2.timeoutAt || !pay2.price || !pay2.iState) {
|
|
153
|
+
const pays = await context.select('pay', {
|
|
154
|
+
data: {
|
|
155
|
+
id: 1,
|
|
156
|
+
entity: 1,
|
|
157
|
+
entityId: 1,
|
|
158
|
+
price: 1,
|
|
159
|
+
iState: 1,
|
|
160
|
+
},
|
|
161
|
+
filter: {
|
|
162
|
+
id: pay.id,
|
|
163
|
+
}
|
|
164
|
+
}, { blockTrigger: true });
|
|
165
|
+
pay2 = pays[0];
|
|
166
|
+
}
|
|
167
|
+
const { entity, entityId, timeoutAt, price } = pay2;
|
|
168
|
+
const clazz = await (0, payClazz_1.getPayClazz)(entity, entityId, context);
|
|
169
|
+
const [iState, updateData] = await clazz.getState(pay);
|
|
170
|
+
if (iState !== pay.iState) {
|
|
171
|
+
let action = 'close';
|
|
172
|
+
switch (iState) {
|
|
173
|
+
case 'closed': {
|
|
174
|
+
// action = 'close';
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'paid': {
|
|
178
|
+
action = 'succeedPaying';
|
|
179
|
+
updateData.paid = price;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
default: {
|
|
183
|
+
(0, assert_1.default)(false);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return await context.operate('pay', {
|
|
187
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
188
|
+
action,
|
|
189
|
+
data: updateData,
|
|
190
|
+
filter: {
|
|
191
|
+
id: pay.id,
|
|
192
|
+
}
|
|
193
|
+
}, {});
|
|
194
|
+
}
|
|
195
|
+
else if (iState === 'paying' && timeoutAt < Date.now()) {
|
|
196
|
+
// 尝试关闭订单
|
|
197
|
+
// 理论上用户可能在上一个getState和这个close之间支付完成,此时关闭失败,下一个Watcher到来时就能处理成功了
|
|
198
|
+
return await context.operate('pay', {
|
|
199
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
200
|
+
action: 'close',
|
|
201
|
+
data: updateData,
|
|
202
|
+
filter: {
|
|
203
|
+
id: pay.id,
|
|
204
|
+
}
|
|
205
|
+
}, {});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.refreshPayState = refreshPayState;
|
|
@@ -86,7 +86,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
86
86
|
ABNORMAL: 退款异常
|
|
87
87
|
*/
|
|
88
88
|
const iState = REFUND_STATE_MATRIX[status];
|
|
89
|
-
return [iState, success_time ? { successAt: (0, dayjs_1.default)(success_time).
|
|
89
|
+
return [iState, success_time ? { successAt: (0, dayjs_1.default)(success_time).valueOf() } : undefined];
|
|
90
90
|
}
|
|
91
91
|
analyzeResult(result) {
|
|
92
92
|
const { success, data, } = result;
|
|
@@ -192,10 +192,10 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
192
192
|
const updateData = {
|
|
193
193
|
meta: {
|
|
194
194
|
getState: (0, lodash_1.omit)(result, ['mchid', 'appid', 'out_trade_no']),
|
|
195
|
-
}
|
|
195
|
+
},
|
|
196
196
|
};
|
|
197
197
|
if (iState === 'paid') {
|
|
198
|
-
updateData.
|
|
198
|
+
updateData.successAt = (0, dayjs_1.default)(success_time).valueOf();
|
|
199
199
|
}
|
|
200
200
|
return [iState, updateData];
|
|
201
201
|
}
|
|
@@ -311,7 +311,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
311
311
|
meta: (0, lodash_1.omit)(result, ['mchid',]),
|
|
312
312
|
};
|
|
313
313
|
if (iState === 'paid') {
|
|
314
|
-
extra.successAt = success_time;
|
|
314
|
+
extra.successAt = (0, dayjs_1.default)(success_time).valueOf();
|
|
315
315
|
}
|
|
316
316
|
return {
|
|
317
317
|
payId,
|
|
@@ -364,7 +364,7 @@ class WechatPay extends WechatPay_debug_1.default {
|
|
|
364
364
|
meta: (0, lodash_1.omit)(result, ['mchid',]),
|
|
365
365
|
};
|
|
366
366
|
if (iState === 'successful') {
|
|
367
|
-
extra.successAt = success_time;
|
|
367
|
+
extra.successAt = (0, dayjs_1.default)(success_time).valueOf();
|
|
368
368
|
}
|
|
369
369
|
return {
|
|
370
370
|
refundId,
|
package/lib/watchers/pay.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const pay_1 = require("../utils/pay");
|
|
5
|
-
const payClazz_1 = require("../utils/payClazz");
|
|
6
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
-
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
8
4
|
const operationResult_1 = require("oak-domain/lib/utils/operationResult");
|
|
9
5
|
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
|
10
6
|
const watchers = [
|
|
@@ -27,46 +23,8 @@ const watchers = [
|
|
|
27
23
|
fn: async (context, data) => {
|
|
28
24
|
const results = [];
|
|
29
25
|
for (const pay of data) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const [iState, updateData] = await clazz.getState(pay);
|
|
33
|
-
if (iState !== pay.iState) {
|
|
34
|
-
let action = 'close';
|
|
35
|
-
switch (iState) {
|
|
36
|
-
case 'closed': {
|
|
37
|
-
// action = 'close';
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
case 'paid': {
|
|
41
|
-
action = 'succeedPaying';
|
|
42
|
-
updateData.paid = price;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
default: {
|
|
46
|
-
(0, assert_1.default)(false);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const result = await context.operate('pay', {
|
|
50
|
-
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
51
|
-
action,
|
|
52
|
-
data: updateData,
|
|
53
|
-
filter: {
|
|
54
|
-
id: pay.id,
|
|
55
|
-
}
|
|
56
|
-
}, {});
|
|
57
|
-
results.push(result);
|
|
58
|
-
}
|
|
59
|
-
else if (iState === 'paying' && timeoutAt < Date.now()) {
|
|
60
|
-
// 尝试关闭订单
|
|
61
|
-
// 理论上用户可能在上一个getState和这个close之间支付完成,此时关闭失败,下一个Watcher到来时就能处理成功了
|
|
62
|
-
const result = await context.operate('pay', {
|
|
63
|
-
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
64
|
-
action: 'close',
|
|
65
|
-
data: updateData,
|
|
66
|
-
filter: {
|
|
67
|
-
id: pay.id,
|
|
68
|
-
}
|
|
69
|
-
}, {});
|
|
26
|
+
const result = await (0, pay_1.refreshPayState)(pay, context);
|
|
27
|
+
if (result) {
|
|
70
28
|
results.push(result);
|
|
71
29
|
}
|
|
72
30
|
}
|
package/lib/watchers/refund.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-pay-business",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"classnames": "^2.3.1",
|
|
31
31
|
"dayjs": "^1.11.5",
|
|
32
32
|
"oak-domain": "~5.0.15",
|
|
33
|
-
"oak-frontend-base": "5.2.10",
|
|
33
|
+
"oak-frontend-base": "~5.2.10",
|
|
34
34
|
"oak-general-business": "~5.2.5",
|
|
35
35
|
"wechat-pay-nodejs": "^0.2.3"
|
|
36
36
|
},
|