react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

invalid Product ID and empty product list array

Open pouya92 opened this issue 7 years ago • 1 comments

Version of react-native-iap

3.3.9

Version of react-native

0.59.6

Platforms you faced the error (IOS or Android or both?)

IOS

Expected behavior

I expect to get an array of products in Appstore.

Actual behavior

it will return an empty array

Tested environment (Emulator? Real Device?)

both

Steps to reproduce the behavior

I followed excactly as you mentioned in you documents after activating in-app purchase in X-code I tried to import library with : this line in my store component:

import * as RNIap from 'react-native-iap';

const itemSkus = Platform.select({
  ios: [
    'com.example.myAppBundleName'
  ],
  android: [
    'com.example.myAppBundleName'
  ]
});

and in componentDidMount lifecycle I tried to get product list as follow:

try {
      const products: Product[] = await RNIap.getProducts(itemSkus);
     console.log('products', products)
    } catch(err) {
      console.warn(err); // standardized err.code and err.message available
    }

I allways get empty array. I also put listeners to my root component as you mentioned in document. Moreover, when I try to request a purchase directly with inputing productID it will show me invalid productID :

requestPurchase = async (productID) => {
    try {
      await RNIap.requestPurchase(productID, false);
    } catch (err) {
      console.warn(err.code, err.message);
    }
  }

pouya92 avatar Aug 21 '19 11:08 pouya92

I made a mistake, I tought in itemSkus I just need to set my bundleName but it was wrong, it needs to set all product's id as an array and seperated with ',' like this:

const itemSkus = Platform.select({
  ios: [
    'product_id_1',
    'product_id_2,
  ],
  android: [
    'product_id_1',
    'product_id_2,
  ]
});

and after doing this every thing works perfect.

pouya92 avatar Aug 22 '19 05:08 pouya92