question

goranhoriamihail avatar image
goranhoriamihail asked

in app purchase - PurchaseUpdatesAsyncTask doesn't work.

Hello, I'm implementing amazon's in app purchase api in my app and everything works great besides updating the state (paid / not paid) for the in app items. More specifically I'm using the amazon test client to test the purchases, buying items works but after I exit and enter again in the app the items appear locked again. If I try to buy the item again the amazon test client responds with "you already own the item". I identified the problem to be in the PurchaseUpdatesAsyncTask class , purchaseUpdatesResponse.getReceipts() has the size 0, and I don't understand why. It never enters in the for loop: for(final Receipt receipt : purchaseUpdatesResponse.getReceipts()) { switch(receipt.getItemType()) { case ENTITLED: { //update item's state to paid } } } Any suggestions in what might be wrong will be highly appreciated. Thank you.
fire tablet
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Goranhoriamihail, Thank you for posting. onPurchaseUpdatesResponse() returns a valid purchaseUpdatesResponse that contains receipts for the purchase of items of type either Entitlement and Subscription. You would receive purchaseUpdatesResponse.getReceipts() of size 0 if you have bought consumable type items. Receipts are provided for Entitled Content and Subscription Content. Please go through this link for complete understanding the methods of Purchasing Observer : https://developer.amazon.com/sdk/in-app-purchasing/documentation/developer-guide.html#IAP%20API Message was edited by: Sujoy@Amazon
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

matmideveloper avatar image
matmideveloper answered
I realise this is many months on from your query but I've also just been experiencing the very same problem. From my understanding, in the test environment (haven't actually made the app live yet, so can only confirm for test environment), once a purchase is made you can then request the receipt for it ONLY ONCE PER INSTALLED APP, so you must store something locally to indicate the purchase has been made. If you uninstall the app and then reinstall it, the first time you check for receipts you will receive them.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Matmideveloper, Thank you for comments. Actually, for consumable items you would receive the receipt of a purchase in onPurchaseResponse() and you can persist the data in device for reference. onPurchaseUpdatesResponse() would receive callback for entitlements and subscription type. onPurchaseUpdatesResponse(PurchaseUpdatesResponse purchaseUpdatesResponse) Callback is invoked after a call to initiatePurchaseUpdatesRequest(Offset offset) and is used to sync purchases made from other devices onto this device, and sync revoked entitlements across all instances of your app. It is best practice to persist the returned PurchaseUpdatesResponse data and last Offset to store the transaction history internally and only query the system for updates.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

matmideveloper avatar image
matmideveloper answered
Ah, I see. I have been using the Unity plugin and the ability to directly call PurchaseUpdatesResponse is obscured. PurchaseUpdates are received after calling initiateItemDataRequest(string[] items). The plugin must store the Offset (of which I have no access to) and would explain why I only receive ENTITLED receipts once, since the plugin automatically increments the offset.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.