checkPurchase static method
Checks previous purchases and queries product details.
Calls onCompleted
with true
if unlock feature is purchased.
Implementation
static Future<void> checkPurchase({void Function(bool)? onCompleted}) async {
var unlockFeature = false;
try {
final addition = _iap.getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
final purchases = await addition.queryPastPurchases();
unlockFeature = purchases.pastPurchases.any(
(purchase) => purchase.productID == inAppUnlockFeature,
);
if (!await _iap.isAvailable()) {
return;
}
final Set<String> idList = {inAppUnlockFeature};
final response = await _iap.queryProductDetails(idList);
if (response.error != null) {
LoggerUtil.d('Error fetching product details: ${response.error}');
} else {
products = response.productDetails;
}
} catch (e) {
LoggerUtil.d('Error in checkPurchase: $e');
} finally {
onCompleted?.call(unlockFeature);
}
}