Skip to main content
Solved

Entitlements not showing up when calling Purchases.purchasePackage

  • 3 November 2021
  • 2 replies
  • 451 views

Forum|alt.badge.img+2

I have several offerings setup and my code looks similar to the example for react native although there is an extra error handle as not all cases are handled in the doc example (please see below)

What is happening is that I make the purchase, I get a pop up saying “You’re all set - your purchase was successful” but then the code checks typeof purchaserInfo.entitlements.active[this.props.sku] !== 'undefined' and its undefined. So for some reason the purchase is happening but I’m not getting it added to my active entitlements. This error only happens around 50% of the time, so the fact it works sometimes has made it impossible to debug.

    try {
      const { purchaserInfo, productIdentifier } = await Purchases.purchasePackage(this.state.package);
      if (typeof purchaserInfo.entitlements.active[this.props.sku] !== 'undefined') { 
        this.completePurchase(this.props.sku); //Add to our database
      } else {
        Alert.alert('Oops!', 'We ran into an issue... please try again later.');
      }

    } catch (e) {
      if (e.userCancelled) {
        Alert.alert('Cancelled');
      }
      if (!e.userCancelled) {
        Alert.alert('Oops!', 'There was an issue contacting the store, please try again later.');
      }
    }

 

 

Best answer by ryan

Hey @NETFIT NZ!

It looks like you may be crossing up your Entitlement IDs and Product IDs. Typically, apps will just have one Entitlement, like “premium”, that all of your subscription products would unlock. 

Then to check if the customer has access to premium your code would look more like:

typeof purchaserInfo.entitlements.active[‘premium’] !== 'undefined'

 

I think things are working when the SKU purchased matches up with the corresponding entitlement identifier. 

I would start by taking another look at this guide on configuring products and entitlements and make sure things are set up correctly: https://docs.revenuecat.com/docs/entitlements

From there, you will probably have to update your code to check for a hardcoded Entitlement ID, like “premium”, instead of a variable.

View original
Did this post help you find an answer to your question?

2 replies

ryan
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • 391 replies
  • Answer
  • November 5, 2021

Hey @NETFIT NZ!

It looks like you may be crossing up your Entitlement IDs and Product IDs. Typically, apps will just have one Entitlement, like “premium”, that all of your subscription products would unlock. 

Then to check if the customer has access to premium your code would look more like:

typeof purchaserInfo.entitlements.active[‘premium’] !== 'undefined'

 

I think things are working when the SKU purchased matches up with the corresponding entitlement identifier. 

I would start by taking another look at this guide on configuring products and entitlements and make sure things are set up correctly: https://docs.revenuecat.com/docs/entitlements

From there, you will probably have to update your code to check for a hardcoded Entitlement ID, like “premium”, instead of a variable.


Forum|alt.badge.img+2
  • Author
  • New Member
  • 1 reply
  • November 6, 2021

Yes this makes perfect sense. Thank you.


Reply


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