checkPpyPurchase method

Future checkPpyPurchase(
  1. dynamic orderId, {
  2. bool show = false,
  3. int type = 0,
  4. int index = 1,
  5. int indexNum = 1,
  6. int indexNumNext = 1,
})

Implementation

Future checkPpyPurchase(orderId,
    {bool show = false,
    int type = 0,
    int index = 1,
    int indexNum = 1,
    int indexNumNext = 1}) {
  if (show && !showLoading) {
    showLoading = true;
    delegate.showLoadingDialog();
  }
  return Future.delayed(
      Duration(seconds: index > 2 ? indexNum + indexNumNext : indexNumNext),
      () async {
    return RechargeDao.rechargePpCheck(orderId).then((res) {
      if (res.result) {
        if (res.data.payed == '1') {
          popDialog();
          this.orderId = '';
          if ((res.data.addMoney?.compareTo('0') ?? 0) > 0) {
            delegate.showToast(3, true);
            clearRechargeList();
            delegate.rechargeSuccess(
                res.data.money, res.data.addMoney, payPrice);
            delegate.logEvent((type == 0 ? 'paypal' : '信用卡支付') + '加币成功');
            return 2;
          }
          delegate.rechargeSuccess(
              res.data.money, res.data.addMoney, payPrice);
          delegate.logEvent((type == 0 ? 'paypal' : '信用卡支付') + '重复加币');
          return 3;
        } else if (show && res.data.payed == '2') {
          AppConfig.printLog(
              '支付失败重试: $index, 时间: ${index > 2 ? indexNum + indexNumNext : indexNumNext}');
          delegate.logEvent((type == 0 ? 'paypal' : '信用卡支付') + '支付重试$index');
          return checkPpyPurchase(orderId,
              show: show,
              type: type,
              index: index + 1,
              indexNum: indexNumNext,
              indexNumNext:
                  index > 2 ? indexNum + indexNumNext : indexNumNext);
        } else if (!show && res.data.payed == '0') {
          popDialog();
          RechargeDao.rechargeCancel(orderId);
          this.orderId = '';
          return -1;
        } else {
          popDialog();
          this.orderId = '';
          return 0;
        }
      } else {
        try {
          rechargeError = res.data?.msg;
        } catch (e) {
          AppConfig.printLog(e);
        }
        delegate.showErrorToast(res);
      }
      popDialog();
      return 0;
    });
  });
}