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 |
| 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 |
| themeMode | TyroThemeMode Sets the theme mode for Tyro UI. Defaults to |
| hapticFeedbackEnabled | Boolean Enables the haptic feedback for Tyro Embedded Payment SDK. Defaults to |
Example Implementation
Create an instance of the TapToPaySdk in your Application class.
// 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, TyroThemeMode.SYSTEM, hapticFeedbackEnabled = true)).apply {
setPosInfo(
PosInfo(
posName = "Demo",
posVendor = "Tyro Payments",
posVersion = "1.0",
siteReference = "Sydney",
),
)
}
}
}