Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BankFormInteractor #9629

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion paymentsheet/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<ID>LongMethod:EditPaymentMethod.kt$@Composable internal fun EditPaymentMethodUi( viewState: EditPaymentMethodViewState, viewActionHandler: (action: EditPaymentMethodViewAction) -> Unit, modifier: Modifier = Modifier )</ID>
<ID>LongMethod:FormViewModelTest.kt$FormViewModelTest$@Test fun `Verify params are set when element address fields are complete`()</ID>
<ID>LongMethod:FormViewModelTest.kt$FormViewModelTest$@Test fun `Verify params are set when required address fields are complete`()</ID>
<ID>LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, ): PaymentMethodVerticalLayoutInteractor</ID>
<ID>LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, bankFormInteractor: BankFormInteractor, ): PaymentMethodVerticalLayoutInteractor</ID>
<ID>LongMethod:PaymentOptionFactory.kt$PaymentOptionFactory$fun create(selection: PaymentSelection): PaymentOption</ID>
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance()</ID>
<ID>LongMethod:PaymentSheetScreen.kt$@Composable private fun PaymentSheetContent( viewModel: BaseSheetViewModel, headerText: ResolvableString?, walletsState: WalletsState?, walletsProcessingState: WalletsProcessingState?, error: ResolvableString?, currentScreen: PaymentSheetScreen, mandateText: MandateText?, modifier: Modifier )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -61,6 +62,7 @@ internal class USBankAccountFormArguments(
paymentMethodMetadata: PaymentMethodMetadata,
hostedSurface: String,
selectedPaymentMethodCode: String,
bankFormInteractor: BankFormInteractor,
): USBankAccountFormArguments {
val isSaveForFutureUseValueChangeable = isSaveForFutureUseValueChangeable(
code = selectedPaymentMethodCode,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +79,8 @@ internal class DefaultAddPaymentMethodInteractor(
linkInlineHandler = linkInlineHandler,
paymentMethodMetadata = paymentMethodMetadata
)
val bankFormInteractor = BankFormInteractor.create(viewModel)

return DefaultAddPaymentMethodInteractor(
initiallySelectedPaymentMethodType = viewModel.initiallySelectedPaymentMethodType,
selection = viewModel.selection,
Expand All @@ -95,6 +98,7 @@ internal class DefaultAddPaymentMethodInteractor(
paymentMethodMetadata = paymentMethodMetadata,
hostedSurface = CollectBankAccountLauncher.HOSTED_SURFACE_PAYMENT_ELEMENT,
selectedPaymentMethodCode = it,
bankFormInteractor = bankFormInteractor,
)
},
coroutineScope = coroutineScope,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -133,6 +134,7 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
bankFormInteractor = bankFormInteractor,
)
PaymentSheetScreen.VerticalModeForm(interactor = interactor)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal object VerticalModeInitialScreenFactory {
customerStateHolder: CustomerStateHolder,
): List<PaymentSheetScreen> {
val supportedPaymentMethodTypes = paymentMethodMetadata.supportedPaymentMethodTypes()
val bankFormInteractor = BankFormInteractor.create(viewModel)

if (supportedPaymentMethodTypes.size == 1 && customerStateHolder.paymentMethods.value.isEmpty()) {
return listOf(
Expand All @@ -25,6 +26,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
bankFormInteractor = bankFormInteractor,
),
showsWalletHeader = true,
)
Expand All @@ -36,6 +38,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
bankFormInteractor = bankFormInteractor,
)
val verticalModeScreen = PaymentSheetScreen.VerticalMode(interactor = interactor)
add(verticalModeScreen)
Expand All @@ -54,6 +57,7 @@ internal object VerticalModeInitialScreenFactory {
viewModel = viewModel,
paymentMethodMetadata = paymentMethodMetadata,
customerStateHolder = customerStateHolder,
bankFormInteractor = bankFormInteractor,
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading