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.