connectionInPayVip method
Implementation
void connectionInPayVip(String id, String? payId, String price) async {
if (await checkInPay(first: false) == false && !showLoading) {
if (!showLoading) {
showLoading = true;
delegate.showLoadingDialog();
}
final bool isAvailable = await connection.isAvailable();
if (isAvailable) {
Set<String> _kProductIds = {payId!};
ProductDetailsResponse productDetailResponse =
await connection.queryProductDetails(_kProductIds);
if (productDetailResponse.error == null) {
List<ProductDetails> products = productDetailResponse.productDetails;
if (products.isNotEmpty) {
bool buy = false;
try {
PurchaseParam purchaseParam =
PurchaseParam(productDetails: products[0]);
buy = await connection.buyNonConsumable(
purchaseParam: purchaseParam);
AppConfig.printLog('buyNonConsumable: $buy');
if (buy) {
orderId = '';
payPrice = price;
SpUtil.putString(RechargeConfig.inappOrderId, orderId!);
SpUtil.putString(RechargeConfig.inappPrice, payPrice!);
delegate.logEvent('发起订阅');
return;
}
} catch (e) {
delegate.logEvent('发起订阅失败');
AppConfig.printLog(e);
popDialog();
showInPay = true;
delegate.showDialogBase(1).then((value) async {
showInPay = false;
if (value == true) {
queryPastPurchases(refresh: true);
}
});
RechargeDao.rechargeFailLog('', '', orderId, e.toString());
return;
}
}
}
}
delegate.logEvent('订阅不存在');
popDialog();
delegate.showToast(2);
}
}