oak-pay-business/lib/watchers/pay.js

73 lines
2.1 KiB
JavaScript
Raw 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 pay_1 = require("../utils/pay");
const operationResult_1 = require("oak-domain/lib/utils/operationResult");
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 600 * 1000 : 60 * 1000;
const watchers = [
{
name: '对paying状态的订单同步其真实支付状态',
entity: 'pay',
filter: async () => {
const now = Date.now();
return {
iState: 'paying',
$$updateAt$$: {
$lte: now - QUERY_PAYING_STATE_GAP,
},
externalId: {
$exists: true,
}
};
},
projection: pay_1.fullPayProjection,
fn: async (context, data) => {
const results = [];
for (const pay of data) {
const result = await (0, pay_1.refreshPayState)(pay, context);
if (result) {
results.push(result);
}
}
if (results.length === 0) {
return {};
}
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
}
},
{
name: '当pay达到禁止退款期限时关闭退款允许',
entity: 'pay',
filter: () => {
const now = Date.now();
return {
refundable: true,
forbidRefundAt: {
$lte: now,
},
};
},
action: 'closeRefund',
actionData: {
refundable: false,
}
},
{
name: '当pay达到禁止退款期限时关闭退款允许',
entity: 'pay',
filter: () => {
const now = Date.now();
return {
iState: {
$in: ['unpaid', 'paying'],
},
timeoutAt: {
$lt: now,
},
};
},
action: 'close',
actionData: {},
}
];
exports.default = watchers;