Hey all,
I’m having quite a bit of trouble getting a rather simple implementation of IAP going in my app, and was hoping I could get some help. I have the non-consumable item set up in iTunes Connect, and a Test User account set up as well. I also have the proper Product ID.
However, whenever I try to run the purchase function, I get the same error returned: “Could not connect to iTunes store”. I’m sure I’m doing something stupid, but I can’t figure out what it is. Here’s the extent of my code (some things I’ve omitted because they aren’t related to the IAP.)
Oh, also…I just have one item that I’d like to be up for purchase, so I’m just directly imputing it’s product ID (in the com.blah.blahblah.productID fashion) directly into the store.purchase() function.
store = require("store")
local function buyAction()
audio.play(clickSound)
if store.canMakePurchases then
store.purchase( {"com.loganhasson.crazydriver.startwith2lives"} )
else
local alert = native.showAlert( "Rapid Racer", "Purchase are not available", { "OK"})
end
end
local listOfProducts = {
"com.loganhasson.crazydriver.startwith2lives",
}
local validProducts, invalidProducts = {}, {}
function unpackValidProducts()
print ("Loading product list")
if not validProducts then
native.showAlert( "In-App features not available", "initStore() failed", { "OK" } )
else
for i=1, #invalidProducts do
native.showAlert( "Item " .. invalidProducts[i] .. " is invalid.",{ "OK" } )
end
end
end
function loadProductsCallback( event )
validProducts = event.products
invalidProducts = event.invalidProducts
unpackValidProducts ()
end
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
end
function storeTransaction( event )
local transaction = event.transaction
if transaction.state == "purchased" then
-- If store.purchase() was successful, you should end up in here for each product you buy.
local alert = native.showAlert( "Rapid Racer", "Transaction Successful!", { "OK"})
doSomethingHere()
elseif transaction.state == "restored" then
local alert = native.showAlert( "Rapid Racer", "Transaction restored (from previous session)", { "OK"})
elseif transaction.state == "cancelled" then
local alert = native.showAlert( "Rapid Racer", "User cancelled transaction", { "OK"})
elseif transaction.state == "failed" then
local alert = native.showAlert( "Rapid Racer", "Transaction failed!"..transaction.errorString, { "OK"})
--print("Transaction failed, type:", transaction.errorType, transaction.errorString)
else
local alert = native.showAlert( "Rapid Racer", "Unknown event", { "OK"})
end
store.finishTransaction( transaction )
end
store.init( storeTransaction )
setupMyStore()
(And I, of course, have the requisite event listener for a button that calls the buyAction() function.)
Thanks!
Logan [import]uid: 44896 topic_id: 18067 reply_id: 318067[/import]