In-app Purchases not Accessing Google Play Store

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

Here is the Console Print Out

I/Corona  ( 7083): Runtime error
I/Corona  ( 7083): ?:0: attempt to index field ‘availableStores’ (a nil value)
I/Corona  ( 7083): stack traceback:
I/Corona  ( 7083):     ?: in function ‘_onRelease’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button.lua:113: in function ‘manageButtonTouch’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button.lua:681: in function ‘method’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:253: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:221>

You probably should flip the tests for iOS and Google.  By the time you get to:

if ( store.availableStores.apple ) then

and you’re using the Google IAP v3 plugin, store has been replaced by the plugin version and it doesn’t have an avaialbleStores table and that’s probably where you’re erroring.  If you put Google in the “if” part of the test and leave Apple to the “else”, it should work because the v3 will be true and it won’t check that condition any further.

Rob

Here is the Console Print Out

I/Corona  ( 7083): Runtime error
I/Corona  ( 7083): ?:0: attempt to index field ‘availableStores’ (a nil value)
I/Corona  ( 7083): stack traceback:
I/Corona  ( 7083):     ?: in function ‘_onRelease’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button.lua:113: in function ‘manageButtonTouch’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button.lua:681: in function ‘method’
I/Corona  ( 7083):     /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:253: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:221>

You probably should flip the tests for iOS and Google.  By the time you get to:

if ( store.availableStores.apple ) then

and you’re using the Google IAP v3 plugin, store has been replaced by the plugin version and it doesn’t have an avaialbleStores table and that’s probably where you’re erroring.  If you put Google in the “if” part of the test and leave Apple to the “else”, it should work because the v3 will be true and it won’t check that condition any further.

Rob

after trying and failing for WEEKS this is the only solution that worked (along with Robs suggestions). Everybody follow this strategy, for android anyways. Not sure yet if it works for apple.

after trying and failing for WEEKS this is the only solution that worked (along with Robs suggestions). Everybody follow this strategy, for android anyways. Not sure yet if it works for apple.