transactionCallback is only being called on transaction cancellation

Here’s my code in details:

build.settings:

-- -- Android Section -- android = { usesPermissions = { "android.permission.INTERNET", "android.permission.VIBRATE",       "com.android.vending.BILLING",       "com.android.vending.CHECK\_LICENSE", }, },     plugins =     {         ["CoronaProvider.analytics.flurry"] =         {             publisherId = "com.coronalabs"         },         ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },         ["plugin.google.iap.v3"] =         {             publisherId = "com.coronalabs",             supportedPlatforms = { android=true }         },     },

config.lua:

application = {     license =     {         google =         {             key = "The key I got from 'SERVICES & APIS' in Google Play Developer console",         },     }, }

main.lua:

composer.gotoScene( "scripts.menu" )

scripts/menu.lua

local composer = require( "composer" ) local scene = composer.newScene() local widget = require "widget" local global = require( "scripts.global" ) -------------------------------------------- function scene:create( event ) local sceneGroup = self.view ... if not isFullVersion then buyBtn = widget.newButton{ defaultFile="images/buttons/full-version.png", overFile="images/buttons/full-version-over.png", width=stool.width / 2048 \* 414 \* 1.6, height=stool.height / 1536 \* 83 \* 1.6, onRelease = function () audio.play( tapSound, { channel = 3 } ) license.showBuyFullVersion( "locked-home" ) return true end } buyBtn.x = prevBtn.x buyBtn.y = prevBtn.y + firstBtn.height + (display.contentHeight / 2 \* 0.02) end ... return scene

scripts/global.lua:

...

store = require( “store” )

if store.target == “google” then

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

end

if store.target == “amazon” then

    store = require( “plugin.amazon.iap” )

end

transaction = require( “scripts.libs.transaction” )

scripts/libs/transaction.lua:

function transactionCallback( event )     local transaction = event.transaction     local tstate = event.transaction.state     print( "here" )     print( transaction )     print( tstate )     print( "end here" )     if ( tstate == "purchased" ) then         license.create( )         print( "Transaction succuessful!" )         print( "productIdentifier:", transaction.productIdentifier )         print( "receipt:", transaction.receipt )         print( "transactionIdentifier:", transaction.identifier )         print( "date:", transaction.date )     elseif ( tstate == "restored" ) then         license.create( )         print( "Transaction restored from previous session" )         print( "productIdentifier:", transaction.productIdentifier )         print( "receipt:", transaction.receipt )         print( "transactionIdentifier:", transaction.identifier )         print( "date:", transaction.date )         print( "originalReceipt:", transaction.originalReceipt )         print( "originalTransactionIdentifier:", transaction.originalIdentifier )         print( "originalDate:", transaction.originalDate )     elseif ( tstate == "cancelled" ) then         print( "User cancelled transaction" )     elseif ( tstate == "failed" ) then         print( "Transaction failed:", transaction.errorType, transaction.errorString )     else         print( "Unknown event" )     end     license.buyGroup:removeSelf( )     license.buyGroup = nil     -- Tell the store that the transaction is finished     -- If you are providing downloadable content, wait until after the download completes     store.finishTransaction( transaction ) end store.init( "google", transactionCallback )

license.lua:

... store.purchase( { "android.test.purchased" } ) ...

The purchase box is invoked with the fake transaction from Google and it’s telling me when I hit buy that the transaction was successful. Except transactionCallback is not being called, I can tell because print( “here” ) is not printed in my console (using adb logcat) except when I discard the box.

Please help.

Hi @jongar,

Please clarify your code a little better so we can assist you. You show 3 instances of require()-ing the store, but we don’t know where these instances are. By “somewhere in my app”, do you mean main.lua? Then the second block, where is that? Also in main.lua? If so, you would be overwriting the first require of Google IAP with a new require of Apple, which of course would cause issues if you’re trying to implement Google IAP. Please check your code carefully and edit the post so we can understand it more clearly.

Thanks,

Brent

Hi Brent,

Thanks for you reply. I edited my message with the full details as requested.

I also removed the extra store include you mentioned but still not luck.

Hi @jongar,

I don’t understand. You said that the callback is being triggered when you buy the test product. But then you say that it is not triggered. What is the actual behavior, and when?

Thanks,

Brent

Hi Brent,

It’s being triggered when I cancel the purchase request (I click outside of the purchase box (this is printed: print( “User cancelled transaction” )) but when I complete the purchase and I am told the payment was successful it doesn’t work (print( “Transaction succuessful!” ) is NOT printed.)

Thanks.

What is “license.create( )”? I notice that’s done in the “purchased” phase but not in the “cancelled” phase, and you’re seeing different results in these two phases.

Brent

Hi Brent,

This is really odd because I got passed the error by removing local from: store = require( “store” ):

store = require( “store” )

if store.target == “google” then

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

end

if store.target == “amazon” then

    store = require( “plugin.amazon.iap” )

end

Thanks.

At this point are you working?  Your last post indicates that you’ve solved your issue?

Rob

Hi Rob,

It’s working when I remove “local”.

Sorry, edited my post to say “last” not “lost”.  In your original post you didn’t include your store require code, i.e.

store = require( “store” )

if store.target == “google” then

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

end

if store.target == “amazon” then

    store = require( “plugin.amazon.iap” )

end

Can you please post what is not working?

Thanks Rob. It works after removing local from store = require( “store” ) as I mentioned above.

I would still like to see your code.

Rob

Hi Rob,

I edited the code above (just added the missing bit in scripts/global.lua).

Regards,

Jongar

Hi @jongar,

Please clarify your code a little better so we can assist you. You show 3 instances of require()-ing the store, but we don’t know where these instances are. By “somewhere in my app”, do you mean main.lua? Then the second block, where is that? Also in main.lua? If so, you would be overwriting the first require of Google IAP with a new require of Apple, which of course would cause issues if you’re trying to implement Google IAP. Please check your code carefully and edit the post so we can understand it more clearly.

Thanks,

Brent

Hi Brent,

Thanks for you reply. I edited my message with the full details as requested.

I also removed the extra store include you mentioned but still not luck.

Hi @jongar,

I don’t understand. You said that the callback is being triggered when you buy the test product. But then you say that it is not triggered. What is the actual behavior, and when?

Thanks,

Brent

Hi Brent,

It’s being triggered when I cancel the purchase request (I click outside of the purchase box (this is printed: print( “User cancelled transaction” )) but when I complete the purchase and I am told the payment was successful it doesn’t work (print( “Transaction succuessful!” ) is NOT printed.)

Thanks.

What is “license.create( )”? I notice that’s done in the “purchased” phase but not in the “cancelled” phase, and you’re seeing different results in these two phases.

Brent

Hi Brent,

This is really odd because I got passed the error by removing local from: store = require( “store” ):

store = require( “store” )

if store.target == “google” then

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

end

if store.target == “amazon” then

    store = require( “plugin.amazon.iap” )

end

Thanks.

At this point are you working?  Your last post indicates that you’ve solved your issue?

Rob