I'm working on an app that offers different one-time payment products.
I’ve got a product (remove_ads) tied to an "entitlement" that removes ads from the app forever. I tested it, and it’s working great with the code:
try {
final premiumProduct = _products?.firstWhere((element) => element.identifier == 'remove_ads');
if (premiumProduct == null) return false;
final customerInfo = await Purchases.purchaseStoreProduct(premiumProduct);
if (customerInfo.entitlements.all["remove_ads"]?.isActive ?? false) {
_isPremium = true;
return true;
} else {
return false;
}
} catch (e) {
return false;
}
Now, I need to add new products (coins_100, coins_500, and coins_1000) that aren’t linked to any "entitlement." I just want them to be consumed immediately after purchase using Purchases.purchaseStoreProduct.
Future<bool> buyProduct(StoreProduct product) async {
try {
final customerInfo = await Purchases.purchaseStoreProduct(product);
// How to check if the purchase was successful?
} catch (e) {
return false;
}
}
But I haven’t been able to find any practical examples on how to do this since the codes I’ve seen always use customerInfo.entitlements to check the purchase status.
Can someone shed some light on how to handle this scenario?