store.init()

Type Function
Return value none
Revision Release 2024.3703
Keywords Apple, IAP, in-app purchases, init
See also store.isActive
store.*

Overview

This call is required and must be executed before making other Apple IAP calls. This prepares the Apple IAP library and, upon successful initialization, sets store.isActive to true.

This also allows you to detect storeTransaction events to the listener defined as listener.

Syntax

store.init( listener )
listener (required)

Listener. The listener that will handle storeTransaction events.

For compatibility with Google IAP plugin, store.init() will call listener with event "init".

Example

local store = require( "plugin.apple.iap" )
local json = require( "json" )

-- Transaction listener function
local function transactionListener( event )

    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

    -- Tell the store that the transaction is finished
    store.finishTransaction( event.transaction )
end

-- Initialize Apple IAP
store.init( transactionListener )