Skip to main content
Solved

Entitlements not properly working?

  • February 27, 2023
  • 2 replies
  • 262 views

Forum|alt.badge.img+3

I have the following code, essentially straight from the documentation using react-native-purchases

 

const PackageItem = ({ purchasePackage, setIsPurchasing, styles }) => {

const {

product: { title, description, priceString },

} = purchasePackage;

 

const navigation = useNavigation();

 

const onSelection = async () => {

setIsPurchasing(true);

console.log('being Purchase');

try {

const { purchaserInfo } = await Purchases.purchasePackage(purchasePackage);

console.log('try purchase...');

if (typeof purchaserInfo.entitlements.active['Pro'] !== 'undefined') {

console.log('User has All Access');

// navigation.goBack();

}

} catch (e) {

if (!e.userCancelled) {

console.log('error: ', e);

Alert.alert('Error purchasing package', e.message);

}

} finally {

setIsPurchasing(false);

}

};

```

 

When I click on the subscribe button, I go through the dialogue and sign in and the subscription starts to process.  However, once it begins to finish the transaction, it stops at the 

```

if (typeof purchaserInfo.entitlements.active['Pro'] !== 'undefined') {

```

line and returns the following error:

```

[TypeError: undefined is not an object (evaluating 'purchaserInfo.entitlements')]

```

The entitlement that I have my products and offerings under is called ‘Pro’, so I’m not sure why this error is getting returned.  

Best answer by Michael_Schmitz

Seems like the example for react-native in the weather app is not up to date.  Needed to do 

 

try {

// const { purchaserInfo } = await Purchases.purchasePackage(purchasePackage);

const { customerInfo, productIdentifier } = await Purchases.purchasePackage(purchasePackage);

 

console.log('try purchase...');

if (typeof customerInfo.entitlements.active['Pro'] !== 'undefined') {

console.log('User has All Access');

// navigation.goBack();

}

Rather than what was above, should probably update that

 

View original
Did this post help you find an answer to your question?
This post has been closed for comments

2 replies

Forum|alt.badge.img+3

Seems like the example for react-native in the weather app is not up to date.  Needed to do 

 

try {

// const { purchaserInfo } = await Purchases.purchasePackage(purchasePackage);

const { customerInfo, productIdentifier } = await Purchases.purchasePackage(purchasePackage);

 

console.log('try purchase...');

if (typeof customerInfo.entitlements.active['Pro'] !== 'undefined') {

console.log('User has All Access');

// navigation.goBack();

}

Rather than what was above, should probably update that

 


kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 399 replies
  • March 1, 2023

Hi @Michael_Schmitz ! Thanks for updating with what worked for you - I’ll take a look at our documentation and the sample app and make updates as needed! Appreciate it!


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