@ Naomi. Thank you so much. You are such a great help I think Ansca should hire you. I made the modification you suggested and I build it using the correct profile. I was I expected to see the “confirm your In-app purchase” window to pop up when I touch the continuebutton2 button. That did not happen. I am not sure why. Here’s the print statements I am getting from corona terminal when the project is loaded.
i am here 1
i am here 2
Calling: store.init
Calling: iap_setupMyStore
WARNING: store.loadProducts() is only supported on device.
>>>>>>>>>>>>After store.loadProducts, waiting for callback
When I click on the continuebutton2, I get these print statements:
iam here last
at buythis product id
I am still not sure if my “function savePurchase(product)”, " function transactionCallback( event )" and “local buyThis = function ( product )” functions are correct. My entire code is below. Can you please take a look at these functions and see if I am doing anything wrong? I’ve been trying to figure this out for a while and I am really not sure what is wrong. Thanks again for your help.
[code]
io.output():setvbuf(‘no’)
local store = require(“store”)
local listOfProducts = {
“com.mmm.xxxxxx”,
}
– In-App area
–local validProducts, invalidProducts = {}, {}
local validProducts = {}
local invalidProducts = {}
print (" i am here 1")
function unpackValidProducts()
print (">>>>>>>>>>>>>>Loading product list")
if not validProducts then
print(“not validProducts”)
native.showAlert( “In-App features not available”, “initStore() failed”, { “OK” } )
else
print(“looping through the invalidProducts”)
for numLoop=1, #invalidProducts do
native.showAlert( “Item " … invalidProducts[numLoop] … " is invalid.”,{ “OK” } )
end
end
if validProducts then
print("validProducts = " … tostring(validProducts))
print("validProducts[1].title = " … tostring(validProducts[1].title))
print("validProducts[1].description = " … tostring(validProducts[1].description))
print(“validProducts[1].price = " … tostring(validProducts[1].price))
print(“validProducts[1].productIdentifier = " … tostring(validProducts[1].productIdentifier))
end
end
print(” i am here 2”)
—=======================================
local loadProductsCallback = function( event )
– Debug info for testing
print(“loadProductsCallback()”)
print(“event, event.name”, event, event.name)
print(event.products)
print("#event.products", #event.products)
validProducts = event.products
invalidProducts = event.invalidProducts
unpackValidProducts ()
end
–===========================================
function savePurchase(product)
–function on what should be save when user buy a product
savePurchase(1) – when saving product1
end
–============================================
function transactionCallback( event )
if event.transaction.state == “purchased” then
print (“purchased product”)
–you should enter here the product being purchased
store.purchase( {validProducts[1]} )
elseif event.transcation.state == “restored” then
savePurchase(“product”) --you should enter here the product being purchased
store.purchase( {validProducts[1]} )
elseif event.transaction.state == “cancelled” then
elseif event.transaction.state == “failed” then
infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
local alert = native.showAlert("Failed ", infoString,{ “OK” })
else
infoString = “Unknown event”
local alert = native.showAlert("Unknown ", infoString,{ “OK” })
end
store.finishTransaction( event.transaction )
end
–======================================
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
print (">>>>>>>>>>>>After store.loadProducts, waiting for callback")
end
-----=========================================
continuebutton2 = ui.newButton{
defaultSrc = “images/continue_40_40.png”,
overSrc = “images/continue_40_40.png”,
defaultX = 130,
defaultY = 50,
overX = 130,
overY = 50,
–onEvent = onbuyButTouch,
–onPress = onbuyButTouch,
–onRelease = onbuyButTouch,
id =“continuebutton”,
text =“lock”,
font =“Arial”,
textColor = { 239, 230, 110, 255 },
align = “center”,
size = 16,
}
continuebutton2.x = display.contentWidth * 0.5
continuebutton2.y = display.contentHeight * 0.5+60
local onbuyButTouch = function(event)
if event.phase==“ended” then
print(" iam here last")
local buyThis = function ( product )
if store.canMakePurchases then
print(“at store.can make purchases”)
store.purchase( {validProducts[1]} )
else
native.showAlert(“Store purchases are not available, please try again later”, { “OK” } )
end
end
– Enter your product id here
print(“at buythis product id”)
buyThis (“com.xxx.xxxxx”)
end
end
timer.performWithDelay (1000, function() print(‘Calling: iap_setupMyStore’); setupMyStore() end )
timer.performWithDelay (500, function() print(‘Calling: store.init’); store.init( transactionCallback) end )
timer.performWithDelay(2000, startStore)
[/code] [import]uid: 104131 topic_id: 29458 reply_id: 118837[/import]