Amazon IAP

I am having massive issues getting my Amazon IAP code to work. My app is published in Amazon, Google and Apple and the code below works fine in Google and Apple, but on my Kindle the app hangs, then crashes, seemingly without reporting anything in logcat (with a Corona:I *:S filter).

I am using a separate iap.lua file, and when I don’t require the file, the app works fine (aside from having no store ability). Similarly, if I comment out the store.init and store.loadProducts, everything except purchases is fine. I figure there is something funny happening in my init listener function, but I can’t figure it out. 

All my testing has been done using the live version downloaded from Amazon. I’m building with daily build 2014.2511

Any help would be amazing!

Here is the iap.lua code

module(..., package.seeall); local store local v3 = false local storeName local licensing if system.getInfo( "targetAppStore" ) == "google" then store = require( "plugin.google.iap.v3" ) storeName = "google" v3 = true licensing = require( "licensing" ) licensing.init( "google" ) elseif system.getInfo( "targetAppStore" ) == "apple" then store = require( "store" ) storeName = "apple" elseif system.getInfo( "targetAppStore" ) == "amazon" then store = require( "plugin.amazon.iap" ) storeName = "amazon" else native.showAlert( "Notice", "In-app purchases are not supported by this app on this device.", { "OK" } ) store = require( "store" ) end local callback = nil; local GGData = require( "GGData" ) box = GGData:load("purchases") --To get a price from any screen, just call iap.localizedPrices[XX] and replace the XX with the item number that you'd like localizedPrices = {}; --Fill out this section with all your product IDs. Add or remove them as necessary local productID = { "unlock\_all", --buyItem1 "unlock\_filters", --buyItem2 "unlock\_slogans", --buyItem3 "unlock\_frames", --buyItem4 } function transactionCallback(e) local trans = e.transaction; if (trans.state == "purchased") then if (trans.productIdentifier == productID[1]) then --item1 box.filter = 1 box.text = 1 box.frames = 1 box:save() print ("success buying product 1! Give the user the item here, or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[2]) then --item2 box.filter = 1 box:save() print ("success buying product 2! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[3]) then --item3 box.text = 1 box:save() print ("success buying product 3! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[4]) then --item4 box.frames = 1 box:save() print ("success buying product 4! Give the user the item here or in the callback (see comments above)"); end print("Transaction successful") print("productIdentifier", trans.productIdentifier) print("receipt", trans.receipt) print("transactionIdentifier", trans.identifier) print("date", trans.date) external\_cancel\_iap() locked\_images() removeWatermark() native.showAlert("Thank you" , "You purchase is now available." , {"OK"}, none); elseif (trans.state == "refunded") then if (trans.productIdentifier == productID[1]) then --item1 box.filter = 0 box.text = 0 box.frames = 0 box:save() print ("success buying product 1! Give the user the item here, or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[2]) then --item2 box.filter = 0 box:save() print ("success buying product 2! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[3]) then --item3 box.text = 0 box:save() print ("success buying product 3! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[4]) then --item4 box.frames = 0 box:save() print ("success buying product 4! Give the user the item here or in the callback (see comments above)"); end print("Transaction successful") print("productIdentifier", trans.productIdentifier) print("receipt", trans.receipt) print("transactionIdentifier", trans.identifier) print("date", trans.date) external\_cancel\_iap() locked\_images() removeWatermark() native.showAlert("Thank you" , "You have been refunded." , {"OK"}, none); elseif (trans.state == "restored") then if (trans.productIdentifier == productID[1]) then --item1 box.filter = 1 box.text = 1 box.frames = 1 box:save() print ("success buying product 1! Give the user the item here, or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[2]) then --item2 box.filter = 1 box:save() print ("success buying product 2! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[3]) then --item3 box.text = 1 box:save() print ("success buying product 3! Give the user the item here or in the callback (see comments above)"); elseif (trans.productIdentifier == productID[4]) then --item4 box.frames = 1 box:save() print ("success buying product 4! Give the user the item here or in the callback (see comments above)"); end print("Transaction restored (from previous session)") print("productIdentifier", trans.productIdentifier) print("receipt", trans.receipt) print("transactionIdentifier", trans.identifier) print("date", trans.date) print("originalReceipt", trans.originalReceipt) print("originalTransactionIdentifier", trans.originalIdentifier) print("originalDate", trans.originalDate) external\_cancel\_iap() locked\_images() removeWatermark() native.setActivityIndicator(false); native.showAlert("Thank you" , "Your purchases have been restored." , {"OK"}, none); elseif (trans.state == "cancelled") then external\_cancel\_iap() locked\_images() removeWatermark() store.finishTransaction(trans); native.setActivityIndicator(false); print ("player cancelled; you may want to show an alert here"); native.showAlert("Cancelled" , "The transaction has been cancelled and your account will not be charged." , {"OK"}, none); elseif (trans.state == "failed") then external\_cancel\_iap() locked\_images() removeWatermark() store.finishTransaction(trans); native.setActivityIndicator(false); print ("transaction failed"); native.showAlert("Oops!" , "Something went wrong. Please check your internet connection and try again." , {"OK"}, none); end if (callback ~=nil) then callback(trans.state); end native.setActivityIndicator(false); store.finishTransaction(trans); end if storeName ~= "amazon" then store.init(storeName, transactionCallback); else store.init(transactionCallback); end local function loadedCallback(e) for i=1, #e.products do table.insert(localizedPrices, i, tostring(e.products[i].price)); end end store.loadProducts(productID, loadedCallback); --These are the functions that you call from another lua file. function buyItem1 (callbackFunction) if store.target == "google" or store.target == "amazon" then store.purchase(productID[1]); else store.purchase({productID[1]}); end native.setActivityIndicator(true); callback = callbackFunction; end function buyItem2 (callbackFunction) if store.target == "google" or store.target == "amazon" then store.purchase(productID[2]); else store.purchase({productID[2]}); end native.setActivityIndicator(true); callback = callbackFunction; end function buyItem3 (callbackFunction) if store.target == "google" or store.target == "amazon" then store.purchase(productID[3]); else store.purchase({productID[3]}); end native.setActivityIndicator(true); callback = callbackFunction; end function buyItem4 (callbackFunction) if store.target == "google" or store.target == "amazon" then store.purchase(productID[4]); else store.purchase({productID[4]}); end native.setActivityIndicator(true); callback = callbackFunction; end

I don’t believe the Amazon store is supported by the Corona store api. From the docs:

"Currently, only the Apple iTunes Store and the Google Play Marketplace are supported. In the future, other storefronts may be added."

See here: http://docs.coronalabs.com/api/library/store/index.html

I should also mention I am using the Amazon IAP plugin and have followed this documentation:

http://docs.coronalabs.com/plugin/amazon.iap/index.html

Actually Alex, it is via the Amazon IAP plugin.

Brad, do your “adb logcat” without the Corona filter.  You need to see error messages and warning from other activities.

Rob

Yeesh, I should read more. Sorry for the incorrect statement folks!

I’m going to move this to the Amazon IAP Forum.

Rob

Bizarrely this has started working fine today. Really not sure why, because I haven’t changed anything. Hopefully this is the last I’ll hear of the issue. Thanks anyway!

We’ve had an app rejected due to crashing on startup. It works fine on my HDX 7", but on non Amazon devices it seems to crash.  

I’ve run the apk through Amazon’s own testing service I get the following back in their logs:

 java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.amazon.testclient.iap.appUserId flg=0x10000000 (has extras) } 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1703) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.startService(ContextImpl.java:1687) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:515) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at com.amazon.inapp.purchasing.SandboxRequestHandler.sendGetUserIdRequest(Unknown Source) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at com.amazon.inapp.purchasing.GetUserIdRequest$1.run(Unknown Source) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:61) 

Looking around it seems that there is an issue with intents on Android, and that the SDK may have been updated:  Lollipop https://forums.developer.amazon.com/forums/thread.jspa?threadID=4337&tstart=0

Has the plugin been updated to use the latest SDK? I haven’t downloaded it yet because I’ve just found this out and wanted to ask on the forum first in case anyone knows what the situation is.

Edit: I’ve just looked and the plugin is still using SDK 1.0.3, so that could be causing the problem.

2 week bump - we’re still experiencing the same issue on Lollipop devices, and we have an Amazon submission deadline this week so I’m really eager to see a fix.

Any news at all about the Amazon IAP plugin being updated - latest version afaik is now in-app-purchasing-2.0.1.jar?

I would suggest sending a PM to tamkinp.  He’s been responding to most of these threads regarding the Amazon IAP plugin.  This is a 3rd party developed plugin so issues like will need to be addressed by him.

Rob

I don’t believe the Amazon store is supported by the Corona store api. From the docs:

"Currently, only the Apple iTunes Store and the Google Play Marketplace are supported. In the future, other storefronts may be added."

See here: http://docs.coronalabs.com/api/library/store/index.html

I should also mention I am using the Amazon IAP plugin and have followed this documentation:

http://docs.coronalabs.com/plugin/amazon.iap/index.html

Actually Alex, it is via the Amazon IAP plugin.

Brad, do your “adb logcat” without the Corona filter.  You need to see error messages and warning from other activities.

Rob

Yeesh, I should read more. Sorry for the incorrect statement folks!

I’m going to move this to the Amazon IAP Forum.

Rob

Bizarrely this has started working fine today. Really not sure why, because I haven’t changed anything. Hopefully this is the last I’ll hear of the issue. Thanks anyway!

We’ve had an app rejected due to crashing on startup. It works fine on my HDX 7", but on non Amazon devices it seems to crash.  

I’ve run the apk through Amazon’s own testing service I get the following back in their logs:

 java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.amazon.testclient.iap.appUserId flg=0x10000000 (has extras) } 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1703) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.app.ContextImpl.startService(ContextImpl.java:1687) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:515) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at com.amazon.inapp.purchasing.SandboxRequestHandler.sendGetUserIdRequest(Unknown Source) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at com.amazon.inapp.purchasing.GetUserIdRequest$1.run(Unknown Source) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 01-27 02:52:35.298 8362 8508 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:61) 

Looking around it seems that there is an issue with intents on Android, and that the SDK may have been updated:  Lollipop https://forums.developer.amazon.com/forums/thread.jspa?threadID=4337&tstart=0

Has the plugin been updated to use the latest SDK? I haven’t downloaded it yet because I’ve just found this out and wanted to ask on the forum first in case anyone knows what the situation is.

Edit: I’ve just looked and the plugin is still using SDK 1.0.3, so that could be causing the problem.

2 week bump - we’re still experiencing the same issue on Lollipop devices, and we have an Amazon submission deadline this week so I’m really eager to see a fix.

Any news at all about the Amazon IAP plugin being updated - latest version afaik is now in-app-purchasing-2.0.1.jar?

I would suggest sending a PM to tamkinp.  He’s been responding to most of these threads regarding the Amazon IAP plugin.  This is a 3rd party developed plugin so issues like will need to be addressed by him.

Rob