Solved

Entitlements not showing up when calling Purchases.purchasePackage

  • 3 November 2021
  • 2 replies
  • 237 views

Badge +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.');
      }
    }

 

 

icon

Best answer by ryan 5 November 2021, 19:03

View original

2 replies

Userlevel 5
Badge +9

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.

Badge +2

Yes this makes perfect sense. Thank you.

Reply