I have an app on google play and am currently in process of adding it to amazon store, however I am having problems with the Amazon IAP This is the code I am using (taken mostly from the corona docs) everything works on android but on the kindle it shows a black screen as soon as i call store.init. The logcat only shows the print message “after require” and then proceeds to the black screen.
main.lua
local function transactionCallback( event ) local transaction = event.transaction local tstate = event.transaction.state -- --Google does not return a "restored" state when you call store.restore() --You're only going to get "purchased" with Google. This is a work around --to the problem. -- --The assumption here is that any real purchase should happen reasonably --quick while restores will have a transaction date sometime in the past. --5 minutes seems sufficient to separate a purchase from a restore. -- if store.availableStores.google and tstate == "purchased" then local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") if timeStamp + 360 \< os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. tstate = "restored" restoring = false end end if tstate == "purchased" then myData.isPaid = true mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") native.showAlert("Thank You!", "Your transaction was successful! Thank you for your support!", {"Okay"}) store.finishTransaction( transaction ) composer.hideOverlay() elseif tstate == "restored" then myData.isPaid = true mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) composer.hideOverlay() elseif tstate == "refunded" then myData.isPaid = false mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "revoked" then -- Amazon feature --Revoke this SKU here: mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") elseif tstate == "cancelled" then native.showAlert("Transaction Cancelled", "The transaction has been cancelled, you were not charged.", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "failed" then store.finishTransaction( transaction ) else store.finishTransaction( transaction ) end end local function loadProductsListener( event ) print("In loadProductsListener") local products = event.products for i=1, #event.products do print(event.products[i].title) print(event.products[i].description) print(event.products[i].localizedPrice) print(event.products[i].productIdentifier) end for i=1, #event.invalidProducts do print(event.invalidProducts[i]) end end -- Initialize the store if system.getInfo("targetAppStore") == "amazon" then store = require "plugin.amazon.iap" print("after require") store.init( transactionCallback ) print("after init") store.loadProducts({"com.company.game"}, loadProductsListener) print("after load") store.restore() else if store.availableStores.apple and not mySettings.isPaid then timer.performWithDelay(1000, function() store.init( "apple", transactionCallback); end) end if store.availableStores.google and not mySettings.isPaid then timer.performWithDelay( 1000, function() store.init( "google", transactionCallback ); restoring = true; store.restore(); end ) end end
I have an overlay script which handles the store.purchase. Any help with this would be grealy appreciated as this is the only thing keeping me from submitting the app.