Create Instance

TapToPaySdk.createInstance(tyroEnv, appContext, options)

In your Application class create an instance of the TapToPaySdk by invoking static method TapToPaySdk.createInstance(tyroEnv, appContext, options) in onCreate().

Parameters

tyroEnv
required
TyroEnv

The TyroEnv requires the PosInfo and ConnectionProvider in the constructor. There are 3 TyroEnv subclasses to use based on the desired environment: TyroEnvStub, TyroEnvDev, and TyroEnvProd.

applicationContext
required
Context

The applicationContext from the Application. This function must be called inside onCreate() otherwise the context is null.

options
TyroOptions

Options to configure the SDK such as screen orientation.

TyroEnv

See TyroEnv for more info.

TyroOptions

Optional parameters to provide to the SDK.

screenOrientation
TyroScreenOrientation

Sets the screen orientation for Tyro UI. Landscape options are not supported for phones and will throw an error if attempted. Defaults to PORTRAIT.

Enum: "PORTRAIT" "REVERSE_PORTRAIT" "SENSOR" "LANDSCAPE" "REVERSE_LANDSCAPE"

Example Implementation

Create an instance of the TapToPaySdk in your Application class.

Copy
Copied
// Kotlin Sample Code
import android.app.Application
import com.tyro.taptopay.sdk.api.TapToPaySdk
import com.tyro.taptopay.sdk.api.TapToPaySdk.Companion.createInstance
import com.tyro.taptopay.sdk.api.TyroEnv
import com.tyro.taptopay.sdk.api.TyroEnvDev
import com.tyro.taptopay.sdk.api.TyroEnvProd
import com.tyro.taptopay.sdk.api.TyroEnvStub
import com.tyro.taptopay.sdk.api.TyroOptions
import com.tyro.taptopay.sdk.api.TyroScreenOrientation
import com.tyro.taptopay.sdk.api.data.PosInfo

class SdkDemoApplication : Application() {
    lateinit var tapToPaySDK: TapToPaySdk

    override fun onCreate() {
        super.onCreate()
        tapToPaySDK = createTapToPaySdk()
    }

    @Suppress("KotlinConstantConditions")
    private fun createTapToPaySdk(): TapToPaySdk {
        val tyroEnv: TyroEnv =
            when (BuildConfig.FLAVOR) {
                "stub" -> TyroEnvStub()
                "dev" ->
                    TyroEnvDev(
                        connectionProvider = SdkDemoConnectionProvider(),
                    )
                else ->
                    TyroEnvProd(
                        connectionProvider = SdkDemoConnectionProvider(),
                    )
            }
        return createInstance(tyroEnv, applicationContext, TyroOptions(TyroScreenOrientation.PORTRAIT)).apply {
            setPosInfo(
                PosInfo(
                    posName = "Demo",
                    posVendor = "Tyro Payments",
                    posVersion = "1.0",
                    siteReference = "Sydney",
                ),
            )
        }
    }
}
Copyright © Tyro Payments 2019-2024. All right reserved.