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

Doesn't let rebuy Android item on test account #126

Closed
ilyakar opened this issue Apr 13, 2018 · 22 comments
Closed

Doesn't let rebuy Android item on test account #126

ilyakar opened this issue Apr 13, 2018 · 22 comments
Labels
🙏 help wanted Extra attention is needed

Comments

@ilyakar
Copy link

ilyakar commented Apr 13, 2018

Version of react-native-iap

0.3.10

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

Android

Expected behavior

Should be able to rebuy an item as many times as I need since I'm just testing

Actual behavior

Returns

Error: You already own this item.
    at createErrorFromErrorData (59522b9c-ca17-4e00-9e00-05cc989b1199:2016)
    at 59522b9c-ca17-4e00-9e00-05cc989b1199:1968
    at MessageQueue.__invokeCallback (59522b9c-ca17-4e00-9e00-05cc989b1199:2410)
    at 59522b9c-ca17-4e00-9e00-05cc989b1199:2155
    at MessageQueue.__guardSafe (59522b9c-ca17-4e00-9e00-05cc989b1199:2323)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (59522b9c-ca17-4e00-9e00-05cc989b1199:2154)
    at t (RNDebuggerWorker.js:1)

Steps to reprodue the behabior

Buy an item more than once using a test account

@hyochan
Copy link
Member

hyochan commented Apr 13, 2018

@ilyakar Is this a consumable product? You should consumeItem to rebuy it. Please read some guides on how IAP works in android.

@hyochan hyochan added the 🙏 help wanted Extra attention is needed label Apr 13, 2018
@ilyakar
Copy link
Author

ilyakar commented Apr 13, 2018

Hi @dooboolab, it's not a consumable product. Users have it forever. There's a way to restore the product so it's good to let users known in production that they cannot buy the same product again since they already bought it. But for testing purposes, it gets very uncomfortable to have to use a different account each time all the purchases have been bought.

@ilyakar
Copy link
Author

ilyakar commented Apr 13, 2018

I don't think I had this problem in 0.2.17

@hyochan
Copy link
Member

hyochan commented Apr 14, 2018

@ilyakar Ah.. Sorry I was confused. Actually, if it is non-consumable product, you can't actually rebuy it. If that was possible in 0.2.17 that must be working awkwardly.. Only consumable products are able to rebuy it. It is same in both platforms (ios and android). If user want to restore the item they have to do it optionally but as in LINK, it won't charge the user again. Therefore, if you are designing in-app products that you want to charge users by rebuying, I think you should create consumable product.

@hyochan
Copy link
Member

hyochan commented Apr 16, 2018

@ilyakar I've got feedback from my friend developer and he also faced the same problem. Therefore, I came up with solution to use refreshItems method that only occurs in android. You can use this in react-native-iap@0.3.13. Try using it after prepare method. My friend was facing this issue because he couldn't find the token of purchased product to consume. Therefore, this method is just for your ease if you don't care about the history of the purchases that relies in playstore. When you have your own backend collecting the purchase history, this will help you to solve the issue. I have to take a look on this one furthermore tough. Also, following the readme would help you. Thank you for your report!

P.S. I think above method will work on non-consumable product too. Also this article will help you understand what refeshItems would solve you.

@deadcoder0904
Copy link

I think this is already solved since I don't think IAP works with Test Account

And @dooboolab's solution of refreshItems is the way to go

One noob question @dooboolab as I have only implemented IAP once in an Android App but never tried if it works 😂

Can we buy a product without spending any money like $0❓

@ilyakar
Copy link
Author

ilyakar commented Apr 23, 2018

Yes @deadcoder0904, that's the whole concept of Android test accounts (https://developer.android.com/google/play/billing/billing_testing.html). Which do work fine with the plugin, but as I have pointed out, you cannot make the same purchase twice.

@hyochan
Copy link
Member

hyochan commented Apr 23, 2018

@ilyakar You're saying that it is still not working. Did you tried calling refreshItems after buying product? As described in here, it may cause some delay in playstore. However, you can force consuming the product to able to rebuy again. I'm also curious why this works though.. Also watch out if you rely on purchases on google play history and not collecting it in your backend.

@ilyakar
Copy link
Author

ilyakar commented Apr 23, 2018

Hi @dooboolab, I was just responding to @deadcoder0904 with my previous knowledge. I'm afraid I have not tried your solution and probably won't for some time since it's not an urgent fix. But I will let you know in the future when I have.

@hyochan
Copy link
Member

hyochan commented May 6, 2018

@ilyakar becareful using refreshItems because it will consume all the products user has bought. You can only use it if you don't care about those information stored in playstore because you have your won server. Also, this problem use to occur like I posted 13 days ago from here, if user has refunded the item, user may not rebuy the same item for 24 hours.

@hyochan hyochan closed this as completed May 13, 2018
@TylerNoblett
Copy link

I was running into the same issue as @ilyakar, and using the code below I was able to clear the non-consumable purchase and test it again.

async componentDidMount() {
    const { itemSkus } = this.props;
    try {
      const result = await RNIap.initConnection()
      console.log('initiated connection?', result)
      const consumed = await RNIap.consumeAllItems();
      console.log('consumed all items?', consumed)
      let products = await RNIap.getProducts(itemSkus);
      console.log('loaded products', products)
    } catch (err) {
      console.warn(err);
    }
  };

@roots-ai
Copy link

roots-ai commented Dec 9, 2019

@TylerNoblett This solution isn't working right now.

  • I tried with consumeAllItemsAndroid instead of consumeAllItems.
    Any further help is appreciated.

@tulpn
Copy link

tulpn commented Dec 10, 2019

The console output is:

setUpDeveloperTools.js:73 TypeError: _reactNativeIap.default.consumeAllItems is not a function
    at loadPurchases$ (NewGameScreen.js:167)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:271)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at tryCatch (runtime.js:45)
    at invoke (runtime.js:135)
    at runtime.js:145
    at tryCallOne (core.js:37)
    at core.js:123
    at JSTimers.js:289

On:

    "react": "16.9.0",
    "react-native": "0.61.3",
    "react-native-iap": "^4.3.0",

@hyochan
Copy link
Member

hyochan commented Dec 10, 2019

@tulpn Looks like you've not correctly installed our module since consumeAllItemsAndroid should be working fine.

@roots-ai
Copy link

@hyochan Didn't work for me.

@hyochan
Copy link
Member

hyochan commented Dec 18, 2019

@roots-ai What version are you using? Also, please refers to the code we've provided in example too.

@stephan-rayner
Copy link

I ran into this earlier today and after digging through the code I found that a pretty straight-forward option is to call finishTransaction(purchase, true)

There is a more complete code snippet below.

import * as IAP from "react-native-iap"

...

const App = () => {
  
  ...

  useEffect(() => {
    const checkCurrentPurchases = async (purchase) => {
      if (purchase) {
        const receipt = purchase.transactionReceipt
        if (receipt) {
          try {
            const isConsumable = true // if we were dealing with non-consumables this would be false but we aren't.
            const ackResult = await IAP.finishTransaction(purchase, isConsumable)
            console.info(`Transaction Completed Successfully ${JSON.stringify(ackResult)}`)
          } catch (ackError) {
            console.warn(`Error finishing transaction ${ackError}`)
          }
        }
      }
    }
    checkCurrentPurchases(currentPurchase)
  }, [currentPurchase])

  ...
  
}

I hope this helps someone. 🙂

@noumantahir
Copy link

seems consumeAllPurchasesAndroid() is no longer support, for new purchases finishTransaction(product, isConsumable) seems to work well

However, I have facing the already owned error for already purchased items... any ideas ...?

@kaushil111
Copy link

Facing the same issue. Is there a way to flush already owned items?

@MHB2011
Copy link

MHB2011 commented Nov 22, 2021

@kaushil111 I was able to consume/flush them like this

  try {
    await RNIap.initConnection();
    const availablePurchases = await RNIap.getAvailablePurchases();

    availablePurchases.forEach((purchase) => {
      finishTransaction(purchase, true);
    });
  } catch (error) {
    console.warn(
      "Failed to connect to IAP and finish all available transactions"
    );
  }

@kaushil111
Copy link

That worked! Thanks!

@usmanabid94
Copy link

@kaushil111 I was able to consume/flush them like this

  try {
    await RNIap.initConnection();
    const availablePurchases = await RNIap.getAvailablePurchases();

    availablePurchases.forEach((purchase) => {
      finishTransaction(purchase, true);
    });
  } catch (error) {
    console.warn(
      "Failed to connect to IAP and finish all available transactions"
    );
  }

You are a savior it worked like a charm (Y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests