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

IOS buyProduct() worked without problem, but getAvailablePurchase() returns empty array #1155

Closed Darmaa-YoLo closed 3 years ago

Darmaa-YoLo commented 3 years ago

Version of react-native-iap

2.4.8

Version of react-native

0.58.3

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

IOS

Expected behavior

return previous receipt

Actual behavior

return empty array

Tested environment (Emulator? Real Device?)

real device

Steps to reproduce the behavior

when i try to buy again it says "You've subscribed to This in the past" is it possible to connect iTunes to restore purchases of my non-renewable item

my buy method:

async inAppPurchase(productId) { try { this.setState({ isLoading: true }); await RNIap.clearTransaction() const purchase = await RNIap.buyProduct(productId) .then(async (purchase) => { await this.setState({ isLoading: false }); if (this.state.isLogged) { this._inAppPurchase(purchase.transactionId, purchase.transactionReceipt); } let date = moment.unix(purchase.transactionDate / 1000).format('LLL'); console.warn('date: ', date); if (purchase.productId === productId) { Storage.setStoreItem('restoredPurchase', purchase); this.setState({ restoredPurchase: purchase }); } await RNIap.finishTransaction() }) } catch (e) { Alert.alert( ${lang['Уучлаарай'][global.lang]}, ${e.message}, [{ text: 'OK', onPress: () => this.setState({ isLoading: false }) }], { cancelable: false } ); } }

my restore method:

async _inAppPurchaseRestore(){ if(Platform.OS==='ios'){ this.setState({ isLoading: true }); const possible = await RNIap.initConnection(); // await RNIap.consumeAllItems(); if(possible){ const purchases = await RNIap.getAvailablePurchases().then((purchases)=>{

      console.warn(purchases)
      purchases.forEach(purchase => {
        switch (purchase.productId) {
          case 'product_id':
            console.warn(purchase.transactionId);
            this._inAppPurchase(purchase.transactionId, purchase.transactionReceipt);
            break;
          default:
            break;
        }
      });
      this.setState({ isLoading: false });

    }).catch((e)=>{
      Alert.alert(
        `${lang['Уучлаарай'][global.lang]}`,
        `${e.message}`,
        [{ text: 'OK', onPress: () => this.setState({ isLoading: false }) }],
        { cancelable: false }
      )
    });
  }
}

}

hyochan commented 3 years ago

Have you seen this? https://github.com/dooboolab/react-native-iap#getavailablepurchases-returns-empty-array

stale[bot] commented 3 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.