store.availableStores returning bill with Google yap v3

Hi, I followed the instruction to configure my build.settings and config.lua and to declare the plugin like this:

local store = require("store") if store.target == "google" then     store = require("plugin.google.iap.v3") end

and I have this code inside a method to check the store:

if store.availableStores.apple then -- do something elseif store.availableStores.google then -- do something else -- do something end

However, my app runs also in iOS and Android, and when I run it on a Android device, I receive a error:  “attempt to index field ‘availableStores’ (a nil value)”

What is the best approach to solve this? Should I use store.target instead of store.availableStores? Actually I don’t understand very well what’s the difference between store.target and store.availableStores. Can anyone help?

Thank you very much

local v3 = false local store = require("store") if store.target == "google" then store = require("plugin.google.iap.v3") v3 = true end if store.availableStores.apple then -- do something elseif store.availableStores.google or v3 then -- do something else -- do something end

The target store is what you set in the build dialog.  availableStores are the iap stores we support.  For example you might target Samsung but we don’t support it so its not in availableStores.

Quite simple solution…  :slight_smile:

Thank you very much

Shouldn’t that be:

elseif v3 or store.availableStores.google then

…otherwise you’ll get a crash when running an app deployed for Google.

store.availableStores isn’t defined in the Google IAB V3 plugin as far as I know…

Actually the or store.availableStores.google check is redundant since the previously posted code above always loads the V3 plugin for Google deployments.

Yes, that’s is true ingemar, this is the best approach…

local v3 = false local store = require("store") if store.target == "google" then store = require("plugin.google.iap.v3") v3 = true end if store.availableStores.apple then -- do something elseif store.availableStores.google or v3 then -- do something else -- do something end

The target store is what you set in the build dialog.  availableStores are the iap stores we support.  For example you might target Samsung but we don’t support it so its not in availableStores.

Quite simple solution…  :slight_smile:

Thank you very much

Shouldn’t that be:

elseif v3 or store.availableStores.google then

…otherwise you’ll get a crash when running an app deployed for Google.

store.availableStores isn’t defined in the Google IAB V3 plugin as far as I know…

Actually the or store.availableStores.google check is redundant since the previously posted code above always loads the V3 plugin for Google deployments.

Yes, that’s is true ingemar, this is the best approach…

Hi,  Im getting the “attempt to index field ‘availableStores’ (a nil value)” too when running on android.

Looking at what you put @dchan, I dont understand how that fixes the issues as you are still trying to access the method when you check store.availableStores.apple

Maybe I am missing something obvious?  Could someone explain what the solution is please :slight_smile:

Thanks 

this is what i have:

local store local v3 = false if ( system.getInfo( "platformName" ) == "Android" ) then store = require( "plugin.google.iap.v3" ) v3 = true print("Using Google Play") elseif ( system.getInfo( "platformName" ) == "iPhone OS" ) then store = require( "store" ) print("Using iTunes") else print("In-app purchases are not supported in the Corona Simulator.") end

--utilize 'store.availableStores' function: if store ~= nil then if ( store.availableStores.apple ) then currentProductList = appleProductList store.init( "apple", storeTransaction ) elseif ( v3 == true or store.availableStores.google ) then currentProductList = googleProductList store.init( "google", storeTransaction ) else print( "In-app purchases are not supported on this system/device." ) end end

You should change the logic a bit. Something like this should work:

if store ~= nil then if ( v3 == true ) then -- use Google IAB V3 currentProductList = googleProductList store.init( "google", storeTransaction ) elseif ( store.availableStores.apple ) then currentProductList = appleProductList store.init( "apple", storeTransaction ) else print( "In-app purchases are not supported on this system/device." ) end end

Like you have noted, the previous example given tries to access store.availableStores which isn’t always present.

In the adjusted logic above I have only included v3 == true since store.availableStores.google doesn’t exist in the v3 version of the plugin.

thanks for the reply,  @ingemar.

I tried that but it still didn’t work for me.  I ended up doing this in the end which seems to work but doesn’t feel very neat.

if (v3 == true) then currentProductList = googleProductList store.init( "google", storeTransaction ) elseif ( store.availableStores ~= nil ) then if ( store.availableStores.apple ) then currentProductList = appleProductList store.init( "apple", storeTransaction ) end else print( "In-app purchases are not supported on this system/device." ) end

@david

The code I posted should work. I tested it in a simple test project and it handles Apple and Google V3 without crashing.

What was the problem you saw?

Hi all,

I have a problem similar to yours, perhaps worse.

With V3, on a physical device, GalaxyS GT-I9003 (quite old, Android 2.3.6) the code below crashes the app ( ! i.e. stops and freezes the display. App remains dead with display freezed). After a while an Android message ‘the app is no longer responding’ glows and I may terminate the app.

This same code works smooth in iOS.

In build.settings among plugins=

["plugin.google.iap.v3"] =        {             publisherId = "com.coronalabs",             supportedPlatforms = { android=true }         },.

And among android=:

usesPermissions =         {           "com.android.vending.BILLING",           --"com.android.vending.CHECK\_LICENSE",         },

In the scene:create I have:

if ( device.isAndroid ) then        store = require( "plugin.google.iap.v3" )         v3 = true         infoLabel.text="Google store plugin  load"     elseif ( device.isApple ) then         infoLabel.text="Apple store library load"         store = require( "store" )     end

if  (store~=nil) then              --utilize 'store.availableStores' function:             if device.isApple and store.availableStores.apple then                 currentProductList = appleProductList                 store.init( "apple", storeTransaction )             --elseif ( v3 == true or store.availableStores.google ) then             elseif ( v3 == true ) then                 currentProductList = googleProductList                 store.init( "google", storeTransaction )             else                 local message= "In-app purchases are not supported on this system/device."                 native.showAlert( system.getInfo("appName"), message , { "Ok"},exitFromIap )             end         end         if device.isApple and ( not store.canMakePurchases)  then             message=translations.localize("warnpurchasenotenabled", "language")             native.showAlert( system.getInfo("appName"), message , { "Ok"},exitFromIap )         end

I have removed the store.availableStores.google according to this conversation. But the problem still exists.

Do you have any idea ?

Thank you.

Stefano

@stefano
I’m starting to suspect that the Google Play Store app you have installed on the device may not support IAB V3.
If possible try to see if you can update it.

Also, to see what’s going on, connect your device to your computer and do a ‘adb logcat’ to see what’s crashing.

The log cat says:

10-08 18:06:47.695: V/Corona(5185): > Class.forName: plugin.google.iap.v3.LuaLoader

10-08 18:06:47.703: V/Corona(5185): < Class.forName: plugin.google.iap.v3.LuaLoader

10-08 18:06:47.703: V/Corona(5185): Loading via reflection: plugin.google.iap.v3.LuaLoader

and then stops !

I have the Google Play Store 4.9.13 and Google Play Games 2.0.13

Does it make any sense ?

BTW: thank you for your help.

Stefano

Does the device have the Google Play app installed (and latest version)?    Opps never mind. I didn’t see the message below the code.

Rob

@Rob

Hello, thanks for any help as well !

Hi ingemar - I tried it again and now it works as you said… very strange - I reverted to my older version so it is the exact same code that didn’t work before.  Maybe I forgot to save my file before building haha either way - that part now work!  cheers :slight_smile:

@st.tosi 

I had this problem too but for me, adding the licence key from google dev console resolved it. 

it does not mention it in this article http://docs.coronalabs.com/daily/guide/monetization/IAP/index.html

but it does in this one :   http://docs.coronalabs.com/daily/plugin/google-iap-v3/

(it’s a plugin so I don’t think it matters but i’m on the latest daily build 2014.2458)

Project Configuration

To use Google IAP v3, the license table must be added to the project config.lua file. Inside this table, the key value should be set to the corresponding key obtained from the Google Play Developer Console.

application = { license = { google = { key = "Your key", }, }, }

@rob - off on a complete tangent but…  I upgraded to pro recently but it still says starter under my name? anything to worry about? 

@David

Thanks a lot ! You fixed this issue with your answer. Appreciated.

I missed to add the license key. It is now loading the plugin.

The thing is now it is crashing a little bit later (as usual: Google only. Apple goes) at the store.init call. Full crash: device blocked up. Message on device glows to terminate the not responding app etc.

Code:

in main.lua:

if (device.isAndroid) then print("DEVICE=Android") local licensing = require( "licensing" ) licensing.init( "google" ) local function licensingListener( event ) local verified = event.isVerified print( "address", event.address ) print("name", event.name) print("provider", event.provider) print("isVerified", event.isVerified) print("isError", event.isError) print("errorType", event.errorType) print("response", event.response) if not event.isVerified then --failed verify app from the play store, we print a message print( "Binary NOT BEING VERIFIED from the Google App Store !" ) --native.requestExit() --assuming this is how we handle pirates else print( "Google app has been verified" ) end end licensing.verify( licensingListener ) end

in the InAppPurchase .lua file:

if ( device.isAndroid ) then store = require( "plugin.google.iap.v3" ) v3 = true message="Google store plugin loaded" elseif ( device.isApple ) then message="Apple store library loaded" store = require( "store" ) end if (store ~= nil) then print ("STORE loaded: ".. message) else print ("STORE NOT loaded: ".. message) end

if (store~=nil) then --utilize 'store.availableStores' function: if device.isApple and store.availableStores.apple then currentProductList = appleProductList store.init( "apple", storeTransaction ) --elseif ( v3 == true or store.availableStores.google ) then elseif ( v3 == true ) then currentProductList = googleProductList store.init( "google", storeTransaction ) print ("Google store initialized") else local message= "In-app purchases are not supported on this system/device." native.showAlert( system.getInfo("appName"), message , { "Ok"},exitFromIap ) end end if device.isApple and ( not store.canMakePurchases) then message=translations.localize("warnpurchasenotenabled", "language") native.showAlert( system.getInfo("appName&nbsp;

The crash comes up at the store.init statement. Verified.

The above code prints in the DDMS console:

10-10 18:38:30.859: V/Corona(21662): > Class.forName: CoronaProvider.gameNetwork.google.LuaLoader

10-10 18:38:30.859: V/Corona(21662): < Class.forName: CoronaProvider.gameNetwork.google.LuaLoader

10-10 18:38:30.859: V/Corona(21662): Loading via reflection: CoronaProvider.gameNetwork.google.LuaLoader

10-10 18:38:35.656: I/Corona(21662): address nil

10-10 18:38:35.656: I/Corona(21662): name licensing

10-10 18:38:35.656: I/Corona(21662): provider google

10-10 18:38:35.656: I/Corona(21662): isVerified false

10-10 18:38:35.656: I/Corona(21662): isError true

10-10 18:38:35.656: I/Corona(21662): errorType configuration

10-10 18:38:35.656: I/Corona(21662): response Not market managed

10-10 18:38:35.656: I/Corona(21662): Binary NOT BEING VERIFIED from the Google App Store !

10-10 18:38:44.757: V/Corona(21662): > Class.forName: plugin.google.iap.v3.LuaLoader

10-10 18:38:44.765: V/Corona(21662): < Class.forName: plugin.google.iap.v3.LuaLoader

10-10 18:38:44.765: V/Corona(21662): Loading via reflection: plugin.google.iap.v3.LuaLoader

10-10 18:38:44.773: I/Corona(21662): STORE loaded: Google store plugin  loaded

The app does not come from the market: it obviously comes from my adb install command  of my Mac. Anything related to that ?

Any idea ?

@Rob I also recently (few days) upgraded to Basic but I am always registered here as a Starter: same comment of David. Shall I stay in trouble for that ?