store.init()

Type Function
Return value none
Revision Release 2026.3728
Keywords IAP, Samsung IAP, Samsung In App Purchase, init
See also store.loadProducts()
store.purchase()
store.restore()
store.*

Overview

Initialize the Samsung IAP plugin and set store operation mode. This step is mandatory before any other methods can be used.

The listener passed to this function receives the init event and all storeTransaction events (purchases, restored purchases, consume and acknowledge results, subscription plan changes).

Syntax

store.init( listener [,operationMode] )
listener (required)

Listener. The listener that will handle init and storeTransaction events.

operationMode (optional)

String. can be set to “testMode”, “testFailureMode”, or “production”(default).

“testMode”: financial transactions do not occur (licensed testers are not billed for item purchases), and successful results are always returned.

“testFailureMode” : meant to be a negative testing to ensure that your app can handle errors

“production” : requests are processed as specified, financial transactions do occur for successful requests, and actual results are returned

Example

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

local function transactionListener( event )

    -- Samsung 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

        local transaction = event.transaction

        if ( transaction.state == "purchased" or transaction.state == "restoreCompleted" ) then
            print( "event.transaction: " .. json.prettify( transaction ) )

            -- Grant the item to the user here, then tell Samsung IAP that it was delivered
            if ( transaction.isConsumable ) then
                store.consumePurchase( transaction.purchaseId )
            elseif ( transaction.acknowledgedStatus ~= "acknowledged" ) then
                store.acknowledgePurchase( transaction.purchaseId )
            end

        elseif ( transaction.state == "failed" ) then  -- Unsuccessful transaction; output error details
            print( transaction.errorType )
            print( transaction.errorString )
        end
    end
end

-- Initialize Samsung IAP with test
store.init( transactionListener, "testMode" )