considering that you initiated the store and loaded the products then you should make the purchase by passing productIdentifier
with the purchase method
local IAPList={}
local realIAPList={}
local IAPListT={}
local function onLoadProducts( event )
for i = 1,#event.products do
realIAPList[i]=event.products[i].productIdentifier
IAPListT[i]=event.products[i].title.." "..event.products[i].localizedPrice
end
-- print( "Valid products:", #event.products )
-- print( "Invalid products:", #event.invalidProducts )
end
local function transactionListenerAndroid( event )
if ( event.name == "init" ) then
if not ( event.transaction.isError ) then
if (platformName=="android" or platformName=="iphone os" or platformName=="mac os x" or platformName=="tvos") and store.isActive then
if store.canLoadProducts then
store.loadProducts( IAPList, onLoadProducts )
end
end
else -- Unsuccessful initialization; output error details
native.showAlert( "Info", tostring(event.transaction.errorType) .. "\n"..event.transaction.errorString ,{"Ok"} )
end
-- Store transaction event
elseif ( event.name == "storeTransaction" ) then
if event.transaction.state == "purchased" then -- Successful transaction
store.consumePurchase( currItem)
elseif event.transaction.state == "restored" then -- Successful transaction
store.consumePurchase( currItem)
else -- Unsuccessful transaction; output error details
native.showAlert( "Info", "Unable to complete purchase" ,{"Ok"} )
end
end
end
local function transactionListeneriOS( event )
if event.transaction.state == "purchased" then -- Successful transaction
-- print( json.prettify( event ) )
-- print( "event.transaction: " .. json.prettify( event.transaction ) )
elseif event.transaction.state == "restored" then -- Successful transaction
store.consumePurchase( currItem)
else -- Unsuccessful transaction; output error details
native.showAlert( "Info", "Unable to complete purchase" ,{"Ok"} )
end
-- Tell the store that the transaction is finished
store.finishTransaction( event.transaction )
end
local function loadiOSProducts()
if store.canLoadProducts then
store.loadProducts( IAPList, onLoadProducts )
end
end
-- Initialize IAP
if platformName=="android" then
store.init( transactionListenerAndroid )
elseif platformName=="iphone os" or platformName=="mac os x" or platformName=="tvos" then
store.init( transactionListeneriOS )
timer.performWithDelay( 3000, loadiOSProducts )
end
--somewhere in your code
store.purchase( realIAPList[ID_Of_Product] )