Skip to content

Commit

Permalink
chore: do not hide progress view when challenge is required
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxzero committed Oct 2, 2023
1 parent 04a3e40 commit 1006ef9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal class AuthorizingPaymentViewModel(
val error: LiveData<OmiseException> = _error

private val coroutineExceptionHandler = CoroutineExceptionHandler { _, e ->
_isLoading.postValue(false)
threeDS2Service.transaction.close()
if (e is OmiseException) {
_error.postValue(e)
Expand Down Expand Up @@ -122,16 +123,23 @@ internal class AuthorizingPaymentViewModel(
try {
_isLoading.postValue(true)
val authentication = client.send(request)

// Reccomended by Netcetera's 3DS SDK.
// If the challenge flow is required
// - Do not close the transaction
// - Do not hide the progress view
// See https://3dss.netcetera.com/3dssdk/doc/2.7.0/android-sdk-api#processing-screen
if (authentication.status != Authentication.AuthenticationStatus.CHALLENGE) {
_isLoading.postValue(false)
transaction.close()
}

_authenticationResponse.postValue(authentication)
_authenticationStatus.postValue(authentication.status)
} catch (e: Exception) {
_isLoading.postValue(false)
transaction.close()
_error.postValue(OmiseException("Authentication failed", e))
} finally {
_isLoading.postValue(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -116,6 +117,7 @@ class AuthorizingPaymentViewModelTest {

verify(client).send(any<Request<Authentication>>())
verify(transaction, never()).close()
assertTrue(viewModel.isLoading.value!!)
assertEquals(AuthenticationStatus.CHALLENGE, viewModel.authenticationStatus.value)
}

Expand Down

0 comments on commit 1006ef9

Please sign in to comment.