init

suspend fun init(context: Context, posTerminalId: String, forageConfig: ForageConfig, ksnDir: File = context.filesDir, capabilities: TerminalCapabilities = TerminalCapabilities.TapAndInsert): ForageTerminalSDK

A method that initializes the ForageTerminalSDK.

You must call init ahead of calling any other methods on a ForageTerminalSDK instance.

Forage may perform some long running initialization operations in certain circumstances. The operations typically last less than 10 seconds and only occur infrequently.

⚠️The ForageTerminalSDK.init method is only available in the private distribution of the Forage Terminal SDK.

// Example: Initialize the Forage Terminal SDK
try {
val forageTerminalSdk = ForageTerminalSDK.init(
context = androidContext,
posTerminalId = "<id-that-uniquely-identifies-the-pos-terminal>",
forageConfig = ForageConfig(
merchantId = "123ab45c67",
sessionToken = "sandbox_ey123..."
)
)

// Use the forageTerminalSdk to call other methods
// (e.g. checkBalance, etc.)
} catch (e: Exception) {
// handle initialization error
}

Parameters

context

Required. The Android application context.

posTerminalId

Required. A string that uniquely identifies the POS Terminal used for a transaction. The max length of the string is 255 characters.

ForageConfig

Required. A ForageConfig instance that specifies a merchantId and sessionToken.

ksnDir

Optional. Specifies the directory where the SDK initializes and stores state for DUKPT (Derived Unique Key Per Transaction) key generation. By default, this is set to the app's filesDir. Choose a directory that the host application won't frequently modify or delete to prevent unnecessary reinitialization of the SDK's state.

capabilities

Optional. Defines the terminal's capabilities for processing transactions, such as supporting card swiping, tapping, or inserting. This information is used to report terminal features for compliance purposes. Most applications can use the default value without modification.

Throws

If the initialization fails.