androidreact-nativerevenuecatandroid-inapp-purchase

Purchases.getProducts returns empty array with revenueCat


I had also asked this question on the RevenueCat forum, but I felt the need to ask it here as well. https://community.revenuecat.com/general-questions-7/purchases-getproducts-returns-empty-array-3899

I can make purchases on the iOS side without any issues, but as indicated in the logs on Android, the list is coming up empty.

enter image description here

Configure

  if (Platform.OS === 'ios') {

   try {

   Purchases.configure({

   apiKey: REVENUE_CAT_IOS_API_KEY,

   appUserID: user?.uid,

   })

   } catch (error) {

   console.error('error configuring revenuecat for iOS', error)

   await analytics().logEvent('error_configuring_revenuecat_for_ios')

   }

   } else if (Platform.OS === 'android') {

   try {

    Purchases.configure({

    apiKey: REVENUE_CAT_ANDROID_API_KEY,

    appUserID: user?.uid,

  })

 } catch (error) {

  console.error('error configuring revenuecat for Android', error)

  await analytics().logEvent('error_configuring_revenuecat_for_android')

 }

}

 

This is where I am trying to fetch the products.

  const purchaseStoryToken = async () => {
    try {
      useSetLoading(true)

      const products = await Purchases.getProducts(['dk_story_token'])
      console.log('fetched products', products)
      const storyTokenProduct = products?.[0]
      console.log('storyTokenProduct', storyTokenProduct)

      await Purchases.purchaseStoreProduct(storyTokenProduct)
    } catch (e) {
      analytics().logEvent('error_purchasing_product')
      console.log('error in purchaseStoryToken', e)
      throw e
    } finally {
      useSetLoading(false)
    }
  }
 LOG  fetched products []
 LOG  storyTokenProduct undefined
 LOG  error in purchaseStoryToken [TypeError: Cannot read property 'identifier' of undefined]

Revenue Cat Products

Revenue-cat Offerings

Revenue-cat Entitlements

Google play console In-App products I have

Subscriptions

enter image description here

enter image description here

I created APK and tested it on a real device as well as on the simulator. The result is the same.

I might have overlooked something, please allow me to know if more information is needed.

Questions: 1- Where should the 'dk_story_token' inside the 'Purchases.getProducts(['dk_story_token'])' code exactly come from? Where can I retrieve this information, within the Google Play Console or in Revenue Car's dashboard? Where did this string come from?

As seen in the first screenshot I provided, the 'dk_story_token' is present in the Apple Developer Console for in-app purchases, which is why I can make purchases on iOS. However, I cannot do the same on Android.

Shouldn't it be present and functional in the 'In-app Products' section that I created on Android? Why is this array coming up empty?


Solution

  • I have been using "getOfferings" and "getCustomerInfo" instead of "getProducts" and it is working.

    import Purchases from "react-native-purchases";
    
    // ... getPlatformKey
    const apiKey = getPlatformKey();
    Purchases.configure({ apiKey });
    
    async function getPackages() {
      try {
        const offerings = await Purchases.getOfferings();
        const packages = offerings?.current?.availablePackages || [];
    
        // ... rest and catch     
      }
    }
    
    async function getActivePlans() {
      try {
        const results = await Purchases.getCustomerInfo();
        const customerInfo = results?.customerInfo || results;
        const activePlans = customerInfo.entitlements.active || {};
    
        // ... rest and catch 
      }
    }
    
    async function purchasePkg(pkg) {
      // pkg of packages form getPackages
      try {
        const results = await Purchases.purchasePackage(pkg);
    
        // ... rest and catch 
      }
    }