checkInPayPurchase method
Future
checkInPayPurchase(
- String? token,
- String? orderId,
- String? productID, {
- String? sign,
- String? price,
- bool first = false,
- bool refresh = false,
- PurchaseDetails? purchaseDetail,
- int index = 1,
- int indexNum = 1,
- int indexNumNext = 1,
})
Implementation
Future checkInPayPurchase(String? token, String? orderId, String? productID,
{String? sign,
String? price,
bool first = false,
bool refresh = false,
PurchaseDetails? purchaseDetail,
int index = 1,
int indexNum = 1,
int indexNumNext = 1}) async {
String? baseToken = SpUtil.getString(AppConfig.appToken);
if (baseToken?.isEmpty == false) {
await RechargeDao.rechargeInCheck(token, sign, productID: productID)
.then((res) async {
timer?.cancel();
if (res.result) {
this.orderId = '';
bool show = popDialog();
if ((res.data.addMoney?.compareTo('0') ?? 0) > 0) {
if (show) {
delegate.showToast(3, true);
}
clearRechargeList();
delegate.logEvent('${payInType ?? ''}加币成功');
} else {
delegate.logEvent('${payInType ?? ''}重复加币');
}
delegate.rechargeSuccess(res.data.money, res.data.addMoney, price);
SpUtil.putString(RechargeConfig.inappToken, '');
SpUtil.putString(RechargeConfig.inappSign, '');
SpUtil.putString(RechargeConfig.inappOrderId, '');
SpUtil.putString(RechargeConfig.inappPrice, '');
SpUtil.putString(RechargeConfig.inappCode, '');
if (purchaseDetail != null) {
completePurchaseInPay(purchaseDetail);
} else if (Platform.isAndroid) {
queryPastPurchases();
} else {
paymentQueueWrapper(payId: productID, delayed: false);
}
} else if (res.data.code == '1068' && Platform.isIOS) {
if (refresh) {
delegate.logEvent('服务器1068清空本地缓存');
SpUtil.putString(RechargeConfig.inappToken, '');
SpUtil.putString(RechargeConfig.inappSign, '');
SpUtil.putString(RechargeConfig.inappOrderId, '');
SpUtil.putString(RechargeConfig.inappPrice, '');
SpUtil.putString(RechargeConfig.inappCode, '');
} else if (index == 1) {
queryPastPurchases();
} else {
popDialog();
showInPay = true;
delegate.showDialogBase(2).then((value) async {
showInPay = false;
if (value == true) {
queryPastPurchases();
}
});
}
} else {
delegate.logEvent('支付重试$index');
try {
rechargeError = res.data?.msg;
} catch (e) {
AppConfig.printLog(e);
}
var connectivityResult = await (Connectivity().checkConnectivity());
AppConfig.printLog(
'支付失败重试: $index, 时间: ${index > 2 ? indexNum + indexNumNext : indexNumNext}');
if (connectivityResult == ConnectivityResult.none ||
index >= maxIndex) {
delegate.showErrorToast(res);
popDialog();
showInPayDialog(token, orderId, productID,
sign: sign,
price: price,
showLeft: !first,
restored: purchaseDetail?.status == PurchaseStatus.restored);
} else {
timer = Timer(
Duration(
seconds: index > 2
? indexNum + indexNumNext
: indexNumNext), () async {
checkInPayPurchase(token, orderId, productID,
sign: sign,
price: price,
first: first,
purchaseDetail: purchaseDetail,
index: index + 1,
indexNum: indexNumNext,
indexNumNext:
index > 2 ? indexNum + indexNumNext : indexNumNext);
});
}
}
});
} else {
delegate.logEvent('支付成功token空');
}
}