Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RNIap.getPurchaseHistory() always returns an empty array on iOS

The RNIap.getPurchaseHistory always return an empty array. Does not matter if I call on app start or after purchase was made. In componentDidMount I do the following:

async componentDidMount() {

  await RNIap.initConnection();

  this.purchaseUpdateSubscription = purchaseUpdatedListener(
    async purchase => {
      try {
        // send purchase to the server
        const savedPurchase = await savePurchase(purchase);

        // finish transaction if server returned truthly value
        if (savedPurchase) {
          await RNIap.finishTransaction(purchase, true);

          // always returns en empty array
          console.log('Purchase history', await RNIap.getPurchaseHistory())
        }
      } catch (e) {
        console.log('Error: ', e);
      }
    }
  });
}

buyProduct function:

buyProduct = async productId => {
  try {
    await RNIap.requestPurchase(productId, false);
  } catch (e) {
    console.warn('Error: ', e);
  }
};

When the purchase is made I receive the message:

You're all set.
Your purchase was successful
[Environment: Sandbox].

Maybe the problem can be in another place not related to the codebase?

like image 407
Maksym Bezruchko Avatar asked Oct 17 '25 06:10

Maksym Bezruchko


1 Answers

Stumbled upon what I believe might be a solution for you:

Wrap RNIap.getPurchaseHistory() around initConnection() and an endConnection() call. Perhaps also give RNIap.finshTransaction more time to finish before requesting the purchase history to make sure the latest purchases are included.

// CODE 
await RNIap.initConnection();
   const purchase_history = await RNIap.getPurchaseHistory()
   console.log(purchase_history)
RNIap.endConnection()
like image 91
Erik Dreifaldt Avatar answered Oct 19 '25 22:10

Erik Dreifaldt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!