In app billing: Failure can't be captured from the sample code - android

I integrated the sample code (helper classes) for the inapp billing from the official Android website. I am trying to test error path ( i.e incorrect APK signature, no internet..etc). When this error occurs, the dialog shows the error such as " Error retrieving billing info ..etc"
The problem is that, once you click ok, the app continues (although I have checks everywhere to terminate the app when things go wrong). Before someone says "post some code", let me clarify here. I am not able to "catch the failure" in the sample code. I placed debug points everywhere. The last piece of code that is called is when the "purchase buying intent" is initiated. After that, I can't seem to find anywhere where the code would actually indicate failure (so I can action based on it)
anyone else faced this?

I found the reason for that
The overridden OnActivityResult was not called. So I corrected it and now it receives the results
Hoping this would save someone else many hours

Related

Flutter In App Purchases Consumable Product - Purchase Stream not firing

I am using in_app_purchases flutter package to handle my in app purchasing needs on both android and ios. I only use consumable IAP. But my purchase stream is not firing. Only the queryPastPurchases method returns the list of the consumable. So Im bit confused with the plugin. I have also started to listen to the purchasestream as soon as the app starts in the main method. However Im not receiving the purchase updates in the Purchase Stream.
Also this statement from the in_app_purchase seems a bit ambigous it says trying to complete a pending purchase can cause a error. However it is mentioned to retry the purchase completion on pending status
Completing a [PurchaseStatus.pending] purchase will cause an exception.
For convenience, [PurchaseDetails.pendingCompletePurchase] indicates if a
purchase is pending for completion.
The method returns a [BillingResultWrapper] to indicate a detailed status
of the complete process.
If the result contains [BillingResponse.error] or
[BillingResponse.serviceUnavailable], the developer should try
to complete the purchase via this method again, or retry the
[completePurchase] it at a later time.
If the result indicates other errors, there might be some issue with
the app's code. The developer is responsible to fix the issue.
Please take a look at my answer here:
How can I dd in-app-purchase functionality to my flutter app?
I've also added some links to a video tutorial, which will help you.
Please use the flutter_in_app_purchase package. It's a fork of the original in_app_purchase package

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

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
I tried calling startSetup() and the listener OnIabSetupFinishedListener() in the Activity's onCreate(). Am getting response 0.
Then I tried labHelper class' 'queryInventoryAsync(mReceivedInventoryListener)' method and it also returns 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!
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.

GoogleJSONResponseException

I tried to start using Google Cloud Console and followed after the Google IO tutorial for Geek Serendipity http://www.youtube.com/watch?v=v5u_Owtbfew. I followed all the steps of the tutorial, however, I get an error every time I try to send a request to server. Neither logcat, nor Eclipse console gave any errors, however, I see a toast in the application that says
com.google.apiclient.apis.json.GoogleJSONResponseException:503 Service unavailable... "reason": backend error.
However, in google appengine logs there are no recent error.
Has anyone faced same problem?
I would suggest that you ensure the following:
1) Check that you have set PROJECT_ID correctly in the Consts.java
2) You should definitely see the same message in LogCat. Check this answer to get your LogCat working:
Android debugging on device - LogCat doesn't work!
Once LogCat works, you should see the same Exception there, along with another exception such as SocketTimeoutException, or something else that will give you an idea of what went wrong.

Android IAB: "Error refreshing inventory (querying prices of items)" Developer Error

I've been setting up Android in app billing v3, using the IABHelper class, and following the example code provided by Google. I have it mostly working all the way through purchase (with signed apk and real credit card charge).
However, in the course of testing today I started to get a new error in my QueryInventoryFinishedListener from the queryInventoryAsync() method:
IABResult message: "Error refreshing inventory (querying prices of items)"
IABResult response: 5:Developer Error
Weird thing #1 is that this occurs after the onIabSetupFinished() callback returns (with the customary "Hooray" message). Weird thing #2 is that I can subsequently & successfully process an in app purchase (using the launchPurchaseFlow() method).
I found a patch here that addresses the same symptoms I'm experiencing, but it didn't work for me.
I've tried using different devices, using different gmail accounts, and building a new product from scratch. I even getting the error on earlier versions of my app that ran correctly (what?!).
My question is: Why can't I query the product inventory, even after IABHelper has confirmed the set up was successful? What could be causing this error, and how can I fix it?
Thank you for any insight.
UPDATE
I was able to get the inventory query transactions to work again by ditching the account I was testing with, and switching to a new account. No code change.
My tentative conclusion is that something got corrupted in the user account I was using (?). During testing, I had hit it pretty hard with a lot of purchases of different in-app products -- but I still need to find out what happened, and make sure this doesn't happen to any of my users.
Please let me know if you have any experience with this. Thanks!
We had the same problem in one of our apps under test mode. Later, we figured out that, we had to clear the Cache of the Google Play Store app.
So you can try this -
Go your device's Settings menu.
Go to Applications (may also be labeled Application Manager).
Tab over to All Applications.
Search for and open the Google Play Store app. Tap on it, application settings will show
Tap on Clear Data and Clear Cache.
Now go back to your app and try to load inventory. It solved our problem.
I found by trial and error that if you query more than 20 items at once, it will fail with this error.
I submitted a patch for IabHelper.java that splits the list of SKUs into packets of 20 items each and does the query.
You can grab it there: https://code.google.com/p/marketbilling/issues/detail?id=123
I have the same issue with this log :
"InAppBillingManager.getSkuDetails: Input Error: skusBundle array associated with key ITEM_ID_LIST cannot contain more than 20 items."
this note had mentioned in IInAppBillingService.aidl file, see the documentation of the method getSkuDetails(..) .
So you should make the same process for each 20 items every time
I face same error but my issue is Date Time change
Go to setting and check your date time is accurate

Google In app Billing V3 ERROR Code

In app Billing v3 returns Response Code (BILLING_RESPONSE_RESULT_USER_CANCELED:1) -1005 in more than one scenario.
Launching the purchase flow opens the Google Play-like UI. Whenever an error happens in this UI, say a network disconnection / Timeout / Item Unavailable / Item Already Purchased, a dialog pops up to indicate the error. When OK is clicked , Response code : User Cancelled(1) is invariably returned in the OnActivityResult Intent extras. According to the reference on Android developer's site this is supposed to happen only when the user cancels the activity/Dialog, which i clearly don't do.
I would like to separate out the different errors and handle them individually in my app. Having a single error code returned doesn't help. Any one faced it yet? Is there a solution?
For the record, this seems to be an issue with the Google Play client. Google has started rolling out updates to the GP client as versions 4.0+ and the bug appears to be fixed.
The TrivialDrive demo tests the onActivityResult() callback for the value Activity.RESULT_CANCELED,
and assumes that if that is the value returned then the user has canceled.
That is an incorrect assumption, because if the responseCode in that activity result is BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED (=7) then Activity.RESULT_CANCELED means that
the in-app billing service would not allow the purchase because the item is already owned.
This response code is working for me.
However, once that possibility is eliminated, I've found that it's safe to assume that the user has canceled. I haven't checked very recently however to see if Google has made the BILLING_RESPONSE_RESULT_USER_CANCELED response code directly testable and reliable.

Categories

Resources