Skip to main content
Question

nonSubscription: how to get status from purchaseStoreProduct?

  • 20 August 2024
  • 1 reply
  • 15 views

Forum|alt.badge.img+2

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?

This post has been closed for comments

1 reply

joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 207 replies
  • August 22, 2024

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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings