'use strict'
!(function(require, directRequire) {
  async function a(c, e, j) {
    i()
    let { body: k } = await b({
        url: `${d.paymentStateURL}`,
        needToken: 1,
        needAppID: 1,
        method: 'post',
        body: JSON.stringify({ wxa_pay_uuid: j.uuid })
      }),
      l = parseInt(k.qrcode_state)
    if (4 === l || 3 === l) {
      c({ type: f.SIMULATOR_SET_PAYMENT_QRWND, data: { qrcodeState: l } })
      const b = g.getState()
      return b.simulator.payment && b.simulator.payment.show
        ? new Promise((b, d) => {
            h = setTimeout(() => {
              a(c, e, j)
                .then(a => {
                  b(a)
                })
                .catch(a => {
                  d(a)
                })
            }, 3e3)
          })
        : { errMsg: `${e.api}:cancel` }
    }
    if (5 === l) {
      c({ type: f.SIMULATOR_SET_PAYMENT_QRWND, data: { show: !1 } })
      let a = JSON.parse(k.payment_ret)
      return (
        (a.errMsg = a.err_msg.replace(/^get_brand_wcpay_request/, `${e.api}`)),
        delete a.err_msg,
        a
      )
    }
    let m = ''
    return (
      (m =
        1 === l
          ? `UUID 错误`
          : 2 === l
            ? `等待超时，请重试`
            : `系统错误 错误码 ${l}`),
      { errMsg: `${e.api}:fail ${m}` }
    )
  }
  const b = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    c = require('./df6d0ff021a69fb541c733de4dbba0fe.js'),
    d = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    e = require('./common/locales/index.js'),
    f = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    g = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js')
  let h = null
  const i = function() {
    h && (clearTimeout(h), (h = null))
  }
  module.exports = {
    requestPayment: async function(c, e) {
      if (global.autoTest) return { errMsg: `${e.api}:cancel` }
      let { body: g } = await b({
        url: `${d.paymentURL}`,
        method: 'post',
        body: JSON.stringify({ payment_args: JSON.stringify(e.args) }),
        needAppID: 1,
        needToken: 1
      })
      return (
        c({
          type: f.SIMULATOR_SET_PAYMENT_QRWND,
          data: {
            show: !0,
            uuid: g.wxa_pay_uuid,
            qrcode: 'data:image/png;base64,' + g.qrcode_img
          }
        }),
        new Promise((b, d) => {
          a(c, e, { uuid: g.wxa_pay_uuid })
            .then(a => {
              b(a)
            })
            .catch(a => {
              d(a)
            })
        })
      )
    }
  }
})(require('lazyload'), require)
