Hello people! I need some help with restore button!
And in case that my app promotion starts really soon, i need it as fast as possible.
Apple rejected my app in case that restore button doesn’t work properly.
I won’t tell you how i did this, i will just paste my code here.
If there is any error, please tell me. Thank you.
one of my items to purchase and it’s function:
local whiskeyBot = display.newImageRect("whiskey.png", 106, 205) whiskeyBot.x = screenW/1.28 whiskeyBot.y = screenH/1.42 whiskeyBot.alpha=0 local whiskeyFunc = function(event) if event.phase == "ended" then circle.x = whiskeyBot.x circle.y = whiskeyBot.y circle.alpha=1 audio.play( tapsound, {channel=2}) -- Handler that gets notified when the alert closes if require("socket").connect("google.com", 80) == nil then print("No connection") local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then circle.alpha=0 end end end -- Show alert with two buttons native.showAlert( "Shop", "Store is not available. Please check your internet connection.", { "OK" }, onComplete ) else local buyWhiskey = function ( product ) print ("Congrats! Purchasing " ..product) -- Purchase the item if store.canMakePurchases then infoString = "Can make purchases!" store.purchase( {"whiskey\_bottle"} ) else native.showAlert("Store purchases are not available, please try again later", { "OK" } ) end end -- Enter your product ID here buyWhiskey("whiskey\_bottle") end end end whiskeyBot:addEventListener("touch", whiskeyFunc)
In-app code:
-----------IN-APP-INIT local store = require "store" -----------IN-APP-INIT local listOfProducts = { -- These Product IDs must already be set up in your store -- Note, this simple test only has room for about 4 items, please adjust accordingly -- The iTunes store will not validate bad Product IDs -- Replace with a valid Product ID from iTunes Connect "all\_bottle", "absinth\_bottle", "beer\_bottle", "champagne\_bottle", "cognac\_bottle", "port\_bottle", "vermouth\_bottle", "champagne2\_bottle", "xo\_bottle", "whiskey\_bottle" } ---------------------------------- -- In-App area ---------------------------------- local validProducts = {} local invalidProducts = {} local unpackValidProducts = function() print ("Loading product list") if not validProducts then native.showAlert( "In-App features not available", "initStore() failed", { "OK" } ) else print( "Found " .. #validProducts .. " valid items ") infoString = ( "Found " .. #validProducts .. " valid items ") print(validProducts[1].localizedPrice) PriceOne = (validProducts[1].localizedPrice) print(validProducts[2].localizedPrice) PriceTwo = (validProducts[2].localizedPrice) print(validProducts[3].localizedPrice) PriceThree = (validProducts[3].localizedPrice) print(validProducts[4].localizedPrice) PriceFour = (validProducts[4].localizedPrice) print(validProducts[5].localizedPrice) PriceFive = (validProducts[5].localizedPrice) print(validProducts[6].localizedPrice) PriceSix = (validProducts[6].localizedPrice) print(validProducts[7].localizedPrice) PriceSeven = (validProducts[7].localizedPrice) print(validProducts[8].localizedPrice) PriceEight = (validProducts[8].localizedPrice) print(validProducts[9].localizedPrice) PriceNine = (validProducts[9].localizedPrice) print(validProducts[10].localizedPrice) PriceTen = (validProducts[10].localizedPrice) for i=1, #invalidProducts do -- Debug: display the product info native.showAlert( "Item " .. invalidProducts[i] .. " is invalid.",{ "OK" } ) print("Item " .. invalidProducts[i] .. " is invalid.") end end end 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 local transactionCallback = function( event ) if event.transaction.state == "purchased" then print("Transaction successful!") infoString = "Transaction successful!" if event.transaction.productIdentifier == "all\_bottle" then allBot:set("allBot", "yes") allBot:save() absinth:set("absinth", "yes") absinth:save() beer:set("beer", "yes") beer:save() champagne:set("champagne", "yes") champagne:save() cognac:set("cognac", "yes") cognac:save() port:set("port", "yes") port:save() vermouth:set("vermouth", "yes") vermouth:save() champagne2:set("champagne2", "yes") champagne2:save() xo:set("xo", "yes") xo:save() whiskey:set("whiskey", "yes") whiskey:save() end if event.transaction.productIdentifier == "absinth\_bottle" then absinth:set("absinth", "yes") absinth:save() end if event.transaction.productIdentifier == "beer\_bottle" then beer:set("beer", "yes") beer:save() end if event.transaction.productIdentifier == "champagne\_bottle" then champagne:set("champagne", "yes") champagne:save() end if event.transaction.productIdentifier == "cognac\_bottle" then cognac:set("cognac", "yes") cognac:save() end if event.transaction.productIdentifier == "port\_bottle" then port:set("port", "yes") port:save() end if event.transaction.productIdentifier == "vermouth\_bottle" then vermouth:set("vermouth", "yes") vermouth:save() end if event.transaction.productIdentifier == "champagne2\_bottle" then champagne2:set("champagne2", "yes") champagne2:save() end if event.transaction.productIdentifier == "xo\_bottle" then xo:set("xo", "yes") xo:save() end if event.transaction.productIdentifier == "whiskey\_bottle" then whiskey:set("whiskey", "yes") whiskey:save() end local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then circle.alpha=0 tl = timer.performWithDelay(500, function() director:changeScene("shop", "fade") timer.cancel(tl) end, 1) end end end -- Show alert with two buttons local alert = native.showAlert( "Shop", "Thank you! Your purchase is done!", { "OK" }, onComplete) elseif event.transcation.state == "restored" then if event.transaction.productIdentifier == "all\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<All bottles\> has been restored!", { "OK" }) allBot:set("allBot", "yes") allBot:save() absinth:set("absinth", "yes") absinth:save() beer:set("beer", "yes") beer:save() champagne:set("champagne", "yes") champagne:save() cognac:set("cognac", "yes") cognac:save() port:set("port", "yes") port:save() vermouth:set("vermouth", "yes") vermouth:save() champagne2:set("champagne2", "yes") champagne2:save() xo:set("xo", "yes") xo:save() whiskey:set("whiskey", "yes") whiskey:save() end if event.transaction.productIdentifier == "absinth\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Absinth bottle\> has been restored!", { "OK" }) absinth:set("absinth", "yes") absinth:save() end if event.transaction.productIdentifier == "beer\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Beer bottle\> has been restored!", { "OK" }) beer:set("beer", "yes") beer:save() end if event.transaction.productIdentifier == "champagne\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Champagne bottle\> has been restored!", { "OK" }) champagne:set("champagne", "yes") champagne:save() end if event.transaction.productIdentifier == "cognac\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Cognac bottle\> has been restored!", { "OK" }) cognac:set("cognac", "yes") cognac:save() end if event.transaction.productIdentifier == "port\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Port bottle\> has been restored!", { "OK" }) port:set("port", "yes") port:save() end if event.transaction.productIdentifier == "vermouth\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Vermouth bottle\> has been restored!", { "OK" }) vermouth:set("vermouth", "yes") vermouth:save() end if event.transaction.productIdentifier == "champagne2\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Champagne Holiday bottle \> has been restored!", { "OK" }) champagne2:set("champagne2", "yes") champagne2:save() end if event.transaction.productIdentifier == "xo\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<XO bottle\> has been restored!", { "OK" }) xo:set("xo", "yes") xo:save() end if event.transaction.productIdentifier == "whiskey\_bottle" then native.showAlert( "Shop", "Thank you! Purchase \<Whiskey bottles\> has been restored!", { "OK" }) whiskey:set("whiskey", "yes") whiskey:save() end native.showAlert( "Shop", "Thank you! Purchase \<Whiskey bottles\> has been restored!", { "OK" }) elseif event.transaction.state == "cancelled" then print("Transaction cancelled by user.") infoString = "Transaction canceled by user!" circle.alpha=0 elseif event.transaction.state == "failed" then print("Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString) local alert = native.showAlert("Failed ", infoString,{ "OK" }) circle.alpha=0 else print("Unknown event") local alert = native.showAlert("Unknown ", infoString,{ "OK" }) circle.alpha=0 end -- Tell the store we are done with the transaction. -- If you are providing downloadable content, do not call this until -- the download has completed. store.finishTransaction( event.transaction ) circle.alpha=0 end local setupMyStore = function(event) store.loadProducts( listOfProducts, loadProductsCallback ) print ("After store.loadProducts(), waiting for callback") end --------------------------------------------------------------------
Restore btn function:
local restoreFunction = function ( event ) if event.phase == "release" then local function onCompleteX( event ) if "clicked" == event.action then local i = event.index if 1 == i then store.restore(transactionCallback) elseif 2 == i then -- Open URL if "Learn More" (the 2nd button) was clicked end end end -- Show alert with two buttons local alertX = native.showAlert( "Shop", "Restore Purchases?", { "Yes", "No" }, onCompleteX ) end end
And in app init
------APP-TURNON----- -- Connect to store at startup, if available. if store.availableStores.apple then print("Using Apple's in-app purchase system.") infoString = "Using Apple's in-app purchase system." store.init("apple", transactionCallback) timer.performWithDelay (500, setupMyStore) elseif store.availableStores.google then print("Using Google's Android In-App Billing system.") infoString = "Using Google's Android In-App Billing system." store.init("google", transactionCallback) else print("In-app purchases is not supported on this system/device.") infoString = "In-app purchases is not supported on this system/device." end ------APP-TURNON-----
The thing is that when i touch Restore btn, nothing happens.
Any help will be appreciated.