Question

Purchases.getProducts returns empty array

  • 16 January 2024
  • 1 reply
  • 115 views

Badge

I believe I have configured everything correctly, but I am unable to purchase on Android.

I have followed everything shown in this link 'https://community.revenuecat.com/sdks%2D51/why%2Dare%2Dofferings%2Dor%2Dproducts%2Dempty%2D124' but it still doesn't work.

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]

 

Products
Offerings


 

Entitlements

 

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? 

I'm assuming this string is correct because it works for apple and I've been told that it's the same on the google play side. i'm asking to confirm. Where can I get this?

2- I don't think I have missed a step; I have double-checked multiple times. What should I do?


1 reply

Userlevel 4
Badge +8

Hi, the value inside Purchases.getProducts() ‘dk_story_token’ is the product that you want to purchase. This string is the product id of the product you have created in Google Play Console that is also the product id in RevenueCat. 

Looking at your setup, the problem might be that your product test3 is not in RevenueCat. Could you try adding this and see if it works?

If not, then can you please enable RevenueCat SDK’s debug logs and send the entirety here so I may see what is happening there. You can enable them following our guide here: https://www.revenuecat.com/docs/debugging#section-debugging

Reply