Skip to content

Commit

Permalink
feat(POM-440): (DC) Optionally pre-select single regular payment meth…
Browse files Browse the repository at this point in the history
…od (#248)
  • Loading branch information
vitalii-vanziak-cko authored Dec 10, 2024
1 parent a3d9ebf commit 9d11cc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 9d11cc8

Please # to comment.