HI im trying to implement iap google v3 but crashes

im using this:

local StoreListener

local PLATAFORMA

local store

if ( system.getInfo( “platformName” ) == “Android” ) then

    store = require( “plugin.google.iap.v3” )

     PLATAFORMA=“ANDROID”

elseif ( system.getInfo( “platformName” ) == “iPhone OS” ) then

    store = require( “store” )

    PLATAFORMA=“IOS”

end

and this line code:

store.init( “google”, StoreListener )

give me this error----

Runtime error

I/Corona  (11811): ?:0: attempt to call field ‘?’ (a boolean value)

I/Corona  (11811): stack traceback:

I/Corona  (11811): ?: in function ‘new’

I/Corona  (11811): ?: in function ‘_onEvent’

I/Corona  (11811): ?: in function ‘?’

I/Corona  (11811): ?: in function <?:677>

I/Corona  (11811): ?: in function <?:221>


this is my build.settings

– Supported values for orientation:

– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

settings = {

orientation = {

default = “portrait”,

supported = { “portrait”, }

},

 plugins =

   

    {

        [“plugin.google.iap.v3”] =

        {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android=true }

        },

    

        [“plugin.google.play.services”] =

        {

            publisherId = “com.coronalabs”

        },

    },      

android =

{

permissions =

{

{ name = “.permission.C2D_MESSAGE”, protectionLevel = “signature” },

},

usesPermissions =

{

“android.permission.INTERNET”,

“android.permission.GET_ACCOUNTS”,

“android.permission.RECEIVE_BOOT_COMPLETED”,

“com.google.android.c2dm.permission.RECEIVE”,

“.permission.C2D_MESSAGE”,

  “com.android.vending.BILLING”,

“android.permission.ACCESS_NETWORK_STATE”,

},

},

iphone = {

plist = {

UIAppFonts =

            {

                “orange juice 2.0.ttf”,

               

            },

            

UIStatusBarHidden = true,

UIPrerenderedIcon = false, – set to false for “shine” overlay

–UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend

            CFBundleIconFile = “Icon.png”,

CFBundleIconFiles =

{

                “Icon.png”, 

                “Icon@2x.png”, 

                “Icon-60.png”,

                “Icon-60@2x.png”,

                “Icon-72.png”, 

                “Icon-72@2x.png”,

                “Icon-76.png”,

                “Icon-76@2x.png”, 

                

},

            

            

            --[[

            – iOS app URL schemes:

            CFBundleURLTypes =

            {

                {

                    CFBundleURLSchemes =

                    {

                        “fbXXXXXXXXXXXXXX”, – example scheme for facebook

                        “coronasdkapp”, – example second scheme

                    }

                }

            }

            --]]

}

},

}

and this is my config.lua

local aspectRatio = display.pixelHeight / display.pixelWidth

–print(aspectRatio)

application = {

content = {

     width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio ),

      height = aspectRatio < 1.5 and 480 or math.ceil( 320 * aspectRatio ),

      --width = 320,

–height = 480, 

scale = “letterBox”,

fps = 30,

},

notification =

{

google =

{

– This Project Number (also known as a Sender ID) tells Corona to register this application

– for push notifications with the Google Cloud Messaging service on startup.

– This number can be obtained from the Google API Console at:  https://code.google.com/apis/console

projectNumber = “changed for this post”,

},

},

 license =

{

google =

{

key = “XXX my key of course i change it to make this post”,

– This is optional, it can be strict or serverManaged(default).

– stric WILL NOT cache the server response so if there is no network access then it will always return false.

– serverManaged WILL cache the server response so if there is no network access it can use the cached response.

–policy = “serverManaged”, 

},

},

    

    --[[

    – Push notifications

    notification =

    {

        iphone =

        {

            types =

            {

                “badge”, “sound”, “alert”, “newsstand”

            }

        }

    }

    --]]    

}

What im doing wrong?

Hi @Rene.castillo,

Where do you define your “StoreListener” function? Is it in the proper scope so the store.init() function recognizes it?

Brent

yes are exactly the first part of my code before make the require for the plugin…

Hi Rene,

Yes, I see the local declaration for “StoreListener”, but what does the actual function look like, and where is it located?

Thanks,

Brent

like this in the middle of my code its the function listener:

[lua]

StoreListener=function( event )

    local transaction = event.transaction

    

    if transaction.state == “restored” then

        if transaction.productIdentifier==“lasopa…xxxxxchangedfor the post” then

        print(“corazones ilimitados”)

        Game.vidas=10000

        MASTER.confirmacion(“Hemos recuperado tus corazones ilimitados!”,1)

        end

    elseif ( transaction.state == “purchased” ) then

       

        local prod=transaction.productIdentifier

        if prod==“changed for the post” then

        Game.totalsopas=Game.totalsopas+8000

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 8,000 Monedas más a tu cuenta!”,1)        

        elseif prod==“changed for the post”  then

      Game.totalsopas=Game.totalsopas+29000

      MASTER.actualizavalores(0,0,0,0)

       MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 29,000 Monedas más a tu cuenta!”,1)

         elseif prod==“lchanged for the post”  then

  Game.totalsopas=Game.totalsopas+75000

  MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 75,000 Monedas más a tu cuenta!”,1)

         elseif prod==“lchanged for the post”  then

       Game.totalsopas=Game.totalsopas+250000

       MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 250,000 Monedas más a tu cuenta!..”,1)

         elseif prod==“changed for the post”  then

        Game.publicidad=false

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Disftuta ahora sin publicidad alguna!..”,1)

   

        elseif prod==“lchanged for the post” then

        Game.vidas=1000

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Disftuta de tus corazones Ilimitados…”,1)

       

        end

        

    elseif ( transaction.state == “cancelled” ) then

        --handle a cancelled transaction here

        

    elseif ( transaction.state == “refunded” ) then

print (“quita el contenido comprado que lo pidio pa tra”)

    elseif ( transaction.state == “failed” ) then

        --handle a failed transaction here

        

         --handle a failed transaction here

         elseif ( transaction.state == “revoked” ) then

    end

    --tell the store that the transaction is complete!

    --if you’re providing downloadable content, do not call this until the download has completed

   store.finishTransaction( event.transaction )

end–listener

[/lua]

What happens if you move your store.init() call until after you define StoreListener’s function?

Rob

Hi @Rene.castillo,

Where do you define your “StoreListener” function? Is it in the proper scope so the store.init() function recognizes it?

Brent

yes are exactly the first part of my code before make the require for the plugin…

Hi Rene,

Yes, I see the local declaration for “StoreListener”, but what does the actual function look like, and where is it located?

Thanks,

Brent

like this in the middle of my code its the function listener:

[lua]

StoreListener=function( event )

    local transaction = event.transaction

    

    if transaction.state == “restored” then

        if transaction.productIdentifier==“lasopa…xxxxxchangedfor the post” then

        print(“corazones ilimitados”)

        Game.vidas=10000

        MASTER.confirmacion(“Hemos recuperado tus corazones ilimitados!”,1)

        end

    elseif ( transaction.state == “purchased” ) then

       

        local prod=transaction.productIdentifier

        if prod==“changed for the post” then

        Game.totalsopas=Game.totalsopas+8000

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 8,000 Monedas más a tu cuenta!”,1)        

        elseif prod==“changed for the post”  then

      Game.totalsopas=Game.totalsopas+29000

      MASTER.actualizavalores(0,0,0,0)

       MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 29,000 Monedas más a tu cuenta!”,1)

         elseif prod==“lchanged for the post”  then

  Game.totalsopas=Game.totalsopas+75000

  MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 75,000 Monedas más a tu cuenta!”,1)

         elseif prod==“lchanged for the post”  then

       Game.totalsopas=Game.totalsopas+250000

       MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Se han agregado 250,000 Monedas más a tu cuenta!..”,1)

         elseif prod==“changed for the post”  then

        Game.publicidad=false

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Disftuta ahora sin publicidad alguna!..”,1)

   

        elseif prod==“lchanged for the post” then

        Game.vidas=1000

        MASTER.actualizavalores(0,0,0,0)

MASTER.confirmacion(“Compra Realizada con Éxito! Disftuta de tus corazones Ilimitados…”,1)

       

        end

        

    elseif ( transaction.state == “cancelled” ) then

        --handle a cancelled transaction here

        

    elseif ( transaction.state == “refunded” ) then

print (“quita el contenido comprado que lo pidio pa tra”)

    elseif ( transaction.state == “failed” ) then

        --handle a failed transaction here

        

         --handle a failed transaction here

         elseif ( transaction.state == “revoked” ) then

    end

    --tell the store that the transaction is complete!

    --if you’re providing downloadable content, do not call this until the download has completed

   store.finishTransaction( event.transaction )

end–listener

[/lua]

What happens if you move your store.init() call until after you define StoreListener’s function?

Rob