I am trying to restore domestic purchases within the application. But store.restore not raise the event specified in store.init. What do I do with this problem?
That’s part of my code
[code]
local validProducts, invalidProducts = {}, {}
local listOfProducts = {
“ru.irev.marta.treasure”,
“ru.irev.marta.museum”,
}
function unpackValidProducts()
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)
local files = product…".txt"
local path = system.pathForFile( files, system.DocumentsDirectory )
local file = io.open( path, “r” )
if file then
io.close( file )
else
local path = system.pathForFile( files, system.DocumentsDirectory )
local file = io.open( path, “w+b” )
file:write( “ok” )
io.close( file )
end
setGo = 1
end
function cancelPurchase(product)
local files = product…".txt"
local path = system.pathForFile( files, system.DocumentsDirectory )
local file = io.open( path, “r” )
if file then
local file = io.open( path, “w+b” )
file:write( “canceled” )
io.close( file )
else
io.close( file )
end
end
function transactionCallback( event )
local transaction = event.transaction
if transaction.state == “purchased” then
if transaction.productIdentifier == “ru.irev.marta.treasure” then
savePurchase(“treasure”)
end
if transaction.productIdentifier == “ru.irev.marta.museum” then
savePurchase(“museum”)
end
elseif transaction.state == “restored” then
if transaction.productIdentifier == “ru.irev.marta.treasure” then
savePurchase(“treasure”)
end
if transaction.productIdentifier == “ru.irev.marta.museum” then
savePurchase(“museum”)
end
elseif transaction.state == “refunded” then – NEW FOR GOOGLE PLAY STORE
if transaction.productIdentifier == “ru.irev.marta.treasure” then
cancelPurchase(transaction.productIdentifier)
end
if transaction.productIdentifier == “ru.irev.marta.museum” then
cancelPurchase(transaction.productIdentifier)
end
elseif transaction.state == “cancelled” then
elseif transaction.state == “failed” then
infoString = "Transaction failed, type: “…” “… transaction.errorType…” "… transaction.errorString
local alert = native.showAlert("Failed ", infoString,{ “OK” })
else
infoString = “Unknown event”
local alert = native.showAlert("Unknown ", infoString,{ “OK” })
end
store.finishTransaction( transaction )
end
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
end
…
if store.availableStores.apple then
store.init(“apple”, transactionCallback)
elseif store.availableStores.google then
store.init(“google”, transactionCallback)
end
timer.performWithDelay (1000, setupMyStore)
[/code] [import]uid: 212732 topic_id: 36404 reply_id: 336404[/import]