/* eslint-disable prefer-promise-reject-errors */

/* eslint-disable arrow-parens */
function tradePay(alipayTradeNo, orderId) {
  return new Promise((resolve, reject) => {
    my.tradePay({
      tradeNO: alipayTradeNo,

      success(payRes) {
        // 4000 订单处理失败
        // 6001 用途中途取消支付
        // 6002 网络链接出错
        if (payRes.resultCode === '4000' || payRes.resultCode === '6002' || payRes.resultCode === '6001') {
          // 支付失败
          return reject({
            msg: '订单支付失败',
            type: 'cancel'
          });
        }

        return resolve({
          msg: '支付成功',
          orderId
        });
      },

      fail: () => // 订单支付异常
      reject({
        msg: '订单支付失败',
        type: 'cancel',
        orderId
      })
    }); // setTimeout(() => {
    //   return resolve({ msg: '查询支付', orderId });
    // }, 15000);
  });
}

export default {
  tradePay
};