class SampleFragment : Fragment() {
private val viewModel: SampleViewModel by viewModels()
private val linkAccount = registerForActivityResult(AccountSessionContract()) {
is SessionResult.Success -> {
// get linkingType by calling it.value.linkingType
// get account token by calling it.value.authorizationCode
is SessionResult.Canceled -> {
// do something on user cancellation
is SessionResult.Failure -> {
// do something on failure
override fun onCreateView(
inflater: LayoutInflater,
savedInstanceState: Bundle?
return FragmentSampleBinding.inflate(inflater).apply {
linkAccountButton.setDebounceClickListener {
// fetch account linking state from kevin. API
viewModel.initializeAccountLinking()
private fun observeChanges() {
// observe returned state here
lifecycleScope.launchWhenStarted {
viewModel.state.onEach { state ->
openAccountLinkingSession(state)
private fun openAccountLinkingSession(state: String) {
val config = AccountSessionConfiguration.Builder(state)
.setPreselectedCountry(KevinCountry.LITHUANIA)
linkAccount.launch(config)