Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : In-app purchase returns 3 error code (item already owned) always

Tags:

android

Am trying out in-app billing in my App for the first time. Am using the labHelper code (https://gist.github.com/yigit/4543005) from the TriviaDrive example in the samples folder in the Play Billing Services extras. When I tried with the test code that Google gives i.e. product code as 'android.test.purchased' (give here under 'Testing with static responses'), it worked fine. But now, I switched to using the test Google account (i.e. license testing, given under 'Setting up test accounts' here). I purchased the item successfully. But when I try to use a purchased item (it's a monthly subscription product), I get an error dialog saying 'You already own this item'. At the same time, in the logs, I see the message

05-02 17:10:36.599: D/Finsky(6396): 1 PurchaseFragment.handleError: Error: PurchaseError{type=3 subtype=3}

05-02 17:10:36.599: D/Finsky(6396): 1 PurchaseFragment.fail: Purchase failed: PurchaseError{type=3 subtype=3}

(response code 3 meaning 'billing unavailable')

But, if I dismiss the error dialog, I get response 7 (i.e. 'you already own this item').

Not sure why I keep getting 3 for an item that's already been purchased? Please help.

What I tried

  1. I tried calling startSetup() and the listener OnIabSetupFinishedListener() in the Activity's onCreate(). Am getting response 0.
  2. Then I tried labHelper class' 'queryInventoryAsync(mReceivedInventoryListener)' method and it also returns 3.
  3. I tried consumption related methods from labHelper class launchSubscriptionPurchaseFlow(this, InAppBillingExportProductId, 10001, mPurchaseFinishedListener, "”);

mPurchaseFinishedListener returns the response 0 (i.e. success), but it immediately returns the error -1010 (IABHELPER_INVALID_CONSUMPTION)

Please help. Been struggling with this one issue for more than 3 days now!

like image 209
Jean Avatar asked May 05 '15 06:05

Jean


1 Answers

IabHelper has a method called enableDebugLogging(...) that you can use (call it with true) to turn on pretty detailed logging for all IabHelper actions. If you can post a copy of the full log, it might be easier to figure out exactly what's going on.

But let me post a couple thoughts anyways based on what you wrote:

  • Just like normal managed products, subscription items can not be purchased again if they are already owned.
  • The way to check ownership is via queryInventoryAsync(...) (if inventory.getPurchase(sku) is not null, you own the item). Unfortunately this is not always 100% accurate and I haven't found a fix yet.
  • To "use" a managed product or subscription, simply have your application provide whatever service you sold if the above check tells you that the item is owned.
  • The big difference between managed products and subscriptions is the way that the user loses them again (i.e. can purchase the same sku for a second or third time):
    • Subscriptions expire automatically at the end of a pre-determined period if the user doesn't renew them,
    • while managed products need to actively be "consumed" by your app to make them available again.

So, if you try to purchase a managed product again before "consuming" it, you will get the "you already own this item"-error that you mentioned. Same goes for trying to purchase a subscription again that you already purchased and that hasn't expired yet.

The "IABHELPER_INVALID_CONSUMPTION" error is likely caused by the fact that subscriptions cannot be consumed, only managed products can. Subscriptions only expire (or you can refund them from the developer console).

I'm not sure where the "PurchaseError{type=3 subtype=3}"-error is coming from. That one might be easier to track down from the actual IabHelper debug output. If you can update your question with a full log, send me a comment and I can take a look at it and probably help you make sense of it if needed.

Let me know if you have any further questions. I hope this helps.

like image 108
Markus A. Avatar answered Nov 03 '22 12:11

Markus A.