import { PayMethodCode } from "../../types";
export var isEftposPay = function isEftposPay(code) {
  return [PayMethodCode.EFTPOS_PAYO, PayMethodCode.EFTPOS_TYRO, PayMethodCode.EFTPOS_WINDCAVE, PayMethodCode.EFTPOS_LINKLY].includes(code);
};

/**
 * @title: 处理eftpos支付
 * @description: 处理eftpos支付
 * @param {any} action 引擎action
 * @param {any} params 参数
 * @param {any} successCallback 成功回调
 */
export var handleEftposPay = function handleEftposPay(action, params, successCallback) {
  var payMethod = params.payMethod,
    order = params.order,
    symbol = params.symbol,
    network = params.network,
    type = params.type;
  console.log('tob_pay_handleEftposPay', params);
  action === null || action === void 0 || action({
    type: 'pisell1.handleEftposPaySource',
    data: 'normal',
    callback: function callback() {}
  });
  action === null || action === void 0 || action({
    type: 'pisell1.openEftposPay',
    data: {
      code: payMethod.code,
      terminal: {
        network: network.online
      },
      apiParams: {
        order_id: order === null || order === void 0 ? void 0 : order.id,
        name: (payMethod === null || payMethod === void 0 ? void 0 : payMethod.name) || '',
        symbol: symbol,
        amount: (order === null || order === void 0 ? void 0 : order.expect_amount) || '0.00'
      },
      visible: true,
      mode: type ? type : 'pay'
    },
    callback: function callback(_ref) {
      var status = _ref.status,
        params = _ref.params;
      console.log('tob_pay_openEftposPay_callback', status, params);
      // TODO: shop中的代码是否需要完整的搬运过来？
      if (status === 'success') {
        var result = {
          amount: Number(params === null || params === void 0 ? void 0 : params.amount),
          // 支付金额
          code: payMethod.code,
          // 支付类型code
          id: payMethod.id,
          // 支付类型id
          name: payMethod.name,
          // 支付类型name
          type: payMethod.type,
          // 支付类型type
          voucher_id: '',
          // 手续费配置信息
          service_charge: {
            percentage: params === null || params === void 0 ? void 0 : params.surPercentRate,
            amount: params === null || params === void 0 ? void 0 : params.surMoney
          },
          metadata: {
            unique_payment_number: params === null || params === void 0 ? void 0 : params.uniquePaymentNumber
          }
        };
        successCallback === null || successCallback === void 0 || successCallback({
          result: result,
          status: status,
          params: params
        });
      }
    }
  });
};