oak-pay-business/es/checkers/refund.js

80 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { OakAttrNotNullException } from 'oak-domain/lib/types';
import { pipeline } from 'oak-domain/lib/utils/executor';
const checkers = [
{
// 退款所在的pay一定是可以退款状态且其上不能有另一个正在退款的请求
entity: 'refund',
type: 'row',
filter: {
pay: {
refundable: true,
refund$pay: {
'#sqp': 'not in',
iState: 'refunding',
}
},
},
action: 'create',
errMsg: 'error::refund.create.hasAnotherRefunding',
},
{
entity: 'refund',
action: 'succeed',
type: 'logicalData',
checker(operation, context) {
const { data, filter } = operation;
const { externalId } = data;
// 当offline退款成功时必须有ExternalId
if (!externalId) {
return pipeline(() => context.select('refund', {
data: {
id: 1,
pay: {
id: 1,
entity: 1,
},
},
filter: {
id: filter.id,
}
}, { dontCollect: true }), (refunds) => {
const [refund] = refunds;
if (refund.pay.entity === 'offlineAcount') {
throw new OakAttrNotNullException('refund', ['externalId']);
}
});
}
}
},
{
entity: 'refund',
action: 'fail',
type: 'logicalData',
checker(operation, context) {
const { data, filter } = operation;
const { reason } = data;
// 必须有reason除非是account类型的支付
if (!reason) {
return pipeline(() => context.select('refund', {
data: {
id: 1,
pay: {
id: 1,
entity: 1,
},
},
filter: {
id: filter.id,
}
}, { dontCollect: true }), (refunds) => {
const [refund] = refunds;
if (refund.pay.entity !== 'account') {
throw new OakAttrNotNullException('refund', ['reason']);
}
});
}
}
},
];
export default checkers;