diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index ebbfa878..ca402ff3 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -327,7 +327,12 @@ internal class NativeAlternativePaymentInteractor( val fields = parameters.toFields() val updatedStateValue = stateValue.copy( uuid = UUID.randomUUID().toString(), - redirect = redirect, + redirect = redirect?.let { + Redirect( + data = it, + isFallback = stateValue.redirect != null + ) + }, elements = elements, fields = fields, focusedFieldId = fields.firstFocusableFieldId() @@ -453,17 +458,19 @@ internal class NativeAlternativePaymentInteractor( private fun handleAutoRedirect() { _state.whenNextStep { stateValue -> - if (stateValue.redirect != null && shouldAutoRedirect()) { + val redirect = stateValue.redirect + if (redirect != null && redirect.shouldAutoRedirect()) { redirect( stateValue = stateValue, - redirect = stateValue.redirect + redirect = redirect.data ) } } } - private fun shouldAutoRedirect(): Boolean = - configuration.redirect?.enableHeadlessMode == true || + private fun Redirect.shouldAutoRedirect(): Boolean = + isFallback || + configuration.redirect?.enableHeadlessMode == true || configuration.redirect?.redirectButton == null //endregion @@ -554,12 +561,12 @@ internal class NativeAlternativePaymentInteractor( return@subscribe } _state.whenNextStep { stateValue -> - if (stateValue.redirect?.type == RedirectType.DEEP_LINK) { + if (stateValue.redirect?.data?.type == RedirectType.DEEP_LINK) { handleDeepLink(event.uri) } } _state.whenPending { stateValue -> - if (stateValue.redirect?.type == RedirectType.DEEP_LINK) { + if (stateValue.redirect?.data?.type == RedirectType.DEEP_LINK) { handleDeepLink(event.uri) } } @@ -698,7 +705,7 @@ internal class NativeAlternativePaymentInteractor( if (stateValue.redirect != null) { redirect( stateValue = stateValue, - redirect = stateValue.redirect + redirect = stateValue.redirect.data ) return@whenNextStep } @@ -793,7 +800,7 @@ internal class NativeAlternativePaymentInteractor( private fun handleWebRedirect(result: ProcessOutResult) { result.onSuccess { _state.whenNextStep { stateValue -> - val redirectConfirmation = if (stateValue.redirect?.confirmationRequired == true) + val redirectConfirmation = if (stateValue.redirect?.data?.confirmationRequired == true) PONativeAlternativePaymentRedirectConfirmation(success = true) else null continuePayment(redirectConfirmation) } @@ -819,7 +826,7 @@ internal class NativeAlternativePaymentInteractor( url = redirectUrl, packageNames = deepLinkConfiguration?.packageNames ) - val redirectConfirmation = if (stateValue.redirect?.confirmationRequired == true) + val redirectConfirmation = if (stateValue.redirect?.data?.confirmationRequired == true) PONativeAlternativePaymentRedirectConfirmation(success = didOpenUrl) else null continuePayment(redirectConfirmation) } diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractorState.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractorState.kt index 1e147e46..86514c14 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractorState.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractorState.kt @@ -49,7 +49,7 @@ internal sealed interface NativeAlternativePaymentInteractorState { val uuid: String, val paymentMethod: PONativeAlternativePaymentMethodDetails, val invoice: Invoice?, - val redirect: PONativeAlternativePaymentRedirect?, + val redirect: Redirect?, val elements: List, val fields: List, val focusedFieldId: String?, @@ -63,7 +63,7 @@ internal sealed interface NativeAlternativePaymentInteractorState { val uuid: String, val paymentMethod: PONativeAlternativePaymentMethodDetails, val invoice: Invoice?, - val redirect: PONativeAlternativePaymentRedirect?, + val redirect: Redirect?, val stepper: Stepper?, val elements: List?, val primaryActionId: String?, @@ -75,6 +75,11 @@ internal sealed interface NativeAlternativePaymentInteractorState { val activeStepIndex: Int ) + data class Redirect( + val data: PONativeAlternativePaymentRedirect, + val isFallback: Boolean + ) + sealed interface Element { data class Form( diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt index 7526b6e5..71e900ff 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt @@ -571,7 +571,7 @@ internal class NativeAlternativePaymentViewModel private constructor( return if (redirect != null) { configuration.redirect?.redirectButton?.let { submitAction.copy( - text = it.text ?: redirect.hint, + text = it.text ?: redirect.data.hint, icon = it.icon ) }