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

The app hangs when buyProduct() has an error #183

Closed
wasedaigo opened this issue Jun 8, 2018 · 5 comments
Closed

The app hangs when buyProduct() has an error #183

wasedaigo opened this issue Jun 8, 2018 · 5 comments
Labels
🤖 android Related to android

Comments

@wasedaigo
Copy link
Contributor

wasedaigo commented Jun 8, 2018

Version 1.0.8

If I have a line like this, this will never get returned - it hangs.
In my case the error is responseCode: 7(ITEM_ALREADY_OWNED)

const purchase = await RNIap.buyProduct(productId);

I think this is an unwanted side effect caused by this commit.
You probably should at least resolve the promise if you do not want to reject it.
d74846c#diff-b21dbc2d57e14bf6f1b5f81c3a3c3ba5R309

What do you think?

@wasedaigo wasedaigo changed the title The app hangs when buyItemByType has an error The app hangs when buyProduct() has an error Jun 8, 2018
@hyochan
Copy link
Owner

hyochan commented Jun 8, 2018

@wasedaigo I've moved this code away because below code does that when purchaseListener is called.
image.
However, I've revived this code again for you to see how it works. It is in 1.1.0.

hyochan referenced this issue Jun 8, 2018
This may harm promises handling.
@hyochan hyochan added the 🤖 android Related to android label Jun 8, 2018
@wasedaigo
Copy link
Contributor Author

wasedaigo commented Jun 8, 2018

Ok, this is not hanging anymore. At least enabling the rejection lets me move to the next line of the code.
I needed to do a bit work as android errors were not documented.

So... now I am writing like the follows to purchase a managed product. Does this look right?

async purchaseManagedProduct(productId) {
  let purchase;
  try {
    await RNIap.prepare();
    await RNIap.getProducts([productId]);

    const purchases = await RNIap.getAvailablePurchases();
    purchase = purchases.find(purchase => purchase.productId === productId);
    // Check if you have already purchased the product
    if (!purchase) {
      purchase  = await RNIap.buyProduct(productId);
    }
  } finally {
    await RNIap.endConnection();
  }
  return purchase;
}

For iOS, buyProduct() will return the Purchase object even in the case you are "rebuying" it, so all this extra logics are for Android only...

We can either change the behavor of buyProduct() for Android or introduce RNIap.isPurchaseAvailable(productId), that might help us to simplify the code

@hyochan
Copy link
Owner

hyochan commented Jun 9, 2018

@wasedaigo Good idea. I understood that. I think I can manage this one but since I am really busy these days, I may not upgrade this feature for a while.. I am out of time with my work so these days I am just focusing on maintaining this module for those who needs help or fixing critical bugs. I can be helpful maybe after 2~3 months from now. Sorry for that. However, I may have time to review the PR. I appreciate any PR from you although you already gave some. I also wrote comment in your PR too. Have you tested it? Should I release your update to newer version?

@hyochan
Copy link
Owner

hyochan commented Jun 10, 2018

I've publshed your PR to 1.1.2. I will close this for now.

@hyochan hyochan closed this as completed Jun 10, 2018
@wasedaigo
Copy link
Contributor Author

I can help with PR at some pint, but I need to know what you would like to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android
Projects
None yet
Development

No branches or pull requests

2 participants