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