React-native-iap: Buying the same product twice will give an error

Created on 18 Apr 2018  ·  5Comments  ·  Source: dooboolab/react-native-iap

Version of react-native-iap

0.3.13

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

iOS

Expected behavior

Expected to buy a product without an issues

Actual behavior

First time I buy a product_A on a "new" device - it works.
Second time I try to buy the same product_A (no matter if I restart the app or not)
will not work. The error message is: "An unknown or unexpected error has occurred. Please try again later."

Steps to reprodue the behabior

1.Implement IAP as in ReadME. Try to buy an item with this code:

try {
      const msg = await RNIap.prepare()
      const products = await RNIap.getProducts([`${productId}`])
      const purchase = await RNIap.buyProduct(productId)
      this.props.purchaseCoinsPack(coinsPack)
      await RNIap.consumePurchase(purchase.transactionReceipt)
    } catch (err) {
      alert(err.message);
    }

_Just in case I have this code in my componentDidMount() and componentWillUnmount():_

getPurchases = async () => {
    try {
      const purchases = await RNIap.getAvailablePurchases();
      purchases.forEach(async purchase => {
        const boughtPack = R.find(R.propEq('androidStoreId', purchase.productId))(this.props.coinsPacks)
        if (boughtPack) {
          this.props.purchaseCoinsPack(boughtPack);
          await RNIap.consumePurchase(purchase.transactionReceipt);
        }
      })
    } catch (err) {
      console.warn(err); // standardized err.code and err.message available
    } finally {
      this.setState({ isLoading: false })
    }
  }

  async componentDidMount() {
    try {
      await RNIap.prepare()
    } catch (err) {
      console.warn(err);
    }
    this.getPurchases()
  }

  async componentWillUnmount() {
    RNIap.endConnection()
  }

2.First buy works ok. Try to buy same product once again
Get an alert with ""An unknown or unexpected error has occurred. Please try again later."

Most helpful comment

latest v0.3.15 will give you the error code with a message.
So can you please try the latest release again and what the error code is?
If the error code is -1001, it might be a temporary sandbox's issue from Apple.
I will look this issue as well.

All 5 comments

Is the product consumable or non-consumable?

@JJMoon consumable.
2018-04-19_07h40_09

latest v0.3.15 will give you the error code with a message.
So can you please try the latest release again and what the error code is?
If the error code is -1001, it might be a temporary sandbox's issue from Apple.
I will look this issue as well.

After the update to 0.3.15 the issue disappeared on iOS.
Android also works great.
Thank you!

Good to hear that!
It may be a temporary issue from Apple since new release did not change anything but the log.
There have been so many problems when we test with the sandbox.
Most cases do not happen in production released by App Store.

Was this page helpful?
0 / 5 - 0 ratings