Question

React Native Purchase 6.3.0 check subscription status not working as outlined in documentation. Please check my implementation?

  • 23 July 2023
  • 2 replies
  • 106 views

Badge +1

Following the documentation instructions located here on this RevenueCat “checking-if-a-user-is-subscribed” page i’ve been unable to async verify is a user is already subscribed.  My code is as follows:

```
const checkIfPurchased = async () => {

try {

await Purchases.configure({ apiKey: APIKeys.apple });

await Purchases.syncPurchases();

const customerInfo = await Purchases.getCustomerInfo();

const ENTITLEMENT_ID = 'app_199_1m';

if (

typeof customerInfo.entitlements.active[ENTITLEMENT_ID] !== 'undefined'

) {

setSubscription(true);

}

return user?.subscription;

} catch (e) {

Bugsnag.notify(`Error checkIfPurchased(): ${e}`);

}

};

this does not work.  I get undefined for customerInfo.entitlements.active[ENTITLEMENT_ID] . What am I missing?


2 replies

Badge +1

Turns out that the entitlement ID in this case is actually “Premium” not the product ID.

const checkIfPurchased = async () => {

try {

await Purchases.configure({ apiKey: APIKeys.apple });

await Purchases.syncPurchases();

const customerInfo = await Purchases.getCustomerInfo();

const ENTITLEMENT_ID = 'Premium'; // ** <--- THIS LINE IS DIFFERENT 

if (

typeof customerInfo.entitlements.active[ENTITLEMENT_ID] !== 'undefined'

) {

setSubscription(true);

}

return user?.subscription;

} catch (e) {

Bugsnag.notify(`Error checkIfPurchased(): ${e}`);

}

};

The product ID is entered in the Apple App Store and can also be found in the `customerInfo` object, inside the property `customerInfo.activeSubscriptions`.

However it is better to use the entitlement ID so you can have different entitlements that are associated with various products.

Userlevel 4
Badge +8

Hi, glad to hear you figured it out! Yes, you’ll want to make sure that your entitlement being checked is the entitlement’s identifier and not the product id, and that it must be exactly the same as it is sensitive.

Reply