diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt index 34131d59..ebc36e02 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt @@ -201,11 +201,22 @@ internal class DynamicCheckoutInteractor( paymentMethods = mappedPaymentMethods ) } - restoreSelectedPaymentMethod() + handleSelectedPaymentMethod() handlePendingSubmit() } - private fun restoreSelectedPaymentMethod() { + private fun handleSelectedPaymentMethod() { + if (configuration.preselectSinglePaymentMethod) { + _state.value.paymentMethods + .partition { it.isExpress() } + .let { pair -> + val expressPaymentMethods = pair.first + val regularPaymentMethods = pair.second + if (expressPaymentMethods.isEmpty() && regularPaymentMethods.size == 1) { + _state.update { it.copy(selectedPaymentMethod = regularPaymentMethods.firstOrNull()) } + } + } + } _state.value.selectedPaymentMethod?.id?.let { id -> paymentMethod(id)?.let { start(it) } .orElse { diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/PODynamicCheckoutConfiguration.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/PODynamicCheckoutConfiguration.kt index c2f9810d..13560185 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/PODynamicCheckoutConfiguration.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/PODynamicCheckoutConfiguration.kt @@ -20,6 +20,7 @@ data class PODynamicCheckoutConfiguration( val card: CardConfiguration = CardConfiguration(), val googlePay: GooglePayConfiguration = GooglePayConfiguration(), val alternativePayment: AlternativePaymentConfiguration = AlternativePaymentConfiguration(), + val preselectSinglePaymentMethod: Boolean = true, val submitButtonText: String? = null, val cancelButton: CancelButton? = CancelButton(), val paymentSuccess: PaymentSuccess? = PaymentSuccess(),