"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); const dayjs_1 = tslib_1.__importDefault(require("dayjs")); class Offline { offlineAccount; constructor(offlineAccount) { this.offlineAccount = offlineAccount; } getAccountEntity() { return ['offlineAccount', this.offlineAccount.id]; } async getAccountAmount(context) { const [offlineAccount] = await context.select('offlineAccount', { data: { id: 1, price: 1, }, filter: { id: this.offlineAccount.id, }, }, { dontCollect: true }); return offlineAccount.price; } calcTransferTax(price) { const { allowWithdrawTransfer, withdrawTransferLossRatio } = this.offlineAccount; (0, assert_1.default)(allowWithdrawTransfer); if (typeof withdrawTransferLossRatio !== 'number') { throw new Error('渠道的withdrawTransferLossRatio未设置'); } return [Math.round(price * withdrawTransferLossRatio / 100), 'offlineAccount', this.offlineAccount.id]; } calcRefundTax(price) { const { taxLossRatio, refundCompensateRatio } = this.offlineAccount; // 返回taxLossRatio * refundCompensateRatio / 100 if (typeof refundCompensateRatio !== 'number') { throw new Error('渠道的refundCompensateRatio未设置'); } const value = Math.round(price * taxLossRatio * refundCompensateRatio / 100 / 100); return [-value, 'offlineAccount', this.offlineAccount.id]; } calcPayTax(price) { const { taxLossRatio } = this.offlineAccount; return [taxLossRatio ? Math.round(price * taxLossRatio / 100) : 0, 'offlineAccount', this.offlineAccount.id]; } getRefundableAt(successTime) { const { refundGapDays } = this.offlineAccount; return refundGapDays ? (0, dayjs_1.default)(successTime).add(refundGapDays, 'day').subtract(12, 'hour').valueOf() : 0; } async refund(refund) { // 啥也不做 return; } async getRefundState(refund) { const { iState } = refund; (0, assert_1.default)(iState === 'refunding'); return [iState, undefined]; } decodePayNotification(params, body) { throw new Error("offline类型的pay不需调用此接口"); } decodeRefundNotification(params, body) { throw new Error("offline类型的pay不需调用此接口"); } async prepay(pay, data, context) { data.phantom3 = Math.ceil(Math.random() * 1000000); return; } async getState(pay) { const { iState } = pay; (0, assert_1.default)(iState === 'paying'); return [iState, {}]; } async close(pay) { return; } } exports.default = Offline;