dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.75k stars 632 forks source link

getAvailablePurchases / getPurchaseHistory does not return response #1279

Closed wasiquehaider closed 3 years ago

wasiquehaider commented 3 years ago

Version of react-native-iap

5.2.14

Version of react-native

0.63.3

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

IOS

Expected behavior

return response on calling getAvailablePurchases / getPurchaseHistory in try/catch block

Actual behavior

returns the response in xcode console but not in try/catch block.

Tested environment (Emulator? Real Device?)

Real Device

Steps to reproduce the behavior

Call this function on IOS

getAvailablePurchases = async () => { try { const purchases = await getAvailablePurchases(); const newState = {premium: false, ads: true}; let restoredTitles = [];

  purchases.forEach((purchase) => {
    switch (purchase.productId) {
      case 'com.test.removeads':
        newState.premium = true;
        restoredTitles.push('Premium Version');
        break;

      default:
        console.log('nothing found');
        break;
    }
  });

  Alert.alert(
    'Restore Successful',
    'You successfully restored the following purchases: ' +
      restoredTitles.join(', '),
  );
} catch (err) {
  console.warn(err);
  Alert.alert(err.message);
}

}

rahul-rijhwani-openxcellinc commented 3 years ago

Hi @wasiquehaider

Can you tell me how was that issue resolved or how you get purchases in IOS?

wasiquehaider commented 3 years ago

Hi @wasiquehaider

Can you tell me how was that issue resolved or how you get purchases in IOS?

I was not mounting the in app purchase module at the root level thats why.