I have my in-app purchases accessed by a button press. The information such as what is being purchased and how much are already on the button graphic. I have build.settings set up and config set up with the ‘key’ and internet information. Can anybody tell me if I am doing anything wrong with the code that is shown here?
*Update - While Debugging the issue is ( “availableStores” is a nil value ). I still don’t know how to fix it.
local store local v3 = false if ( system.getInfo( "platformName" ) == "Android" ) then store = require( "plugin.google.iap.v3" ) v3 = true elseif ( system.getInfo( "platformName" ) == "iPhone OS" ) then store = require( "store" ) else store = require( "store" ) native.showAlert( "Notice", "In-app purchases are not supported in the Corona Simulator.", { "OK" } ) end
----------------------------------------------------------------------------------------- -- Bomb Button Configuration ----------------------------------------------------------------------------------------- -- 'onRelease' event listener for bombBtn local function onBombBtnRelease() sfx.play( sfx.menuPress, { channel = 2, onComplete = function() end; } ) boughtItem = "light" ----------------------------------------------------------------------------------------- -- Store Transaction Callback ----------------------------------------------------------------------------------------- function transactionCallback2( event ) local transaction = event.transaction local tstate = event.transaction.state if tstate == "purchased" then if boughtItem == "light" then native.showAlert("Thank you!", "You just purchased Light Boost Pack!", {"Okay"}) else end store.finishTransaction( transaction ) elseif tstate == "consumed" then store.finishTransaction( transaction ) elseif tstate == "cancelled" then store.finishTransaction( transaction ) elseif tstate == "failed" then store.finishTransaction( transaction ) else store.finishTransaction( transaction ) end --print("done with store business for now") end if ( store.availableStores.apple ) then timer.performWithDelay(1000, function() store.init( "apple", transactionCallback2 ); end ) elseif ( v3 == true or store.availableStores.google ) then timer.performWithDelay( 1000, function() store.init( "google", transactionCallback2 ) store.restore() end ) else print( "In-app purchases are not supported on this system/device." ) end if ( system.getInfo( "platformName" ) == "Android" ) then store.consumePurchase( "com.tagfriendzy.light", transactionCallback2 ) elseif ( system.getInfo( "platformName" ) == "iPhone OS" ) then store.purchase( {"com.tagfriendzy.light"} ) else native.showAlert( "Notice", "In-app purchases are not supported in the Corona Simulator.", { "OK" } ) end return true end -- create a widget button bombBtn = widget.newButton{ defaultFile="image/store/StoreBtn99\_Up.png", overFile="image/store/StoreBtn99\_Down.png", width=125, height=31, onRelease = onBombBtnRelease -- event listener function } bombBtn.x = myData.\_W\*0.50 - 75 bombBtn.y = myData.\_H\*0.50 + 22