From ea04631bd1f3589a299f8e864a54453db5d21c78 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 09:39:56 -0800 Subject: [PATCH 1/9] Rename CBC "update" variables to "updateCardBrand" --- .../paymentsheet/SavedPaymentMethodMutator.kt | 11 ++---- .../ui/UpdatePaymentMethodInteractor.kt | 39 +++++-------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index 31af77b8ffa..b68d6e03d68 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -325,7 +325,7 @@ internal class SavedPaymentMethodMutator( displayableSavedPaymentMethod: DisplayableSavedPaymentMethod, canRemove: Boolean, performRemove: suspend () -> Throwable?, - updateCardBrandExecutor: suspend (brand: CardBrand) -> Result, + updateExecutor: suspend (brand: CardBrand) -> Result, ) { if (displayableSavedPaymentMethod.savedPaymentMethod != SavedPaymentMethod.Unexpected) { val isLiveMode = requireNotNull(viewModel.paymentMethodMetadata.value).stripeIntent.isLiveMode @@ -340,7 +340,7 @@ internal class SavedPaymentMethodMutator( performRemove() }, updateCardBrandExecutor = { method, brand -> - updateCardBrandExecutor(brand) + updateExecutor(brand) }, onBrandChoiceOptionsShown = { viewModel.eventReporter.onShowPaymentOptionBrands( @@ -384,16 +384,13 @@ internal class SavedPaymentMethodMutator( navigateBackOnPaymentMethodRemoved(viewModel) }, postPaymentMethodRemoveActions = {}, - onUpdatePaymentMethod = { displayableSavedPaymentMethod, - canRemove, - performRemove, - updateCardBrandExecutor -> + onUpdatePaymentMethod = { displayableSavedPaymentMethod, canRemove, performRemove, updateExecutor -> onUpdatePaymentMethod( viewModel = viewModel, displayableSavedPaymentMethod = displayableSavedPaymentMethod, canRemove = canRemove, performRemove = performRemove, - updateCardBrandExecutor = updateCardBrandExecutor, + updateExecutor = updateExecutor, ) }, navigationPop = viewModel.navigationHandler::pop, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index 713d5269ae1..c261cbafa47 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -166,44 +166,23 @@ internal class DefaultUpdatePaymentMethodInteractor( private fun savePaymentMethod() { coroutineScope.launch { + val newCardBrand = cardBrandChoice.value.brand + error.emit(getInitialError()) status.emit(UpdatePaymentMethodInteractor.Status.Updating) - val updateCardBrandResult = maybeUpdateCardBrand() - - val errorMessage = getErrorMessageForUpdates( - updateCardBrandResult = updateCardBrandResult, - ) - - if (errorMessage != null) { - error.emit(errorMessage) - } - - status.emit(UpdatePaymentMethodInteractor.Status.Idle) - } - } - - private suspend fun maybeUpdateCardBrand(): Result? { - val newCardBrand = cardBrandChoice.value.brand - return if (cardBrandHasBeenChanged.value) { - updateCardBrandExecutor( + val updateCardBrandResult = updateCardBrandExecutor( displayableSavedPaymentMethod.paymentMethod, newCardBrand - ).onSuccess { + ) + + updateCardBrandResult.onSuccess { savedCardBrand.emit(CardBrandChoice(brand = newCardBrand, enabled = true)) cardBrandHasBeenChanged.emit(false) + }.onFailure { + error.emit(it.stripeErrorMessage()) } - } else { - null - } - } - - private fun getErrorMessageForUpdates( - updateCardBrandResult: Result?, - ): ResolvableString? { - return when { - updateCardBrandResult?.isFailure == true -> updateCardBrandResult.exceptionOrNull()?.stripeErrorMessage() - else -> null + status.emit(UpdatePaymentMethodInteractor.Status.Idle) } } From 0a63332bee165790eccb7aaafd6684cf0bdfd765 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 09:47:26 -0800 Subject: [PATCH 2/9] Rename CBC "update" variables to "updateCardBrand" --- .../android/paymentsheet/SavedPaymentMethodMutator.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index b68d6e03d68..31af77b8ffa 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -325,7 +325,7 @@ internal class SavedPaymentMethodMutator( displayableSavedPaymentMethod: DisplayableSavedPaymentMethod, canRemove: Boolean, performRemove: suspend () -> Throwable?, - updateExecutor: suspend (brand: CardBrand) -> Result, + updateCardBrandExecutor: suspend (brand: CardBrand) -> Result, ) { if (displayableSavedPaymentMethod.savedPaymentMethod != SavedPaymentMethod.Unexpected) { val isLiveMode = requireNotNull(viewModel.paymentMethodMetadata.value).stripeIntent.isLiveMode @@ -340,7 +340,7 @@ internal class SavedPaymentMethodMutator( performRemove() }, updateCardBrandExecutor = { method, brand -> - updateExecutor(brand) + updateCardBrandExecutor(brand) }, onBrandChoiceOptionsShown = { viewModel.eventReporter.onShowPaymentOptionBrands( @@ -384,13 +384,16 @@ internal class SavedPaymentMethodMutator( navigateBackOnPaymentMethodRemoved(viewModel) }, postPaymentMethodRemoveActions = {}, - onUpdatePaymentMethod = { displayableSavedPaymentMethod, canRemove, performRemove, updateExecutor -> + onUpdatePaymentMethod = { displayableSavedPaymentMethod, + canRemove, + performRemove, + updateCardBrandExecutor -> onUpdatePaymentMethod( viewModel = viewModel, displayableSavedPaymentMethod = displayableSavedPaymentMethod, canRemove = canRemove, performRemove = performRemove, - updateExecutor = updateExecutor, + updateCardBrandExecutor = updateCardBrandExecutor, ) }, navigationPop = viewModel.navigationHandler::pop, From d0beb2588422dafb40fc043aebf8606b0eb6de31 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 10:19:36 -0800 Subject: [PATCH 3/9] Only update card brand when the brand has changed --- .../ui/UpdatePaymentMethodInteractor.kt | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index c261cbafa47..8081ab2b1f5 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -166,23 +166,44 @@ internal class DefaultUpdatePaymentMethodInteractor( private fun savePaymentMethod() { coroutineScope.launch { - val newCardBrand = cardBrandChoice.value.brand - error.emit(getInitialError()) status.emit(UpdatePaymentMethodInteractor.Status.Updating) - val updateCardBrandResult = updateCardBrandExecutor( - displayableSavedPaymentMethod.paymentMethod, - newCardBrand + val updateCardBrandResult = maybeUpdateCardBrand() + + val errorMessage = getErrorMessageForUpdates( + updateCardBrandResult = updateCardBrandResult, ) - updateCardBrandResult.onSuccess { + if (errorMessage != null) { + error.emit(errorMessage) + } + + status.emit(UpdatePaymentMethodInteractor.Status.Idle) + } + } + + private suspend fun maybeUpdateCardBrand(): Result? { + val newCardBrand = cardBrandChoice.value.brand + return if (newCardBrand != getInitialCardBrandChoice().brand) { + updateCardBrandExecutor( + displayableSavedPaymentMethod.paymentMethod, + newCardBrand + ).onSuccess { savedCardBrand.emit(CardBrandChoice(brand = newCardBrand, enabled = true)) cardBrandHasBeenChanged.emit(false) - }.onFailure { - error.emit(it.stripeErrorMessage()) } - status.emit(UpdatePaymentMethodInteractor.Status.Idle) + } else { + null + } + } + + private fun getErrorMessageForUpdates( + updateCardBrandResult: Result?, + ): ResolvableString? { + return when { + updateCardBrandResult?.isFailure == true -> updateCardBrandResult.exceptionOrNull()?.stripeErrorMessage() + else -> null } } From 19c94ddd6768683678f2ced9e35162ed6cf453ca Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 10:26:26 -0800 Subject: [PATCH 4/9] Update how we check whether a card brand has been changed --- .../android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index 8081ab2b1f5..713d5269ae1 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -185,7 +185,7 @@ internal class DefaultUpdatePaymentMethodInteractor( private suspend fun maybeUpdateCardBrand(): Result? { val newCardBrand = cardBrandChoice.value.brand - return if (newCardBrand != getInitialCardBrandChoice().brand) { + return if (cardBrandHasBeenChanged.value) { updateCardBrandExecutor( displayableSavedPaymentMethod.paymentMethod, newCardBrand From c0d4bdd1f59904d9d392ed1e69e32c2956405158 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 10:41:02 -0800 Subject: [PATCH 5/9] Add onUpdateSuccess parameter to DefaultUpdatePaymentMethodInteractor constructor --- .../customersheet/CustomerSheetViewModel.kt | 7 ++++--- .../EmbeddedUpdateScreenInteractorFactory.kt | 13 +++++++------ .../paymentsheet/SavedPaymentMethodMutator.kt | 19 ++++++++++--------- .../ui/UpdatePaymentMethodInteractor.kt | 1 + .../paymentsheet/ui/UpdatePaymentMethodUI.kt | 5 +++-- .../CustomerSheetScreenshotTest.kt | 13 +++++++------ ...efaultUpdatePaymentMethodInteractorTest.kt | 7 ++++--- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt index 58e05fad59a..3b4f804e75b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -543,7 +543,10 @@ internal class CustomerSheetViewModel( canRemove = customerState.canRemove, displayableSavedPaymentMethod = paymentMethod, cardBrandFilter = PaymentSheetCardBrandFilter(customerState.configuration.cardBrandAcceptance), + // This checkbox is never displayed in CustomerSheet. + shouldShowSetAsDefaultCheckbox = false, removeExecutor = ::removeExecutor, + updateCardBrandExecutor = ::updateCardBrandExecutor, onBrandChoiceOptionsShown = { eventReporter.onShowPaymentOptionBrands( source = CustomerSheetEventReporter.CardBrandChoiceEventSource.Edit, @@ -556,10 +559,8 @@ internal class CustomerSheetViewModel( selectedBrand = it ) }, - updateCardBrandExecutor = ::updateCardBrandExecutor, + onUpdateSuccess = {}, workContext = workContext, - // This checkbox is never displayed in CustomerSheet. - shouldShowSetAsDefaultCheckbox = false, ), isLiveMode = isLiveModeProvider(), ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt index cb83f2cbaac..0dda4e84880 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt @@ -33,6 +33,12 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( canRemove = customerStateHolder.canRemove.value, displayableSavedPaymentMethod, cardBrandFilter = paymentMethodMetadata.cardBrandFilter, + shouldShowSetAsDefaultCheckbox = ( + paymentMethodMetadata.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && + !displayableSavedPaymentMethod.isDefaultPaymentMethod( + defaultPaymentMethodId = customerStateHolder.customer.value?.defaultPaymentMethodId + ) + ), removeExecutor = { method -> val result = savedPaymentMethodMutatorProvider.get().removePaymentMethodInEditScreen(method) if (result == null) { @@ -67,12 +73,7 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( selectedBrand = it ) }, - shouldShowSetAsDefaultCheckbox = ( - paymentMethodMetadata.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && - !displayableSavedPaymentMethod.isDefaultPaymentMethod( - defaultPaymentMethodId = customerStateHolder.customer.value?.defaultPaymentMethodId - ) - ), + onUpdateSuccess = {}, ) } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index 31af77b8ffa..fa5a9afce07 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -336,6 +336,15 @@ internal class SavedPaymentMethodMutator( canRemove = canRemove, displayableSavedPaymentMethod, cardBrandFilter = PaymentSheetCardBrandFilter(viewModel.config.cardBrandAcceptance), + shouldShowSetAsDefaultCheckbox = ( + viewModel + .paymentMethodMetadata + .value?.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && + !displayableSavedPaymentMethod.isDefaultPaymentMethod( + defaultPaymentMethodId = + viewModel.customerStateHolder.customer.value?.defaultPaymentMethodId + ) + ), removeExecutor = { method -> performRemove() }, @@ -354,15 +363,7 @@ internal class SavedPaymentMethodMutator( selectedBrand = it ) }, - shouldShowSetAsDefaultCheckbox = ( - viewModel - .paymentMethodMetadata - .value?.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && - !displayableSavedPaymentMethod.isDefaultPaymentMethod( - defaultPaymentMethodId = - viewModel.customerStateHolder.customer.value?.defaultPaymentMethodId - ) - ), + onUpdateSuccess = {}, ) ) ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index 713d5269ae1..073e4f7952d 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -87,6 +87,7 @@ internal class DefaultUpdatePaymentMethodInteractor( private val updateCardBrandExecutor: UpdateCardBrandOperation, private val onBrandChoiceOptionsShown: (CardBrand) -> Unit, private val onBrandChoiceOptionsDismissed: (CardBrand) -> Unit, + val onUpdateSuccess: () -> Unit, workContext: CoroutineContext = Dispatchers.Default, ) : UpdatePaymentMethodInteractor { private val coroutineScope = CoroutineScope(workContext + SupervisorJob()) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt index 2f9d9ca11f6..08aedc92ddb 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt @@ -528,12 +528,13 @@ private fun PreviewUpdatePaymentMethodUI() { isLiveMode = false, canRemove = true, displayableSavedPaymentMethod = exampleCard, + cardBrandFilter = DefaultCardBrandFilter, + shouldShowSetAsDefaultCheckbox = true, removeExecutor = { null }, updateCardBrandExecutor = { paymentMethod, _ -> Result.success(paymentMethod) }, - cardBrandFilter = DefaultCardBrandFilter, onBrandChoiceOptionsShown = {}, onBrandChoiceOptionsDismissed = {}, - shouldShowSetAsDefaultCheckbox = true, + onUpdateSuccess = {}, ), modifier = Modifier ) diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt index e5ad6861ab3..9d4fc60d0ce 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt @@ -347,16 +347,17 @@ internal class CustomerSheetScreenshotTest { ): CustomerSheetViewState { return CustomerSheetViewState.UpdatePaymentMethod( updatePaymentMethodInteractor = DefaultUpdatePaymentMethodInteractor( - displayableSavedPaymentMethod = PaymentMethodFixtures.displayableCard(), - removeExecutor = { null }, - updateCardBrandExecutor = { paymentMethod, _ -> Result.success(paymentMethod) }, - canRemove = canRemove, isLiveMode = true, + canRemove = canRemove, + displayableSavedPaymentMethod = PaymentMethodFixtures.displayableCard(), cardBrandFilter = DefaultCardBrandFilter, - onBrandChoiceOptionsDismissed = {}, - onBrandChoiceOptionsShown = {}, // This checkbox is never displayed in CustomerSheet. shouldShowSetAsDefaultCheckbox = false, + removeExecutor = { null }, + updateCardBrandExecutor = { paymentMethod, _ -> Result.success(paymentMethod) }, + onBrandChoiceOptionsShown = {}, + onBrandChoiceOptionsDismissed = {}, + onUpdateSuccess = {}, ), isLiveMode = true, ) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt index ecd13d0d8f6..5b84c839032 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt @@ -315,13 +315,14 @@ class DefaultUpdatePaymentMethodInteractorTest { isLiveMode = isLiveMode, canRemove = canRemove, displayableSavedPaymentMethod = displayableSavedPaymentMethod, + cardBrandFilter = DefaultCardBrandFilter, + shouldShowSetAsDefaultCheckbox = shouldShowSetAsDefaultCheckbox, removeExecutor = onRemovePaymentMethod, updateCardBrandExecutor = onUpdateCardBrand, - workContext = UnconfinedTestDispatcher(), - cardBrandFilter = DefaultCardBrandFilter, onBrandChoiceOptionsShown = {}, onBrandChoiceOptionsDismissed = {}, - shouldShowSetAsDefaultCheckbox = shouldShowSetAsDefaultCheckbox, + onUpdateSuccess = {}, + workContext = UnconfinedTestDispatcher(), ) TestParams(interactor).apply { runTest { testBlock() } } From ced69f2f7b0bdfcc5586ccd0a6964535449d401f Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 12:44:31 -0800 Subject: [PATCH 6/9] Use onUpdateSuccess function in DefaultUpdatePaymentMethodInteractor --- .../ui/UpdatePaymentMethodInteractor.kt | 26 ++++++++++---- ...efaultUpdatePaymentMethodInteractorTest.kt | 36 ++++++++++++++++++- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index 073e4f7952d..683794e4e71 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -172,12 +172,14 @@ internal class DefaultUpdatePaymentMethodInteractor( val updateCardBrandResult = maybeUpdateCardBrand() - val errorMessage = getErrorMessageForUpdates( + val updateResult = getUpdateResult( updateCardBrandResult = updateCardBrandResult, ) - if (errorMessage != null) { - error.emit(errorMessage) + when (updateResult) { + is UpdateResult.Error -> error.emit(updateResult.errorMessage) + UpdateResult.Success -> onUpdateSuccess() + UpdateResult.NoUpdatesMade -> {} } status.emit(UpdatePaymentMethodInteractor.Status.Idle) @@ -199,12 +201,16 @@ internal class DefaultUpdatePaymentMethodInteractor( } } - private fun getErrorMessageForUpdates( + private fun getUpdateResult( updateCardBrandResult: Result?, - ): ResolvableString? { + ): UpdateResult { return when { - updateCardBrandResult?.isFailure == true -> updateCardBrandResult.exceptionOrNull()?.stripeErrorMessage() - else -> null + updateCardBrandResult == null -> UpdateResult.NoUpdatesMade + updateCardBrandResult.isFailure -> UpdateResult.Error( + updateCardBrandResult.exceptionOrNull()?.stripeErrorMessage() + ) + updateCardBrandResult.isSuccess -> UpdateResult.Success + else -> UpdateResult.NoUpdatesMade } } @@ -244,6 +250,12 @@ internal class DefaultUpdatePaymentMethodInteractor( }?.filter { cardBrandFilter.isAccepted(it) } return (filteredCardBrands?.size ?: 0) > 1 } + + sealed class UpdateResult { + data class Error(val errorMessage: ResolvableString?) : UpdateResult() + data object Success : UpdateResult() + data object NoUpdatesMade : UpdateResult() + } } internal const val PaymentMethodRemovalDelayMillis = 600L diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt index 5b84c839032..66c6c43df97 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt @@ -159,6 +159,38 @@ class DefaultUpdatePaymentMethodInteractorTest { } } + @Test + fun updatingCardBrand_callsOnUpdateSuccess() { + var updateSuccessCalled = false + fun onUpdateSuccess() { + updateSuccessCalled = true + } + + runScenario( + displayableSavedPaymentMethod = + PaymentMethodFixtures.CARD_WITH_NETWORKS_PAYMENT_METHOD.toDisplayableSavedPaymentMethod(), + onUpdateCardBrand = { paymentMethod, _ -> Result.success(paymentMethod) }, + onUpdateSuccess = ::onUpdateSuccess, + ) { + interactor.state.test { + assertThat(awaitItem().cardBrandChoice.brand).isEqualTo(CardBrand.CartesBancaires) + } + + val expectedNewCardBrand = CardBrand.Visa + interactor.handleViewAction( + UpdatePaymentMethodInteractor.ViewAction.BrandChoiceChanged( + cardBrandChoice = CardBrandChoice(brand = expectedNewCardBrand, enabled = true) + ) + ) + interactor.state.test { + assertThat(awaitItem().cardBrandHasBeenChanged).isTrue() + } + + interactor.handleViewAction(UpdatePaymentMethodInteractor.ViewAction.SaveButtonPressed) + assertThat(updateSuccessCalled).isTrue() + } + } + @Test fun updatingCardBrand_updatesStateAsExpected() { var updatedPaymentMethod: PaymentMethod? = null @@ -175,6 +207,7 @@ class DefaultUpdatePaymentMethodInteractorTest { runScenario( displayableSavedPaymentMethod = initialPaymentMethod.toDisplayableSavedPaymentMethod(), onUpdateCardBrand = ::updateCardBrandExecutor, + onUpdateSuccess = {}, ) { interactor.state.test { assertThat(awaitItem().cardBrandChoice.brand).isEqualTo(CardBrand.CartesBancaires) @@ -308,6 +341,7 @@ class DefaultUpdatePaymentMethodInteractorTest { displayableSavedPaymentMethod: DisplayableSavedPaymentMethod = PaymentMethodFixtures.displayableCard(), onRemovePaymentMethod: (PaymentMethod) -> Throwable? = { notImplemented() }, onUpdateCardBrand: (PaymentMethod, CardBrand) -> Result = { _, _ -> notImplemented() }, + onUpdateSuccess: () -> Unit = { notImplemented() }, shouldShowSetAsDefaultCheckbox: Boolean = false, testBlock: suspend TestParams.() -> Unit ) { @@ -321,7 +355,7 @@ class DefaultUpdatePaymentMethodInteractorTest { updateCardBrandExecutor = onUpdateCardBrand, onBrandChoiceOptionsShown = {}, onBrandChoiceOptionsDismissed = {}, - onUpdateSuccess = {}, + onUpdateSuccess = onUpdateSuccess, workContext = UnconfinedTestDispatcher(), ) From 221e67a461f0fe290348accebc6db440abd5b0c5 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 12:48:11 -0800 Subject: [PATCH 7/9] Move navigationPop/onBackPressed logic into onUpdateSuccess --- .../stripe/android/customersheet/CustomerSheetViewModel.kt | 3 +-- .../stripe/android/paymentsheet/SavedPaymentMethodMutator.kt | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt index 3b4f804e75b..1f88473c14e 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -512,7 +512,6 @@ internal class CustomerSheetViewModel( productUsageTokens = setOf("CustomerSheet"), ) ).onSuccess { updatedMethod -> - onBackPressed() updatePaymentMethodInState(updatedMethod) eventReporter.onUpdatePaymentMethodSucceeded( @@ -559,7 +558,7 @@ internal class CustomerSheetViewModel( selectedBrand = it ) }, - onUpdateSuccess = {}, + onUpdateSuccess = ::onBackPressed, workContext = workContext, ), isLiveMode = isLiveModeProvider(), diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index fa5a9afce07..1e3568d5b99 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -265,8 +265,6 @@ internal class SavedPaymentMethodMutator( ) onSuccess(updatedMethod) - - navigationPop() } eventReporter.onUpdatePaymentMethodSucceeded( @@ -363,7 +361,7 @@ internal class SavedPaymentMethodMutator( selectedBrand = it ) }, - onUpdateSuccess = {}, + onUpdateSuccess = viewModel.navigationHandler::pop, ) ) ) From 12bb29ee3b086d8905a276bd7c95af8ae4cb1dae Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 13:01:47 -0800 Subject: [PATCH 8/9] Remove unused navigationPop parameter --- .../embedded/content/EmbeddedContentHelper.kt | 2 -- .../manage/EmbeddedUpdateScreenInteractorFactory.kt | 5 ++++- .../manage/ManageSavedPaymentMethodMutatorFactory.kt | 3 --- .../android/paymentsheet/SavedPaymentMethodMutator.kt | 2 -- .../android/paymentsheet/SavedPaymentMethodMutatorTest.kt | 7 ------- 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedContentHelper.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedContentHelper.kt index 12704333227..02eaeeaac1d 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedContentHelper.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedContentHelper.kt @@ -212,8 +212,6 @@ internal class DefaultEmbeddedContentHelper @Inject constructor( selection = selectionHolder.selection.value, ) }, - navigationPop = { - }, isLinkEnabled = stateFlowOf(paymentMethodMetadata.linkState != null), isNotPaymentFlow = false, ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt index 0dda4e84880..7c47a90bcb9 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt @@ -24,6 +24,7 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( private val customerStateHolder: CustomerStateHolder, private val selectionHolder: EmbeddedSelectionHolder, private val eventReporter: EventReporter, + private val manageNavigatorProvider: Provider, ) : EmbeddedUpdateScreenInteractorFactory { override fun createUpdateScreenInteractor( displayableSavedPaymentMethod: DisplayableSavedPaymentMethod @@ -73,7 +74,9 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( selectedBrand = it ) }, - onUpdateSuccess = {}, + onUpdateSuccess = { + manageNavigatorProvider.get().performAction(ManageNavigator.Action.Back) + }, ) } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/ManageSavedPaymentMethodMutatorFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/ManageSavedPaymentMethodMutatorFactory.kt index 3564f8d110d..bf1fd18ceda 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/ManageSavedPaymentMethodMutatorFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/ManageSavedPaymentMethodMutatorFactory.kt @@ -57,9 +57,6 @@ internal class ManageSavedPaymentMethodMutatorFactory @Inject constructor( onUpdatePaymentMethod = { displayableSavedPaymentMethod, _, _, _ -> onUpdatePaymentMethod(displayableSavedPaymentMethod) }, - navigationPop = { - manageNavigatorProvider.get().performAction(ManageNavigator.Action.Back) - }, isLinkEnabled = stateFlowOf(false), // Link is never enabled in the manage screen. isNotPaymentFlow = false, ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index 1e3568d5b99..e455c9a9f28 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -55,7 +55,6 @@ internal class SavedPaymentMethodMutator( performRemove: suspend () -> Throwable?, updateExecutor: suspend (brand: CardBrand) -> Result, ) -> Unit, - private val navigationPop: () -> Unit, isLinkEnabled: StateFlow, isNotPaymentFlow: Boolean, ) { @@ -395,7 +394,6 @@ internal class SavedPaymentMethodMutator( updateCardBrandExecutor = updateCardBrandExecutor, ) }, - navigationPop = viewModel.navigationHandler::pop, isLinkEnabled = viewModel.linkHandler.isLinkEnabled, isNotPaymentFlow = !viewModel.isCompleteFlow, ).apply { diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt index 34363d3f9ec..436fa1f56ef 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt @@ -408,7 +408,6 @@ class SavedPaymentMethodMutatorTest { updatePaymentMethodTurbine.awaitItem().updateExecutor(CardBrand.CartesBancaires) assertThat(calledUpdate.awaitItem()).isTrue() - assertThat(navigationPopTurbine.awaitItem()).isNotNull() val paymentMethods = customerStateHolder.paymentMethods.value assertThat(paymentMethods).hasSize(1) @@ -450,7 +449,6 @@ class SavedPaymentMethodMutatorTest { ) assertThat(calledUpdate.awaitItem()).isTrue() - assertThat(navigationPopTurbine.awaitItem()).isNotNull() val paymentMethods = customerStateHolder.paymentMethods.value assertThat(paymentMethods).hasSize(1) @@ -552,7 +550,6 @@ class SavedPaymentMethodMutatorTest { val postPaymentMethodRemovedTurbine = Turbine() val prePaymentMethodRemovedTurbine = Turbine() val updatePaymentMethodTurbine = Turbine() - val navigationPopTurbine = Turbine() val savedPaymentMethodMutator = SavedPaymentMethodMutator( paymentMethodMetadataFlow = stateFlowOf( @@ -579,7 +576,6 @@ class SavedPaymentMethodMutatorTest { UpdateCall(displayableSavedPaymentMethod, canRemove, performRemove, updateExecutor) ) }, - navigationPop = { navigationPopTurbine.add(Unit) }, isLinkEnabled = stateFlowOf(false), isNotPaymentFlow = true, ) @@ -591,7 +587,6 @@ class SavedPaymentMethodMutatorTest { prePaymentMethodRemovedTurbine = prePaymentMethodRemovedTurbine, postPaymentMethodRemovedTurbine = postPaymentMethodRemovedTurbine, updatePaymentMethodTurbine = updatePaymentMethodTurbine, - navigationPopTurbine = navigationPopTurbine, testScope = this, ).apply { block() @@ -601,7 +596,6 @@ class SavedPaymentMethodMutatorTest { postPaymentMethodRemovedTurbine.ensureAllEventsConsumed() updatePaymentMethodTurbine.ensureAllEventsConsumed() - navigationPopTurbine.ensureAllEventsConsumed() } } @@ -613,7 +607,6 @@ class SavedPaymentMethodMutatorTest { val prePaymentMethodRemovedTurbine: ReceiveTurbine, val postPaymentMethodRemovedTurbine: ReceiveTurbine, val updatePaymentMethodTurbine: ReceiveTurbine, - val navigationPopTurbine: ReceiveTurbine, val testScope: TestScope, ) From dcc62c0d4fae380ba612dbd6401886c2aefbf200 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 20 Feb 2025 13:21:06 -0800 Subject: [PATCH 9/9] Simplify diff --- .../customersheet/CustomerSheetViewModel.kt | 6 +++--- .../EmbeddedUpdateScreenInteractorFactory.kt | 12 ++++++------ .../paymentsheet/SavedPaymentMethodMutator.kt | 18 +++++++++--------- .../ui/UpdatePaymentMethodInteractor.kt | 2 +- .../paymentsheet/ui/UpdatePaymentMethodUI.kt | 4 ++-- .../CustomerSheetScreenshotTest.kt | 12 ++++++------ ...DefaultUpdatePaymentMethodInteractorTest.kt | 6 +++--- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt index 1f88473c14e..219aaf22902 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -542,10 +542,7 @@ internal class CustomerSheetViewModel( canRemove = customerState.canRemove, displayableSavedPaymentMethod = paymentMethod, cardBrandFilter = PaymentSheetCardBrandFilter(customerState.configuration.cardBrandAcceptance), - // This checkbox is never displayed in CustomerSheet. - shouldShowSetAsDefaultCheckbox = false, removeExecutor = ::removeExecutor, - updateCardBrandExecutor = ::updateCardBrandExecutor, onBrandChoiceOptionsShown = { eventReporter.onShowPaymentOptionBrands( source = CustomerSheetEventReporter.CardBrandChoiceEventSource.Edit, @@ -559,7 +556,10 @@ internal class CustomerSheetViewModel( ) }, onUpdateSuccess = ::onBackPressed, + updateCardBrandExecutor = ::updateCardBrandExecutor, workContext = workContext, + // This checkbox is never displayed in CustomerSheet. + shouldShowSetAsDefaultCheckbox = false, ), isLiveMode = isLiveModeProvider(), ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt index 7c47a90bcb9..f83f4698de9 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/manage/EmbeddedUpdateScreenInteractorFactory.kt @@ -34,12 +34,6 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( canRemove = customerStateHolder.canRemove.value, displayableSavedPaymentMethod, cardBrandFilter = paymentMethodMetadata.cardBrandFilter, - shouldShowSetAsDefaultCheckbox = ( - paymentMethodMetadata.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && - !displayableSavedPaymentMethod.isDefaultPaymentMethod( - defaultPaymentMethodId = customerStateHolder.customer.value?.defaultPaymentMethodId - ) - ), removeExecutor = { method -> val result = savedPaymentMethodMutatorProvider.get().removePaymentMethodInEditScreen(method) if (result == null) { @@ -74,6 +68,12 @@ internal class DefaultEmbeddedUpdateScreenInteractorFactory @Inject constructor( selectedBrand = it ) }, + shouldShowSetAsDefaultCheckbox = ( + paymentMethodMetadata.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && + !displayableSavedPaymentMethod.isDefaultPaymentMethod( + defaultPaymentMethodId = customerStateHolder.customer.value?.defaultPaymentMethodId + ) + ), onUpdateSuccess = { manageNavigatorProvider.get().performAction(ManageNavigator.Action.Back) }, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt index e455c9a9f28..02f9343d485 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -333,15 +333,6 @@ internal class SavedPaymentMethodMutator( canRemove = canRemove, displayableSavedPaymentMethod, cardBrandFilter = PaymentSheetCardBrandFilter(viewModel.config.cardBrandAcceptance), - shouldShowSetAsDefaultCheckbox = ( - viewModel - .paymentMethodMetadata - .value?.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && - !displayableSavedPaymentMethod.isDefaultPaymentMethod( - defaultPaymentMethodId = - viewModel.customerStateHolder.customer.value?.defaultPaymentMethodId - ) - ), removeExecutor = { method -> performRemove() }, @@ -360,6 +351,15 @@ internal class SavedPaymentMethodMutator( selectedBrand = it ) }, + shouldShowSetAsDefaultCheckbox = ( + viewModel + .paymentMethodMetadata + .value?.customerMetadata?.isPaymentMethodSetAsDefaultEnabled == true && + !displayableSavedPaymentMethod.isDefaultPaymentMethod( + defaultPaymentMethodId = + viewModel.customerStateHolder.customer.value?.defaultPaymentMethodId + ) + ), onUpdateSuccess = viewModel.navigationHandler::pop, ) ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt index 683794e4e71..12db9a9cb02 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodInteractor.kt @@ -87,7 +87,7 @@ internal class DefaultUpdatePaymentMethodInteractor( private val updateCardBrandExecutor: UpdateCardBrandOperation, private val onBrandChoiceOptionsShown: (CardBrand) -> Unit, private val onBrandChoiceOptionsDismissed: (CardBrand) -> Unit, - val onUpdateSuccess: () -> Unit, + private val onUpdateSuccess: () -> Unit, workContext: CoroutineContext = Dispatchers.Default, ) : UpdatePaymentMethodInteractor { private val coroutineScope = CoroutineScope(workContext + SupervisorJob()) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt index 08aedc92ddb..beb1972ecd0 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/UpdatePaymentMethodUI.kt @@ -528,12 +528,12 @@ private fun PreviewUpdatePaymentMethodUI() { isLiveMode = false, canRemove = true, displayableSavedPaymentMethod = exampleCard, - cardBrandFilter = DefaultCardBrandFilter, - shouldShowSetAsDefaultCheckbox = true, removeExecutor = { null }, updateCardBrandExecutor = { paymentMethod, _ -> Result.success(paymentMethod) }, + cardBrandFilter = DefaultCardBrandFilter, onBrandChoiceOptionsShown = {}, onBrandChoiceOptionsDismissed = {}, + shouldShowSetAsDefaultCheckbox = true, onUpdateSuccess = {}, ), modifier = Modifier diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt index 9d4fc60d0ce..3a2b2cab98c 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetScreenshotTest.kt @@ -347,16 +347,16 @@ internal class CustomerSheetScreenshotTest { ): CustomerSheetViewState { return CustomerSheetViewState.UpdatePaymentMethod( updatePaymentMethodInteractor = DefaultUpdatePaymentMethodInteractor( - isLiveMode = true, - canRemove = canRemove, displayableSavedPaymentMethod = PaymentMethodFixtures.displayableCard(), - cardBrandFilter = DefaultCardBrandFilter, - // This checkbox is never displayed in CustomerSheet. - shouldShowSetAsDefaultCheckbox = false, removeExecutor = { null }, updateCardBrandExecutor = { paymentMethod, _ -> Result.success(paymentMethod) }, - onBrandChoiceOptionsShown = {}, + canRemove = canRemove, + isLiveMode = true, + cardBrandFilter = DefaultCardBrandFilter, onBrandChoiceOptionsDismissed = {}, + onBrandChoiceOptionsShown = {}, + // This checkbox is never displayed in CustomerSheet. + shouldShowSetAsDefaultCheckbox = false, onUpdateSuccess = {}, ), isLiveMode = true, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt index 66c6c43df97..bbeaf79aeea 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/DefaultUpdatePaymentMethodInteractorTest.kt @@ -349,14 +349,14 @@ class DefaultUpdatePaymentMethodInteractorTest { isLiveMode = isLiveMode, canRemove = canRemove, displayableSavedPaymentMethod = displayableSavedPaymentMethod, - cardBrandFilter = DefaultCardBrandFilter, - shouldShowSetAsDefaultCheckbox = shouldShowSetAsDefaultCheckbox, removeExecutor = onRemovePaymentMethod, updateCardBrandExecutor = onUpdateCardBrand, + workContext = UnconfinedTestDispatcher(), + cardBrandFilter = DefaultCardBrandFilter, onBrandChoiceOptionsShown = {}, onBrandChoiceOptionsDismissed = {}, + shouldShowSetAsDefaultCheckbox = shouldShowSetAsDefaultCheckbox, onUpdateSuccess = onUpdateSuccess, - workContext = UnconfinedTestDispatcher(), ) TestParams(interactor).apply { runTest { testBlock() } }