Skip to main content
Question

nonSubscription: how to get status from purchaseStoreProduct?

  • 20 August 2024
  • 1 reply
  • 8 views

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?

Hi @nathanael540,

Your no ads entitlement it’s a great example on how to use entitlements in the right way!

For your new features, since it’s about applying coins to a user’s account, you shouldn’t be using entitlements. The ideal scenario would be to listen to webhook events; your backend should be listening to our webhooks and whenever a purchase happens, you add the credits to that user’s account. You could use your own backend or use a Firebase integration as well.

 

Let me know if this works!