Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -698,7 +705,7 @@ internal class NativeAlternativePaymentInteractor(
if (stateValue.redirect != null) {
redirect(
stateValue = stateValue,
redirect = stateValue.redirect
redirect = stateValue.redirect.data
)
return@whenNextStep
}
Expand Down Expand Up @@ -793,7 +800,7 @@ internal class NativeAlternativePaymentInteractor(
private fun handleWebRedirect(result: ProcessOutResult<POAlternativePaymentMethodResponse>) {
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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element>,
val fields: List<Field>,
val focusedFieldId: String?,
Expand All @@ -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<Element>?,
val primaryActionId: String?,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Loading