Type Function Return value none Revision Release 2024.3703 Keywords Google, IAP, in-app purchases, init See also store.isActive store.*
This call is required and must be made before making other Google IAP calls. This prepares the Google IAP library and allows you to detect storeTransaction events to the listener defined as listener
.
This method also dispatches an init event to the specified listener (the same listenter used for storeTransaction events). At this point, store.isActive will be true
unless an error occurred.
To reiterate, you must wait until the init event is dispatched before attempting to load products, restore
Note that initialization is done ansynchronously because it may require network calls which take a variable amount of time depending on server load and network latencies.
store.init( listener )
Listener. The listener that will handle storeTransaction events. Note that this listener will also handle the init event as outlined above.
local store = require( "plugin.google.iap.v3" ) local json = require( "json" ) local function transactionListener( event ) -- Google IAP initialization event if ( event.name == "init" ) then if not ( event.transaction.isError ) then -- Perform steps to enable IAP, load products, etc. else -- Unsuccessful initialization; output error details print( event.transaction.errorType ) print( event.transaction.errorString ) end -- Store transaction event elseif ( event.name == "storeTransaction" ) then if not ( event.transaction.state == "failed" ) then -- Successful transaction print( json.prettify( event ) ) print( "event.transaction: " .. json.prettify( event.transaction ) ) else -- Unsuccessful transaction; output error details print( event.transaction.errorType ) print( event.transaction.errorString ) end end end -- Initialize Google IAP store.init( transactionListener )