Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android InApp Purchase: getPurchases returns empty response

I have an app which contains 4 Managed In App Purchases and using In App Billing API v3. The purchases works fine. In order for restoring the purchases, when I make a call to getPurchases(...) it doesn't show any owned SKUs.

Following is the code snippet:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
alert("response " + response);
ArrayList ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");

alert("ownedSkus " + ownedSkus);
for (int i = 0; i < purchaseDataList.size(); ++i) {
    String purchaseData = (String) purchaseDataList.get(i);
    String signature = (String) signatureList.get(i);
    String sku = (String) ownedSkus.get(i);

    alert("PURACHSED ITEM " + i + " === " + sku);

    // do something with this purchase information
    // e.g. display the updated list of products owned by user
} 

Has anybody experienced anything similar? Am I missing something?

Any help is appreciated!

like image 768
Mahendra Liya Avatar asked Sep 21 '13 04:09

Mahendra Liya


1 Answers

The code which my client gave me was written by a previous developer. After referring to the docs and checking the source code I identified the cause for this.

The docs says:

If you are using the Version 3 API, you can also consume managed items within your application. You would typically implement consumption for items that can be purchased multiple times (such as in-game currency, fuel, or magic spells). Once purchased, a managed item cannot be purchased again until you consume the item, by sending a consumption request to Google Play.

The previous developer was actually consuming the purchase which makes it available again for purchase. Since my InApp Purchase was Managed there was no need to call consume.

After I removed the call to consume the product everything worked fine.

Here is the link from the docs.

like image 186
Mahendra Liya Avatar answered Oct 13 '22 23:10

Mahendra Liya