IAP store.init callback event not execute

Hi,

I do not understand why my  function “storeTransaction” is neved called by store.init

Yet “store.isActive” returns true

Thank you

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 } }, }, -- Android permissions androidPermissions = { "android.permission.INTERNET", "com.android.vending.BILLING", "com.android.vending.CHECK\_LICENSE", }, }

application = { content = { width = 320, height = 480, scale = "letterBox", fps = 30, --[[imageSuffix = { ["@2x"] = 2, } --]] }, license = { google = { key = "MIIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxDAQAB", }, }, --[[-- Push notifications notification = { iphone = { types = { "badge", "sound", "alert", "newsstand" } } } --]] }

local store = require( "plugin.google.iap.v3" ) local storeTransaction store.init( "google", storeTransaction ) print(tostring(store.isActive)) local function storeTransaction( event ) local transaction = event.transaction print ("transaction.state="..tostring(transaction.state)) if ( transaction.state == "purchased" ) then --handle a successful transaction here print( "productIdentifier", transaction.productIdentifier ) print( "receipt", transaction.receipt ) print( "signature:", transaction.signature ) print( "transactionIdentifier", transaction.identifier ) print( "date", transaction.date ) elseif ( transaction.state == "cancelled" ) then print ("transaction cancelled") --handle a cancelled transaction here elseif ( transaction.state == "failed" ) then print ("transaction failed") --handle a failed transaction here 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

Hi @shadrak,

This is because you’ve defined two different instances of “storeTransaction”: one as a local variable (which begins as nil), then you define the same name as a local function. They are not the same Lua reference however, so the init() function is not aware of your function at all.

Hope this helps,

Brent

Hi Brent Sorrentino

Thank you for your reply. In my real application, I have the same problem and I did not make the mistake of declaring the function twice.

Moreover, even correcting the error you reported to me, I still can not get to them executed the callback event.

Hi @shadrak,

Can you show me some code from your actual app then? I’d like to diagnose that instead of what you showed first.

Brent

Hi Brent,

This is my very simple code for test

Config.lua ( key is cut ) 

application = { content = { width = 320, height = 480, scale = "letterBox", fps = 30, showRuntimeErrors = true, --[[imageSuffix = { ["@2x"] = 2, } --]] }, license = { google = { key = "MIIBIjANBgkqhkiG9w0 .... KqYbj1esAmcap5QIDAQAB", }, }, --[[-- Push notifications notification = { iphone = { types = { "badge", "sound", "alert", "newsstand" } } } --]] }

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 } }, }, -- Android permissions android = { --versionCode = "16", usesPermissions = { "android.permission.INTERNET", "com.android.vending.BILLING", --"com.android.vending.CHECK\_LICENSE", }, }, }

main:

local store = require( "plugin.google.iap.v3" ) local tstate local function storeTransaction( event ) local transaction = event.transaction tstate=transaction.state print ("transaction.state="..tostring(transaction.state)) if ( transaction.state == "purchased" ) then --handle a successful transaction here print( "productIdentifier", transaction.productIdentifier ) print( "receipt", transaction.receipt ) print( "signature:", transaction.signature ) print( "transactionIdentifier", transaction.identifier ) print( "date", transaction.date ) elseif ( transaction.state == "cancelled" ) then print ("transaction cancelled") --handle a cancelled transaction here elseif ( transaction.state == "failed" ) then print ("transaction failed") --handle a failed transaction here 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 store.init( "google", storeTransaction ) print("store is active="..tostring(store.isActive))

my logcat:

C:\Users\Pascal\Desktop\>adb logcat Corona:v \*:s --------- beginning of /dev/log/system --------- beginning of /dev/log/main V/Corona ( 2312): \> Class.forName: network.LuaLoader V/Corona ( 2312): \< Class.forName: network.LuaLoader V/Corona ( 2312): Loading via reflection: network.LuaLoader I/Corona ( 2312): Platform: Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 / x86 / 4.3 / Android Emulator OpenGL ES Translator (GeForce GTS 450/PCIe/SSE2) / OpenGL ES 2.0 (4.4.0 NVIDIA 344.75) / 2015.2582 V/Corona ( 2312): \> Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): \< Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): Loading via reflection: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): \> Class.forName: plugin.google.iap.v3.LuaLoader V/Corona ( 2312): \< Class.forName: plugin.google.iap.v3.LuaLoader V/Corona ( 2312): Loading via reflection: plugin.google.iap.v3.LuaLoader I/Corona ( 2312): store is active=true

hoping to find the solution …

Pascal.

Hi Pascal,

This is strange, the code looks OK at a first review.

Is there a reason you have disabled the license permission with a comment (–) ?

Brent

Hi Brent,

I later added that permission. I do not know what it is for but was sometimes used in the Forums.

Enable this permission does not change my problem.

If my code is ok, it might be to see  my google play parameters.

Yet I can make a in-app purchase but impossible to check the status with store.init.

Pascal.

Ok, I realized my mistake ( big mistake )

The callback is not called immediately to the initialization but only when “store.purchase” is called. This is logical.

Hi @shadrak,

This is because you’ve defined two different instances of “storeTransaction”: one as a local variable (which begins as nil), then you define the same name as a local function. They are not the same Lua reference however, so the init() function is not aware of your function at all.

Hope this helps,

Brent

Hi Brent Sorrentino

Thank you for your reply. In my real application, I have the same problem and I did not make the mistake of declaring the function twice.

Moreover, even correcting the error you reported to me, I still can not get to them executed the callback event.

Hi @shadrak,

Can you show me some code from your actual app then? I’d like to diagnose that instead of what you showed first.

Brent

Hi Brent,

This is my very simple code for test

Config.lua ( key is cut ) 

application = { content = { width = 320, height = 480, scale = "letterBox", fps = 30, showRuntimeErrors = true, --[[imageSuffix = { ["@2x"] = 2, } --]] }, license = { google = { key = "MIIBIjANBgkqhkiG9w0 .... KqYbj1esAmcap5QIDAQAB", }, }, --[[-- Push notifications notification = { iphone = { types = { "badge", "sound", "alert", "newsstand" } } } --]] }

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 } }, }, -- Android permissions android = { --versionCode = "16", usesPermissions = { "android.permission.INTERNET", "com.android.vending.BILLING", --"com.android.vending.CHECK\_LICENSE", }, }, }

main:

local store = require( "plugin.google.iap.v3" ) local tstate local function storeTransaction( event ) local transaction = event.transaction tstate=transaction.state print ("transaction.state="..tostring(transaction.state)) if ( transaction.state == "purchased" ) then --handle a successful transaction here print( "productIdentifier", transaction.productIdentifier ) print( "receipt", transaction.receipt ) print( "signature:", transaction.signature ) print( "transactionIdentifier", transaction.identifier ) print( "date", transaction.date ) elseif ( transaction.state == "cancelled" ) then print ("transaction cancelled") --handle a cancelled transaction here elseif ( transaction.state == "failed" ) then print ("transaction failed") --handle a failed transaction here 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 store.init( "google", storeTransaction ) print("store is active="..tostring(store.isActive))

my logcat:

C:\Users\Pascal\Desktop\>adb logcat Corona:v \*:s --------- beginning of /dev/log/system --------- beginning of /dev/log/main V/Corona ( 2312): \> Class.forName: network.LuaLoader V/Corona ( 2312): \< Class.forName: network.LuaLoader V/Corona ( 2312): Loading via reflection: network.LuaLoader I/Corona ( 2312): Platform: Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 / x86 / 4.3 / Android Emulator OpenGL ES Translator (GeForce GTS 450/PCIe/SSE2) / OpenGL ES 2.0 (4.4.0 NVIDIA 344.75) / 2015.2582 V/Corona ( 2312): \> Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): \< Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): Loading via reflection: CoronaProvider.licensing.google.LuaLoader V/Corona ( 2312): \> Class.forName: plugin.google.iap.v3.LuaLoader V/Corona ( 2312): \< Class.forName: plugin.google.iap.v3.LuaLoader V/Corona ( 2312): Loading via reflection: plugin.google.iap.v3.LuaLoader I/Corona ( 2312): store is active=true

hoping to find the solution …

Pascal.

Hi Pascal,

This is strange, the code looks OK at a first review.

Is there a reason you have disabled the license permission with a comment (–) ?

Brent

Hi Brent,

I later added that permission. I do not know what it is for but was sometimes used in the Forums.

Enable this permission does not change my problem.

If my code is ok, it might be to see  my google play parameters.

Yet I can make a in-app purchase but impossible to check the status with store.init.

Pascal.

Ok, I realized my mistake ( big mistake )

The callback is not called immediately to the initialization but only when “store.purchase” is called. This is logical.