0

I have added all of the products as managed products.When I'm querying getPurchases it returns only 1 items but when I'm querying getHistory than it returns 3 items I'm confused why it is happening?

get purchases Code :

Bundle ownedItems = mService.getPurchases(6, getPackageName(), "inapp", null);

get Purchase History Code :

 Bundle purchaseHistoryBundle = mService.getPurchaseHistory(6, getPackageName(), "inapp", null, new Bundle());

I have purchased many products how can I fix this issue?

Robin Royal
  • 1,788
  • 1
  • 18
  • 29

1 Answers1

1

getPurchases needs an Integer that is representing the InApp Billing API. So your call

Bundle ownedItems = mService.getPurchases(6, getPackageName(), "inapp", null);

must be handling the api version. If you developing InApp Billing version 3, it must be:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

Like described in API:

Pass the In-app Billing API version (“3”), the package name of your calling app, and the purchase type (“inapp” or "subs") into the method. Here is an example:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

I wonder why it works, anyway I don´t think that this is causing the problem.

The next thing is, the getPurchases() returns only not consumed items. If your items are consumed, it will not return these. That´s why history returns it. Like described in API:

getPurchases()

This method returns the current un-consumed products owned by the user, including both purchased items and items acquired by redeeming a promo code.

getPurchaseHistory()

This method returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.

My experience with inApp Billing is that this is a huge pain as it is not possible to test every cirumstances through a test account. It seems like a not finished part of android. But we have no other choice to follow exact the api, so I recommend to do it exactly like described.

API and Source Codes:

https://developer.android.com/google/play/billing/billing_integrate.html

https://developer.android.com/google/play/billing/billing_reference.html

https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive/app/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49