Solved

Entitlements not properly working?

  • 27 February 2023
  • 2 replies
  • 122 views

Badge +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.  

icon

Best answer by Michael_Schmitz 27 February 2023, 18:33

View original

2 replies

Badge +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

 

Userlevel 4
Badge +6

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!

Reply