Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buying the same product twice will give an error #131

Closed
Symyon opened this issue Apr 18, 2018 · 5 comments
Closed

Buying the same product twice will give an error #131

Symyon opened this issue Apr 18, 2018 · 5 comments

Comments

@Symyon
Copy link

Symyon commented Apr 18, 2018

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."

@JJMoon
Copy link
Contributor

JJMoon commented Apr 19, 2018

Is the product consumable or non-consumable?

@Symyon
Copy link
Author

Symyon commented Apr 19, 2018

@JJMoon consumable.
2018-04-19_07h40_09

@benevbright
Copy link
Contributor

benevbright commented Apr 20, 2018

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.

@Symyon
Copy link
Author

Symyon commented Apr 20, 2018

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

@benevbright
Copy link
Contributor

benevbright commented Apr 21, 2018

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.

@hyochan hyochan closed this as completed Apr 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants