diff --git a/paymentsheet/detekt-baseline.xml b/paymentsheet/detekt-baseline.xml
index 30ee2a366ad..f9ad2777d62 100644
--- a/paymentsheet/detekt-baseline.xml
+++ b/paymentsheet/detekt-baseline.xml
@@ -31,7 +31,7 @@
LongMethod:EditPaymentMethod.kt$@Composable internal fun EditPaymentMethodUi( viewState: EditPaymentMethodViewState, viewActionHandler: (action: EditPaymentMethodViewAction) -> Unit, modifier: Modifier = Modifier )
LongMethod:FormViewModelTest.kt$FormViewModelTest$@Test fun `Verify params are set when element address fields are complete`()
LongMethod:FormViewModelTest.kt$FormViewModelTest$@Test fun `Verify params are set when required address fields are complete`()
- LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, ): PaymentMethodVerticalLayoutInteractor
+ LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, bankFormInteractor: BankFormInteractor, ): PaymentMethodVerticalLayoutInteractor
LongMethod:PaymentOptionFactory.kt$PaymentOptionFactory$fun create(selection: PaymentSelection): PaymentOption
LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance()
LongMethod:PaymentSheetScreen.kt$@Composable private fun PaymentSheetContent( viewModel: BaseSheetViewModel, headerText: ResolvableString?, walletsState: WalletsState?, walletsProcessingState: WalletsProcessingState?, error: ResolvableString?, currentScreen: PaymentSheetScreen, mandateText: MandateText?, modifier: Modifier )
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormArguments.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormArguments.kt
index dfa9a7fb52f..89a14c8ab26 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormArguments.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormArguments.kt
@@ -12,6 +12,7 @@ import com.stripe.android.paymentsheet.addresselement.AddressDetails
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.state.PaymentElementLoader
import com.stripe.android.paymentsheet.ui.PrimaryButton
+import com.stripe.android.paymentsheet.verticalmode.BankFormInteractor
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import kotlinx.coroutines.flow.update
@@ -61,6 +62,7 @@ internal class USBankAccountFormArguments(
paymentMethodMetadata: PaymentMethodMetadata,
hostedSurface: String,
selectedPaymentMethodCode: String,
+ bankFormInteractor: BankFormInteractor,
): USBankAccountFormArguments {
val isSaveForFutureUseValueChangeable = isSaveForFutureUseValueChangeable(
code = selectedPaymentMethodCode,
@@ -91,7 +93,7 @@ internal class USBankAccountFormArguments(
shippingDetails = viewModel.config.shippingDetails,
draftPaymentSelection = viewModel.newPaymentSelection?.paymentSelection,
onMandateTextChanged = viewModel.mandateHandler::updateMandateText,
- onLinkedBankAccountChanged = viewModel::handleLinkedBankAccountChanged,
+ onLinkedBankAccountChanged = bankFormInteractor::handleLinkedBankAccountChanged,
onUpdatePrimaryButtonUIState = { viewModel.customPrimaryButtonUiState.update(it) },
onUpdatePrimaryButtonState = viewModel::updatePrimaryButtonState,
onError = viewModel::onError
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethodInteractor.kt
index 73326c222c3..daa1fc218b5 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethodInteractor.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethodInteractor.kt
@@ -10,6 +10,7 @@ import com.stripe.android.paymentsheet.forms.FormFieldValues
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.paymentdatacollection.FormArguments
import com.stripe.android.paymentsheet.paymentdatacollection.ach.USBankAccountFormArguments
+import com.stripe.android.paymentsheet.verticalmode.BankFormInteractor
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import com.stripe.android.uicore.elements.FormElement
import kotlinx.coroutines.CoroutineScope
@@ -78,6 +79,8 @@ internal class DefaultAddPaymentMethodInteractor(
linkInlineHandler = linkInlineHandler,
paymentMethodMetadata = paymentMethodMetadata
)
+ val bankFormInteractor = BankFormInteractor.create(viewModel)
+
return DefaultAddPaymentMethodInteractor(
initiallySelectedPaymentMethodType = viewModel.initiallySelectedPaymentMethodType,
selection = viewModel.selection,
@@ -95,6 +98,7 @@ internal class DefaultAddPaymentMethodInteractor(
paymentMethodMetadata = paymentMethodMetadata,
hostedSurface = CollectBankAccountLauncher.HOSTED_SURFACE_PAYMENT_ELEMENT,
selectedPaymentMethodCode = it,
+ bankFormInteractor = bankFormInteractor,
)
},
coroutineScope = coroutineScope,
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/BankFormInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/BankFormInteractor.kt
new file mode 100644
index 00000000000..19a07f48434
--- /dev/null
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/BankFormInteractor.kt
@@ -0,0 +1,22 @@
+package com.stripe.android.paymentsheet.verticalmode
+
+import com.stripe.android.paymentsheet.model.PaymentSelection
+import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
+
+internal class BankFormInteractor private constructor(
+ private val updateSelection: (PaymentSelection.New.USBankAccount?) -> Unit,
+) {
+
+ fun handleLinkedBankAccountChanged(selection: PaymentSelection.New.USBankAccount?) {
+ updateSelection(selection)
+ }
+
+ companion object {
+
+ fun create(viewModel: BaseSheetViewModel): BankFormInteractor {
+ return BankFormInteractor(
+ updateSelection = viewModel::updateSelection,
+ )
+ }
+ }
+}
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/PaymentMethodVerticalLayoutInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/PaymentMethodVerticalLayoutInteractor.kt
index 5114267e88b..64bf87001e5 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/PaymentMethodVerticalLayoutInteractor.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/PaymentMethodVerticalLayoutInteractor.kt
@@ -98,6 +98,7 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
viewModel: BaseSheetViewModel,
paymentMethodMetadata: PaymentMethodMetadata,
customerStateHolder: CustomerStateHolder,
+ bankFormInteractor: BankFormInteractor,
): PaymentMethodVerticalLayoutInteractor {
val linkInlineHandler = LinkInlineHandler.create(viewModel, viewModel.viewModelScope)
val formHelper = FormHelper.create(viewModel, linkInlineHandler, paymentMethodMetadata)
@@ -133,6 +134,7 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
+ bankFormInteractor = bankFormInteractor,
)
PaymentSheetScreen.VerticalModeForm(interactor = interactor)
},
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeFormInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeFormInteractor.kt
index c7982f42d54..8b80e545bf2 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeFormInteractor.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeFormInteractor.kt
@@ -93,6 +93,7 @@ internal class DefaultVerticalModeFormInteractor(
viewModel: BaseSheetViewModel,
paymentMethodMetadata: PaymentMethodMetadata,
customerStateHolder: CustomerStateHolder,
+ bankFormInteractor: BankFormInteractor,
): VerticalModeFormInteractor {
val coroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
val formHelper = FormHelper.create(
@@ -109,7 +110,8 @@ internal class DefaultVerticalModeFormInteractor(
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
hostedSurface = CollectBankAccountLauncher.HOSTED_SURFACE_PAYMENT_ELEMENT,
- selectedPaymentMethodCode = selectedPaymentMethodCode
+ selectedPaymentMethodCode = selectedPaymentMethodCode,
+ bankFormInteractor = bankFormInteractor,
),
headerInformation = paymentMethodMetadata.formHeaderInformationForCode(
selectedPaymentMethodCode,
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeInitialScreenFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeInitialScreenFactory.kt
index deea858fca0..d8df2736857 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeInitialScreenFactory.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/verticalmode/VerticalModeInitialScreenFactory.kt
@@ -16,6 +16,7 @@ internal object VerticalModeInitialScreenFactory {
customerStateHolder: CustomerStateHolder,
): List {
val supportedPaymentMethodTypes = paymentMethodMetadata.supportedPaymentMethodTypes()
+ val bankFormInteractor = BankFormInteractor.create(viewModel)
if (supportedPaymentMethodTypes.size == 1 && customerStateHolder.paymentMethods.value.isEmpty()) {
return listOf(
@@ -25,6 +26,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
+ bankFormInteractor = bankFormInteractor,
),
showsWalletHeader = true,
)
@@ -36,6 +38,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
+ bankFormInteractor = bankFormInteractor,
)
val verticalModeScreen = PaymentSheetScreen.VerticalMode(interactor = interactor)
add(verticalModeScreen)
@@ -54,6 +57,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
+ bankFormInteractor = bankFormInteractor,
),
)
)
diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/BaseSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/BaseSheetViewModel.kt
index e1ce613ce62..c2763936a20 100644
--- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/BaseSheetViewModel.kt
+++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/BaseSheetViewModel.kt
@@ -141,10 +141,6 @@ internal abstract class BaseSheetViewModel(
abstract fun handlePaymentMethodSelected(selection: PaymentSelection?)
- fun handleLinkedBankAccountChanged(selection: PaymentSelection.New.USBankAccount?) {
- updateSelection(selection)
- }
-
fun updateSelection(selection: PaymentSelection?) {
when (selection) {
is PaymentSelection.New -> newPaymentSelection = NewOrExternalPaymentSelection.New(selection)