Skip to content

Commit c1b89c1

Browse files
feat(ad-hoc): (nAPM) Support manual web fallback redirect (#387)
1 parent 3718fb6 commit c1b89c1

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.processout.sdk.api.model.event.PODeepLinkReceivedEvent
2424
import com.processout.sdk.api.model.request.napm.v2.*
2525
import com.processout.sdk.api.model.request.napm.v2.PONativeAlternativePaymentSubmitData.Parameter.Companion.phoneNumber
2626
import com.processout.sdk.api.model.request.napm.v2.PONativeAlternativePaymentSubmitData.Parameter.Companion.string
27-
import com.processout.sdk.api.model.response.POAlternativePaymentMethodResponse
2827
import com.processout.sdk.api.model.response.POImageResource
2928
import com.processout.sdk.api.model.response.napm.v2.*
3029
import com.processout.sdk.api.model.response.napm.v2.PONativeAlternativePaymentAuthorizationResponse.Invoice
@@ -560,15 +559,10 @@ internal class NativeAlternativePaymentInteractor(
560559
if (_completion.value !is Awaiting) {
561560
return@subscribe
562561
}
563-
_state.whenNextStep { stateValue ->
564-
if (stateValue.redirect?.data?.type == RedirectType.DEEP_LINK) {
565-
handleDeepLink(event.uri)
566-
}
567-
}
568-
_state.whenPending { stateValue ->
569-
if (stateValue.redirect?.data?.type == RedirectType.DEEP_LINK) {
570-
handleDeepLink(event.uri)
571-
}
562+
when (_state.value) {
563+
is NextStep,
564+
is Pending -> handleDeepLink(event.uri)
565+
else -> {}
572566
}
573567
}
574568
}
@@ -638,7 +632,7 @@ internal class NativeAlternativePaymentInteractor(
638632
}
639633
}
640634
is PermissionRequestResult -> handlePermission(event)
641-
is WebRedirectResult -> handleWebRedirect(event.result)
635+
is WebRedirectResult -> event.result.onFailure { handleWebRedirect(failure = it) }
642636
is Dismiss -> {
643637
POLogger.info("Dismissed: %s", event.failure)
644638
dispatch(DidFail(event.failure, paymentState))
@@ -797,15 +791,11 @@ internal class NativeAlternativePaymentInteractor(
797791
}
798792
}
799793

800-
private fun handleWebRedirect(result: ProcessOutResult<POAlternativePaymentMethodResponse>) {
801-
result.onSuccess {
802-
_state.whenNextStep { stateValue ->
803-
val redirectConfirmation = if (stateValue.redirect?.data?.confirmationRequired == true)
804-
PONativeAlternativePaymentRedirectConfirmation(success = true) else null
805-
continuePayment(redirectConfirmation)
806-
}
807-
}.onFailure { failure ->
808-
_completion.update { Failure(failure) }
794+
private fun handleWebRedirect(failure: ProcessOutResult.Failure) {
795+
when (failure.code) {
796+
Cancelled,
797+
is Timeout -> _completion.update { Failure(failure) }
798+
else -> {}
809799
}
810800
}
811801

0 commit comments

Comments
 (0)