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

82 lines
2.7 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.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("oak-domain/lib/types");
const executor_1 = require("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 (0, executor_1.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 types_1.OakAttrNotNullException('refund', ['externalId']);
}
});
}
}
},
{
entity: 'refund',
action: 'fail',
type: 'logicalData',
checker(operation, context) {
const { data, filter } = operation;
const { reason } = data;
// 必须有reason除非是account类型的支付
if (!reason) {
return (0, executor_1.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 types_1.OakAttrNotNullException('refund', ['reason']);
}
});
}
}
},
];
exports.default = checkers;