Hi everyone.
I’m trying to implement an In App Purchase. For that i create a new App in Itunes Connect and a new In App Purchase. These are in state “Waiting fot Upload” and “Ready to Submit”. I create a test user too.
When i try my code on device it gives me an error. “Failed: Cannot connect to Itunes Store”
I’m login with the test user.
This is my code.
display.setStatusBar( display.HiddenStatusBar )
local loadsave = require("loadsave")
local store = require("store")
---FUNCIONES-----
local unpackValidProducts, loadProductsCallback, savePurchase
local transactionCallback, setupMyStore, onbuyButTap, onbuyButTap2
local boton1, boton2, boton3
descriptionArea = native.newTextBox (10, 0.7\*display.contentHeight, display.contentCenterX - 20, display.contentCenterY - 10)
descriptionArea.text = "Select a product..."
descriptionArea:setTextColor (2, 0, 127)
descriptionArea.size = 18
descriptionArea.hasBackground = false
function onbuyButTap2()
descriptionArea.text = "onbuyButTap2"
if store.canMakePurchases then
store.purchase( {"com.Bilu.diferenciasTest.fullversion123" } )
else
native.showAlert("Store purchases are not available, please try again later", { "OK" } )
end
end
function onbuyButTap()
descriptionArea.text = "onbuyButTap"
boton1:removeEventListener("tap", onbuyButTap)
boton1.alpha = 0.4
boton2.alpha = 1
boton2:addEventListener("tap", onbuyButTap2)
--if store.canMakePurchases then
store.restore()
-- store.purchase( {"com.Bilu.diferenciasTest.fullversion123" } )
--else
-- native.showAlert("Store purchases are not available, please try again later", { "OK" } )
--end
end
local estado = loadTable("estado.json")
if estado == nil then
estado = "sincompra"
saveTable(estado,"estado.json")
end
boton1 = display.newImage( "comprar.png", 50, 50 )
boton2 = display.newImage( "comprar2.png", 50, 170 )
boton3 = display.newImage( "listo.png", 300, 300 )
if estado == "sincompra" then
boton2.alpha = 0.4
boton3.alpha = 0.4
boton1:addEventListener("tap", onbuyButTap)
elseif estado == "comprado" then
boton1.alpha = 0.4
boton2.alpha = 0.4
end
local listOfProducts = {
"com.Bilu.diferenciasTest.fullversion123",
}
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 savePurchase(product)
estado = "comprado"
saveTable(estado,"estado.json")
boton2:removeEventListener("tap", onbuyButTap2)
boton2.alpha = 0.4
end
function transactionCallback( event )
--descriptionArea.text = "Transaction failed, type: " .. event.transaction.errorType .. "String:" .. event.transaction.errorString
--local alert = native.showAlert("Estado", event.transaction.state,{ "OK" })
if event.transaction.state == "purchased" then
descriptionArea.text = "purchsed"
savePurchase("product")
elseif event.transcation.state == "restored" then
descriptionArea.text = "restored"
savePurchase("product")
elseif event.transaction.state == "cancelled" then
descriptionArea.text = "cancelled"
elseif event.transaction.state == "failed" then
descriptionArea.text = "failed"
--infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
--local alert = native.showAlert("Failed ", infoString,{ "OK" })
else
descriptionArea.text = "Unknow"
end
store.finishTransaction( event.transaction )
end
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
end
store.init(transactionCallback)
timer.performWithDelay (1000, setupMyStore)
[import]uid: 105206 topic_id: 25314 reply_id: 325314[/import]