{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["json-schema"]},"type":"markdown"},"seo":{"title":"Initialise SDK","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":["openapi"],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"initialise-sdk","__idx":0},"children":["Initialise SDK"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"taptopaysdkinitactivity-oninitresult","__idx":1},"children":["tapToPaySdk.init(activity, onInitResult)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["onCreate()"]}," method of your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Activity"]}," class, invoke ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["tapToPaySdk.init()"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["tapToPaySdk.registerTransactionResultHandler()"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"kotlin","header":{"controls":{"copy":{}}},"source":"fun init(\n    activity: ComponentActivity,\n    onInitResult: (InitResult) -> Unit\n)\n","lang":"kotlin"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"parameters","__idx":2},"children":["Parameters"]},{"$$mdtype":"Tag","name":"JsonSchema","attributes":{"schema":{"type":"object","properties":{"activity":{"type":"ComponentActivity","description":"The Android Activity"},"onInitResult":{"type":"(InitResult) -> Unit","description":"The callback for the initialisation result"}},"required":["activity","onInitResult"]},"options":{"schemaExpansionLevel":1},"schemaResolved":{"openapi":"3.1.0","components":{"schemas":{"__root":{"type":"object","properties":{"activity":{"type":"ComponentActivity","description":"The Android Activity"},"onInitResult":{"type":"(InitResult) -> Unit","description":"The callback for the initialisation result"}},"required":["activity","onInitResult"]}}}},"schemaResolvedErrors":[]},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"initresult","__idx":3},"children":["InitResult"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"kotlin","header":{"controls":{"copy":{}}},"source":"data class InitResult(\n    val status: InitStatus,\n    val errorMessage: String? = null\n)\n","lang":"kotlin"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"parameters-1","__idx":4},"children":["Parameters"]},{"$$mdtype":"Tag","name":"JsonSchema","attributes":{"schema":{"type":"object","properties":{"status":{"type":"InitStatus","description":"The initialisation status.","enum":["INIT_SUCCESS","INIT_CONNECTION_ERROR","INIT_AUTH_ERROR","INIT_NFC_UNAVAILABLE_ERROR","INIT_REQUEST_PERMISSIONS_ERROR","INIT_ATTESTATION_FAILED_ERROR","INIT_ATTESTATION_ERROR","INIT_SDK_ERROR","INIT_ERROR"]},"errorMessage":{"type":"String","description":"The error message if returned."}},"required":["status"]},"options":{"schemaExpansionLevel":1},"schemaResolved":{"openapi":"3.1.0","components":{"schemas":{"__root":{"type":"object","properties":{"status":{"type":"InitStatus","description":"The initialisation status.","enum":["INIT_SUCCESS","INIT_CONNECTION_ERROR","INIT_AUTH_ERROR","INIT_NFC_UNAVAILABLE_ERROR","INIT_REQUEST_PERMISSIONS_ERROR","INIT_ATTESTATION_FAILED_ERROR","INIT_ATTESTATION_ERROR","INIT_SDK_ERROR","INIT_ERROR"]},"errorMessage":{"type":"String","description":"The error message if returned."}},"required":["status"]}}}},"schemaResolvedErrors":[]},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"taptopaysdkregistertransactionresulthandleractivity-ontransactionresult","__idx":5},"children":["tapToPaySdk.registerTransactionResultHandler(activity, onTransactionResult)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Register the transaction result handler to be notified of the transaction results."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"kotlin","header":{"controls":{"copy":{}}},"source":"fun registerTransactionResultHandler(\n       activity: ComponentActivity,\n       onTransactionResult: (TransactionResult) -> Unit,\n   )\n","lang":"kotlin"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"parameters-2","__idx":6},"children":["Parameters"]},{"$$mdtype":"Tag","name":"JsonSchema","attributes":{"schema":{"type":"object","properties":{"activity":{"type":"ComponentActivity","description":"The Android Activity"},"onTransactionResult":{"type":"(TransactionResult) -> Unit","description":"The callback for the transaction"}},"required":["activity","onTransactionResult"]},"options":{"schemaExpansionLevel":1},"schemaResolved":{"openapi":"3.1.0","components":{"schemas":{"__root":{"type":"object","properties":{"activity":{"type":"ComponentActivity","description":"The Android Activity"},"onTransactionResult":{"type":"(TransactionResult) -> Unit","description":"The callback for the transaction"}},"required":["activity","onTransactionResult"]}}}},"schemaResolvedErrors":[]},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"see","__idx":7},"children":["See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/in-person-payments/tap-to-pay/android/sdk/transaction-result"},"children":["Transaction Result"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example-implementation","__idx":8},"children":["Example Implementation"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"kotlin","header":{"controls":{"copy":{}}},"source":"...\nclass MainActivity : ComponentActivity() {\n    private val viewModel: SdkDemoViewModel by viewModels { SdkDemoViewModel.Factory }\n\n    private val tapToPaySdk: TapToPaySdk\n        get() = TapToPaySdk.instance\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContent {\n            TapToPaySdkDemoApp(viewModel)\n        }\n\n        // register a handler for transaction results\n        tapToPaySdk.registerTransactionResultHandler(this) { transactionResult ->\n            viewModel.onTransactionResult(transactionResult)\n        }\n\n        // initialise the Tyro Embedded Payments SDK\n        // this could take some time, so show a progress spinner\n        viewModel.showLoadingScreen()\n        tapToPaySdk.init(this) { initResult ->\n            viewModel.onInitResult(initResult)\n        }\n    }\n\n...\n\nclass SdkDemoViewModel(private val tapToPaySdk: TapToPaySdk) : ViewModel() {\n...\n    fun onInitResult(initResult: InitResult) {\n        when (initResult.status) {\n            InitStatus.INIT_SUCCESS ->\n                _state.update { it.copy(screen = HOME) }\n            else ->\n                _state.update {\n                    it.copy(\n                        screen = INIT_ERROR,\n                        errorMessage = initResult.errorMessage(),\n                    )\n                }\n        }\n    }\n...\n    fun onTransactionResult(result: TransactionResult) {\n        when (result.status) {\n            TXN_CANCELLED ->\n                _state.update { it.copy(screen = AMOUNT) }\n            TXN_SUCCESS ->\n                _state.update { it.copy(screen = SUCCESS) }\n            else ->\n                _state.update {\n                    it.copy(\n                        screen = TRANSACTION_ERROR,\n                        errorMessage = result.errorMessage(),\n                    )\n                }\n        }\n    }\n\n...\n}\n\n","lang":"kotlin"},"children":[]}]},"headings":[{"value":"Initialise SDK","id":"initialise-sdk","depth":1},{"value":"tapToPaySdk.init(activity, onInitResult)","id":"taptopaysdkinitactivity-oninitresult","depth":2},{"value":"Parameters","id":"parameters","depth":3},{"value":"InitResult","id":"initresult","depth":3},{"value":"Parameters","id":"parameters-1","depth":3},{"value":"tapToPaySdk.registerTransactionResultHandler(activity, onTransactionResult)","id":"taptopaysdkregistertransactionresulthandleractivity-ontransactionresult","depth":2},{"value":"Parameters","id":"parameters-2","depth":3},{"value":"See","id":"see","depth":4},{"value":"Example Implementation","id":"example-implementation","depth":2}],"frontmatter":{"title":"Initialise SDK","seo":{"title":"Initialise SDK"}},"lastModified":"2026-09-02T01:02:13.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/in-person-payments/tap-to-pay/android/sdk/init-sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}