From 4aa391fbdc754da27e45a401b751b545e965cd2b Mon Sep 17 00:00:00 2001 From: Jay Newstrom Date: Fri, 19 Jul 2024 13:55:16 -0600 Subject: [PATCH] Move google pay into PaymentMethodMetadata. (#8829) --- paymentsheet/api/paymentsheet.api | 24 ------------------- .../customersheet/CustomerSheetLoader.kt | 10 ++++---- .../customersheet/CustomerSheetState.kt | 1 - .../customersheet/CustomerSheetViewModel.kt | 8 +++---- .../paymentmethod/PaymentMethodMetadata.kt | 5 +++- .../paymentsheet/PaymentOptionsViewModel.kt | 17 ++++--------- .../paymentsheet/PaymentSheetViewModel.kt | 17 ++++--------- .../paymentsheet/SavedPaymentMethodMutator.kt | 7 +++--- .../flowcontroller/PaymentSelectionUpdater.kt | 2 +- .../paymentsheet/state/GooglePayState.kt | 18 -------------- .../paymentsheet/state/PaymentSheetLoader.kt | 15 ++++++------ .../paymentsheet/state/PaymentSheetState.kt | 4 +--- .../paymentsheet/state/WalletsState.kt | 4 ++-- .../viewmodels/BaseSheetViewModel.kt | 5 ---- .../viewmodels/PaymentOptionsItemsMapper.kt | 13 +++++----- .../CustomerSheetViewModelTest.kt | 2 ++ .../state/DefaultCustomerSheetLoaderTest.kt | 10 ++++---- .../utils/CustomerSheetTestHelper.kt | 4 +++- .../utils/FakeCustomerSheetLoader.kt | 4 ++-- .../PaymentMethodMetadataFactory.kt | 4 +++- .../PaymentMethodMetadataTest.kt | 2 ++ .../PaymentOptionsViewModelTest.kt | 8 +++---- .../paymentsheet/PaymentSheetFixtures.kt | 10 ++++---- .../paymentsheet/PaymentSheetViewModelTest.kt | 9 ++++--- .../SavedPaymentMethodMutatorTest.kt | 3 +-- .../DefaultFlowControllerTest.kt | 8 ------- .../PaymentSelectionUpdaterTest.kt | 8 +++---- .../state/DefaultPaymentSheetLoaderTest.kt | 9 +++---- .../PaymentOptionsItemsMapperTest.kt | 11 ++++----- .../android/utils/FakePaymentSheetLoader.kt | 3 +-- .../utils/RelayingPaymentSheetLoader.kt | 2 -- 31 files changed, 85 insertions(+), 162 deletions(-) delete mode 100644 paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/GooglePayState.kt diff --git a/paymentsheet/api/paymentsheet.api b/paymentsheet/api/paymentsheet.api index 293a9f87f61..b7871babc92 100644 --- a/paymentsheet/api/paymentsheet.api +++ b/paymentsheet/api/paymentsheet.api @@ -1890,30 +1890,6 @@ public final class com/stripe/android/paymentsheet/state/CustomerState$Permissio public synthetic fun newArray (I)[Ljava/lang/Object; } -public final class com/stripe/android/paymentsheet/state/GooglePayState$Available$Creator : android/os/Parcelable$Creator { - public fun ()V - public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/state/GooglePayState$Available; - public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object; - public final fun newArray (I)[Lcom/stripe/android/paymentsheet/state/GooglePayState$Available; - public synthetic fun newArray (I)[Ljava/lang/Object; -} - -public final class com/stripe/android/paymentsheet/state/GooglePayState$Indeterminate$Creator : android/os/Parcelable$Creator { - public fun ()V - public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/state/GooglePayState$Indeterminate; - public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object; - public final fun newArray (I)[Lcom/stripe/android/paymentsheet/state/GooglePayState$Indeterminate; - public synthetic fun newArray (I)[Ljava/lang/Object; -} - -public final class com/stripe/android/paymentsheet/state/GooglePayState$NotAvailable$Creator : android/os/Parcelable$Creator { - public fun ()V - public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/state/GooglePayState$NotAvailable; - public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object; - public final fun newArray (I)[Lcom/stripe/android/paymentsheet/state/GooglePayState$NotAvailable; - public synthetic fun newArray (I)[Ljava/lang/Object; -} - public final class com/stripe/android/paymentsheet/state/LinkState$Creator : android/os/Parcelable$Creator { public fun ()V public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/state/LinkState; diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt index 3e29adcc8bc..77172b8b428 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt @@ -131,6 +131,10 @@ internal class DefaultCustomerSheetLoader( preferredNetworks = configuration.preferredNetworks, ) + val isGooglePayReadyAndEnabled = configuration.googlePayEnabled && googlePayRepositoryFactory( + if (isLiveModeProvider()) GooglePayEnvironment.Production else GooglePayEnvironment.Test + ).isReady().first() + val metadata = PaymentMethodMetadata( stripeIntent = elementsSession.stripeIntent, billingDetailsCollectionConfiguration = billingDetailsCollectionConfig, @@ -145,6 +149,7 @@ internal class DefaultCustomerSheetLoader( sharedDataSpecs = sharedDataSpecs, financialConnectionsAvailable = isFinancialConnectionsAvailable(), externalPaymentMethodSpecs = emptyList(), + isGooglePayReady = isGooglePayReadyAndEnabled, ) ElementsSessionWithMetadata(elementsSession = elementsSession, metadata = metadata) @@ -194,10 +199,6 @@ internal class DefaultCustomerSheetLoader( } } - val isGooglePayReadyAndEnabled = configuration.googlePayEnabled && googlePayRepositoryFactory( - if (isLiveModeProvider()) GooglePayEnvironment.Production else GooglePayEnvironment.Test - ).isReady().first() - val elementsSession = elementsSessionWithMetadata.elementsSession val metadata = elementsSessionWithMetadata.metadata @@ -211,7 +212,6 @@ internal class DefaultCustomerSheetLoader( paymentMethodMetadata = metadata, supportedPaymentMethods = validSupportedPaymentMethods, customerPaymentMethods = paymentMethods, - isGooglePayReady = isGooglePayReadyAndEnabled, paymentSelection = paymentSelection, validationError = elementsSession.stripeIntent.validate(), ) diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetState.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetState.kt index dc8e98f90e5..167b8167177 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetState.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetState.kt @@ -14,7 +14,6 @@ internal sealed interface CustomerSheetState { val paymentMethodMetadata: PaymentMethodMetadata, val customerPaymentMethods: List, val supportedPaymentMethods: List, - val isGooglePayReady: Boolean, val paymentSelection: PaymentSelection?, val validationError: Throwable?, ) : CustomerSheetState 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 3d0b30b9bf7..dacd090d7c0 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -149,7 +149,6 @@ internal class CustomerSheetViewModel( private val _result = MutableStateFlow(null) val result: StateFlow = _result - private var isGooglePayReadyAndEnabled: Boolean = false private var paymentLauncher: PaymentLauncher? = null private var previouslySelectedPaymentMethod: SupportedPaymentMethod? = null @@ -322,7 +321,6 @@ internal class CustomerSheetViewModel( supportedPaymentMethods.addAll(state.supportedPaymentMethods) originalPaymentSelection = state.paymentSelection - isGooglePayReadyAndEnabled = state.isGooglePayReady paymentMethodMetadata = state.paymentMethodMetadata transitionToInitialScreen( @@ -345,7 +343,7 @@ internal class CustomerSheetViewModel( paymentSelection: PaymentSelection?, cbcEligibility: CardBrandChoiceEligibility, ) { - if (paymentMethods.isEmpty() && !isGooglePayReadyAndEnabled) { + if (paymentMethods.isEmpty() && paymentMethodMetadata?.isGooglePayReady == false) { transitionToAddPaymentMethod( isFirstPaymentMethod = true, cbcEligibility = cbcEligibility, @@ -625,7 +623,7 @@ internal class CustomerSheetViewModel( } } - if (newSavedPaymentMethods.isEmpty() && !isGooglePayReadyAndEnabled) { + if (newSavedPaymentMethods.isEmpty() && paymentMethodMetadata?.isGooglePayReady == false) { transitionToAddPaymentMethod(isFirstPaymentMethod = true) } } @@ -1215,7 +1213,7 @@ internal class CustomerSheetViewModel( isLiveMode = isLiveModeProvider(), isProcessing = false, isEditing = false, - isGooglePayEnabled = isGooglePayReadyAndEnabled, + isGooglePayEnabled = paymentMethodMetadata?.isGooglePayReady == true, primaryButtonVisible = false, primaryButtonLabel = resources.getString(R.string.stripe_paymentsheet_confirm), errorMessage = null, diff --git a/paymentsheet/src/main/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadata.kt b/paymentsheet/src/main/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadata.kt index d995980b67c..e07042260be 100644 --- a/paymentsheet/src/main/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadata.kt +++ b/paymentsheet/src/main/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadata.kt @@ -37,6 +37,7 @@ internal data class PaymentMethodMetadata( val sharedDataSpecs: List, val externalPaymentMethodSpecs: List, val hasCustomerConfiguration: Boolean, + val isGooglePayReady: Boolean, val financialConnectionsAvailable: Boolean = DefaultIsFinancialConnectionsAvailable(), ) : Parcelable { fun hasIntentToSetup(): Boolean { @@ -194,6 +195,7 @@ internal data class PaymentMethodMetadata( configuration: PaymentSheet.Configuration, sharedDataSpecs: List, externalPaymentMethodSpecs: List, + isGooglePayReady: Boolean, ): PaymentMethodMetadata { return PaymentMethodMetadata( stripeIntent = elementsSession.stripeIntent, @@ -211,7 +213,8 @@ internal data class PaymentMethodMetadata( shippingDetails = configuration.shippingDetails, hasCustomerConfiguration = configuration.customer != null, sharedDataSpecs = sharedDataSpecs, - externalPaymentMethodSpecs = externalPaymentMethodSpecs + externalPaymentMethodSpecs = externalPaymentMethodSpecs, + isGooglePayReady = isGooglePayReady, ) } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt index d738a215847..b932b078c1f 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt @@ -24,7 +24,6 @@ import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen.AddFirstPaymentMethod import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen.SelectSavedPaymentMethods import com.stripe.android.paymentsheet.repositories.CustomerRepository -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.paymentsheet.state.WalletsProcessingState import com.stripe.android.paymentsheet.state.WalletsState import com.stripe.android.paymentsheet.ui.DefaultAddPaymentMethodInteractor @@ -99,12 +98,12 @@ internal class PaymentOptionsViewModel @Inject constructor( linkConfigurationCoordinator.emailFlow, buttonsEnabled, paymentMethodMetadata.mapAsStateFlow { it?.supportedPaymentMethodTypes().orEmpty() }, - googlePayState, - ) { isLinkAvailable, linkEmail, buttonsEnabled, paymentMethodTypes, googlePayState -> + paymentMethodMetadata.mapAsStateFlow { it?.isGooglePayReady == true }, + ) { isLinkAvailable, linkEmail, buttonsEnabled, paymentMethodTypes, isGooglePayReady -> WalletsState.create( isLinkAvailable = isLinkAvailable, linkEmail = linkEmail, - googlePayState = googlePayState, + isGooglePayReady = isGooglePayReady, buttonsEnabled = buttonsEnabled, paymentMethodTypes = paymentMethodTypes, googlePayLauncherConfig = null, @@ -138,14 +137,6 @@ internal class PaymentOptionsViewModel @Inject constructor( init { SessionSavedStateHandler.attachTo(this, savedStateHandle) - savedStateHandle[SAVE_GOOGLE_PAY_STATE] = if (args.state.isGooglePayReady) { - GooglePayState.Available - } else { - GooglePayState.NotAvailable - } - - val linkState = args.state.linkState - viewModelScope.launch { linkHandler.processingState.collect { processingState -> handleLinkProcessingState(processingState) @@ -155,7 +146,7 @@ internal class PaymentOptionsViewModel @Inject constructor( // This is bad, but I don't think there's a better option PaymentSheet.FlowController.linkHandler = linkHandler - linkHandler.setupLink(linkState) + linkHandler.setupLink(args.state.linkState) // After recovering from don't keep activities the paymentMethodMetadata will be saved, // calling setPaymentMethodMetadata would require the repository be initialized, which diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt index aff53d23e1d..b6e7941ba5b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt @@ -55,7 +55,6 @@ import com.stripe.android.paymentsheet.paymentdatacollection.bacs.BacsMandateCon import com.stripe.android.paymentsheet.paymentdatacollection.bacs.BacsMandateConfirmationResult import com.stripe.android.paymentsheet.paymentdatacollection.bacs.BacsMandateData import com.stripe.android.paymentsheet.repositories.CustomerRepository -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.paymentsheet.state.PaymentSheetLoader import com.stripe.android.paymentsheet.state.PaymentSheetState import com.stripe.android.paymentsheet.state.WalletsProcessingState @@ -218,14 +217,14 @@ internal class PaymentSheetViewModel @Inject internal constructor( override val walletsState: StateFlow = combineAsStateFlow( linkHandler.isLinkEnabled, linkConfigurationCoordinator.emailFlow, - googlePayState, + paymentMethodMetadata.mapAsStateFlow { it?.isGooglePayReady == true }, buttonsEnabled, paymentMethodMetadata.mapAsStateFlow { it?.supportedPaymentMethodTypes().orEmpty() }, - ) { isLinkAvailable, linkEmail, googlePayState, buttonsEnabled, paymentMethodTypes -> + ) { isLinkAvailable, linkEmail, isGooglePayReady, buttonsEnabled, paymentMethodTypes -> WalletsState.create( isLinkAvailable = isLinkAvailable, linkEmail = linkEmail, - googlePayState = googlePayState, + isGooglePayReady = isGooglePayReady, buttonsEnabled = buttonsEnabled, paymentMethodTypes = paymentMethodTypes, googlePayLauncherConfig = googlePayLauncherConfig, @@ -373,17 +372,9 @@ internal class PaymentSheetViewModel @Inject internal constructor( updateSelection(state.paymentSelection) - savedStateHandle[SAVE_GOOGLE_PAY_STATE] = if (state.isGooglePayReady) { - GooglePayState.Available - } else { - GooglePayState.NotAvailable - } - setPaymentMethodMetadata(state.paymentMethodMetadata) - val linkState = state.linkState - - linkHandler.setupLink(linkState) + linkHandler.setupLink(state.linkState) val pendingFailedPaymentResult = awaitPaymentResult() as? InternalPaymentResult.Failed val errorMessage = pendingFailedPaymentResult?.throwable?.stripeErrorMessage() 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 13b11430e99..61bcd17e6f9 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutator.kt @@ -12,7 +12,6 @@ import com.stripe.android.paymentsheet.navigation.NavigationHandler import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen import com.stripe.android.paymentsheet.repositories.CustomerRepository import com.stripe.android.paymentsheet.state.CustomerState -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.paymentsheet.ui.DefaultAddPaymentMethodInteractor import com.stripe.android.paymentsheet.ui.EditPaymentMethodViewInteractor import com.stripe.android.paymentsheet.ui.ModifiableEditPaymentMethodViewInteractor @@ -43,7 +42,7 @@ internal class SavedPaymentMethodMutator( private val updateSelection: (PaymentSelection?) -> Unit, private val isLiveModeProvider: () -> Boolean, isCbcEligible: () -> Boolean, - googlePayState: StateFlow, + isGooglePayReady: StateFlow, isLinkEnabled: StateFlow, isNotPaymentFlow: Boolean, ) { @@ -66,7 +65,7 @@ internal class SavedPaymentMethodMutator( private val paymentOptionsItemsMapper: PaymentOptionsItemsMapper by lazy { PaymentOptionsItemsMapper( paymentMethods = paymentMethods, - googlePayState = googlePayState, + isGooglePayReady = isGooglePayReady, isLinkEnabled = isLinkEnabled, isNotPaymentFlow = isNotPaymentFlow, nameProvider = providePaymentMethodName, @@ -297,7 +296,7 @@ internal class SavedPaymentMethodMutator( isCbcEligible = { viewModel.paymentMethodMetadata.value?.cbcEligibility is CardBrandChoiceEligibility.Eligible }, - googlePayState = viewModel.googlePayState, + isGooglePayReady = viewModel.paymentMethodMetadata.mapAsStateFlow { it?.isGooglePayReady == true }, isLinkEnabled = viewModel.linkHandler.isLinkEnabled, isNotPaymentFlow = !viewModel.isCompleteFlow, isLiveModeProvider = { requireNotNull(viewModel.paymentMethodMetadata.value).stripeIntent.isLiveMode } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdater.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdater.kt index d07909d7262..dbe29688ffb 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdater.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdater.kt @@ -51,7 +51,7 @@ internal class DefaultPaymentSelectionUpdater @Inject constructor() : PaymentSel code in allowedTypes && paymentMethod in (state.customer?.paymentMethods ?: emptyList()) } is PaymentSelection.GooglePay -> { - state.isGooglePayReady + state.paymentMethodMetadata.isGooglePayReady } is PaymentSelection.Link -> { state.linkState != null diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/GooglePayState.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/GooglePayState.kt deleted file mode 100644 index 2ccc9fb0e07..00000000000 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/GooglePayState.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.stripe.android.paymentsheet.state - -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -@Parcelize -internal sealed class GooglePayState( - val isReadyForUse: Boolean -) : Parcelable { - @Parcelize - object Available : GooglePayState(true) - - @Parcelize - object NotAvailable : GooglePayState(false) - - @Parcelize - object Indeterminate : GooglePayState(false) -} diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetLoader.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetLoader.kt index 5e241db3a36..a91c74ec570 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetLoader.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetLoader.kt @@ -96,19 +96,18 @@ internal class DefaultPaymentSheetLoader @Inject constructor( defaultPaymentMethodId = savedPaymentMethodSelection?.id, ).getOrThrow() + val isGooglePayReady = isGooglePayReady(paymentSheetConfiguration, elementsSession) + val metadata = createPaymentMethodMetadata( paymentSheetConfiguration = paymentSheetConfiguration, elementsSession = elementsSession, + isGooglePayReady = isGooglePayReady ) - val isGooglePayReady = async { - isGooglePayReady(paymentSheetConfiguration, elementsSession) - } - val savedSelection = async { retrieveSavedSelection( config = paymentSheetConfiguration, - isGooglePayReady = isGooglePayReady.await(), + isGooglePayReady = isGooglePayReady, elementsSession = elementsSession ) } @@ -147,9 +146,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( val state = PaymentSheetState.Full( config = paymentSheetConfiguration, customer = customer.await(), - isGooglePayReady = isGooglePayReady.await(), linkState = linkState.await(), - isEligibleForCardBrandChoice = elementsSession.isEligibleForCardBrandChoice, paymentSelection = initialPaymentSelection.await(), validationError = stripeIntent.validate(), paymentMethodMetadata = metadata, @@ -182,6 +179,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( private fun createPaymentMethodMetadata( paymentSheetConfiguration: PaymentSheet.Configuration, elementsSession: ElementsSession, + isGooglePayReady: Boolean, ): PaymentMethodMetadata { val sharedDataSpecsResult = lpmRepository.getSharedDataSpecs( stripeIntent = elementsSession.stripeIntent, @@ -205,7 +203,8 @@ internal class DefaultPaymentSheetLoader @Inject constructor( elementsSession = elementsSession, configuration = paymentSheetConfiguration, sharedDataSpecs = sharedDataSpecsResult.sharedDataSpecs, - externalPaymentMethodSpecs = externalPaymentMethodSpecs + externalPaymentMethodSpecs = externalPaymentMethodSpecs, + isGooglePayReady = isGooglePayReady, ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetState.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetState.kt index 92cd574def3..69da4e03980 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetState.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentSheetState.kt @@ -16,15 +16,13 @@ internal sealed interface PaymentSheetState : Parcelable { data class Full( val config: PaymentSheet.Configuration, val customer: CustomerState?, - val isGooglePayReady: Boolean, val linkState: LinkState?, - val isEligibleForCardBrandChoice: Boolean, val paymentSelection: PaymentSelection?, val validationError: PaymentSheetLoadingException?, val paymentMethodMetadata: PaymentMethodMetadata, ) : PaymentSheetState { val showSavedPaymentMethods: Boolean - get() = (customer != null && customer.paymentMethods.isNotEmpty()) || isGooglePayReady + get() = (customer != null && customer.paymentMethods.isNotEmpty()) || paymentMethodMetadata.isGooglePayReady val stripeIntent: StripeIntent get() = paymentMethodMetadata.stripeIntent diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/WalletsState.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/WalletsState.kt index eb4522bcd4d..8e1ed551295 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/WalletsState.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/WalletsState.kt @@ -32,7 +32,7 @@ internal data class WalletsState( fun create( isLinkAvailable: Boolean?, linkEmail: String?, - googlePayState: GooglePayState, + isGooglePayReady: Boolean, googlePayButtonType: GooglePayButtonType, buttonsEnabled: Boolean, paymentMethodTypes: List, @@ -60,7 +60,7 @@ internal data class WalletsState( isPhoneNumberRequired = it.billingAddressConfig.isPhoneNumberRequired, ) }, - ).takeIf { googlePayState.isReadyForUse } + ).takeIf { isGooglePayReady } return if (link != null || googlePay != null) { WalletsState( 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 e796bfda784..d573be17da5 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 @@ -21,7 +21,6 @@ import com.stripe.android.paymentsheet.analytics.PaymentSheetAnalyticsListener import com.stripe.android.paymentsheet.model.PaymentSelection import com.stripe.android.paymentsheet.navigation.NavigationHandler import com.stripe.android.paymentsheet.repositories.CustomerRepository -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.paymentsheet.state.WalletsProcessingState import com.stripe.android.paymentsheet.state.WalletsState import com.stripe.android.paymentsheet.ui.ModifiableEditPaymentMethodViewInteractor @@ -53,9 +52,6 @@ internal abstract class BaseSheetViewModel( val editInteractorFactory: ModifiableEditPaymentMethodViewInteractor.Factory, val isCompleteFlow: Boolean, ) : AndroidViewModel(application) { - internal val googlePayState: StateFlow = savedStateHandle - .getStateFlow(SAVE_GOOGLE_PAY_STATE, GooglePayState.Indeterminate) - private val _paymentMethodMetadata = MutableStateFlow(null) internal val paymentMethodMetadata: StateFlow = _paymentMethodMetadata @@ -219,6 +215,5 @@ internal abstract class BaseSheetViewModel( companion object { internal const val SAVE_SELECTION = "selection" internal const val SAVE_PROCESSING = "processing" - internal const val SAVE_GOOGLE_PAY_STATE = "google_pay_state" } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapper.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapper.kt index 4392232bf0d..bf555dfca9b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapper.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapper.kt @@ -4,13 +4,12 @@ import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodCode import com.stripe.android.paymentsheet.PaymentOptionsItem import com.stripe.android.paymentsheet.PaymentOptionsStateFactory -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.uicore.utils.combineAsStateFlow import kotlinx.coroutines.flow.StateFlow internal class PaymentOptionsItemsMapper( private val paymentMethods: StateFlow>, - private val googlePayState: StateFlow, + private val isGooglePayReady: StateFlow, private val isLinkEnabled: StateFlow, private val nameProvider: (PaymentMethodCode?) -> String, private val isNotPaymentFlow: Boolean, @@ -21,14 +20,14 @@ internal class PaymentOptionsItemsMapper( return combineAsStateFlow( paymentMethods, isLinkEnabled, - googlePayState, - ) { paymentMethods, isLinkEnabled, googlePayState -> + isGooglePayReady, + ) { paymentMethods, isLinkEnabled, isGooglePayReady -> createPaymentOptionsItems( paymentMethods = paymentMethods, isLinkEnabled = isLinkEnabled, // TODO(samer-stripe): Set this based on customer_session permissions canRemovePaymentMethods = true, - googlePayState = googlePayState, + isGooglePayReady = isGooglePayReady, ) ?: emptyList() } } @@ -38,13 +37,13 @@ internal class PaymentOptionsItemsMapper( paymentMethods: List, isLinkEnabled: Boolean?, canRemovePaymentMethods: Boolean?, - googlePayState: GooglePayState, + isGooglePayReady: Boolean, ): List? { if (isLinkEnabled == null) return null return PaymentOptionsStateFactory.createPaymentOptionsList( paymentMethods = paymentMethods, - showGooglePay = (googlePayState is GooglePayState.Available) && isNotPaymentFlow, + showGooglePay = isGooglePayReady && isNotPaymentFlow, showLink = isLinkEnabled && isNotPaymentFlow, nameProvider = nameProvider, isCbcEligible = isCbcEligible(), diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt index 3fae447841a..466ede6b277 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt @@ -559,6 +559,7 @@ class CustomerSheetViewModelTest { fun `When removing last payment method & google pay disabled, should transition to add payment screen`() = runTest(testDispatcher) { val viewModel = createViewModel( workContext = testDispatcher, + isGooglePayAvailable = false, customerSheetLoader = FakeCustomerSheetLoader( isGooglePayAvailable = false, customerPaymentMethods = listOf(CARD_PAYMENT_METHOD), @@ -2642,6 +2643,7 @@ class CustomerSheetViewModelTest { val viewModel = createViewModel( workContext = testDispatcher, + isGooglePayAvailable = false, initialBackStack = listOf( selectPaymentMethodViewState.copy( savedPaymentMethods = paymentMethods, diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/state/DefaultCustomerSheetLoaderTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/state/DefaultCustomerSheetLoaderTest.kt index 830c82ebe84..677aff2d540 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/state/DefaultCustomerSheetLoaderTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/state/DefaultCustomerSheetLoaderTest.kt @@ -100,12 +100,12 @@ class DefaultCustomerSheetLoaderTest { assertThat(state.paymentMethodMetadata.stripeIntent).isEqualTo(STRIPE_INTENT) assertThat(state.paymentMethodMetadata.cbcEligibility).isEqualTo(CardBrandChoiceEligibility.Ineligible) assertThat(state.paymentMethodMetadata.hasCustomerConfiguration).isTrue() + assertThat(state.paymentMethodMetadata.isGooglePayReady).isTrue() assertThat(state.customerPaymentMethods).containsExactly( PaymentMethodFixtures.CARD_PAYMENT_METHOD, PaymentMethodFixtures.US_BANK_ACCOUNT, ) assertThat(state.supportedPaymentMethods.map { it.code }).containsExactly("card") - assertThat(state.isGooglePayReady).isTrue() assertThat(state.paymentSelection).isEqualTo( PaymentSelection.Saved( paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, @@ -152,12 +152,12 @@ class DefaultCustomerSheetLoaderTest { val state = loader.load(config).getOrThrow() assertThat(state.config).isEqualTo(config) assertThat(state.paymentMethodMetadata.stripeIntent).isEqualTo(STRIPE_INTENT) + assertThat(state.paymentMethodMetadata.isGooglePayReady).isTrue() assertThat(state.customerPaymentMethods).containsExactly( PaymentMethodFixtures.CARD_PAYMENT_METHOD, PaymentMethodFixtures.US_BANK_ACCOUNT, ) assertThat(state.supportedPaymentMethods.map { it.code }).containsExactly("card") - assertThat(state.isGooglePayReady).isTrue() assertThat(state.paymentSelection).isEqualTo( PaymentSelection.Saved( paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, @@ -190,11 +190,11 @@ class DefaultCustomerSheetLoaderTest { val state = loader.load(config).getOrThrow() assertThat(state.config).isEqualTo(config) assertThat(state.paymentMethodMetadata).isNotNull() + assertThat(state.paymentMethodMetadata.isGooglePayReady).isFalse() assertThat(state.customerPaymentMethods).containsExactly( PaymentMethodFixtures.CARD_PAYMENT_METHOD, ) assertThat(state.supportedPaymentMethods.map { it.code }).containsExactly("card") - assertThat(state.isGooglePayReady).isFalse() assertThat(state.paymentSelection).isNull() assertThat(state.paymentMethodMetadata.cbcEligibility).isEqualTo(CardBrandChoiceEligibility.Ineligible) assertThat(state.validationError).isNull() @@ -289,13 +289,13 @@ class DefaultCustomerSheetLoaderTest { val state = loader.load(config).getOrThrow() assertThat(state.config).isEqualTo(config) assertThat(state.paymentMethodMetadata.stripeIntent).isEqualTo(STRIPE_INTENT) + assertThat(state.paymentMethodMetadata.isGooglePayReady).isFalse() assertThat(state.customerPaymentMethods).containsExactly( PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_3"), PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_1"), PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_2"), ) assertThat(state.supportedPaymentMethods.map { it.code }).containsExactly("card") - assertThat(state.isGooglePayReady).isFalse() assertThat(state.paymentSelection).isEqualTo( PaymentSelection.Saved( paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_3"), @@ -325,13 +325,13 @@ class DefaultCustomerSheetLoaderTest { val state = loader.load(config).getOrThrow() assertThat(state.config).isEqualTo(config) assertThat(state.paymentMethodMetadata.stripeIntent).isEqualTo(STRIPE_INTENT) + assertThat(state.paymentMethodMetadata.isGooglePayReady).isFalse() assertThat(state.customerPaymentMethods).containsExactly( PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_1"), PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_2"), PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(id = "pm_3"), ) assertThat(state.supportedPaymentMethods.map { it.code }).containsExactly("card") - assertThat(state.isGooglePayReady).isFalse() assertThat(state.paymentSelection).isNull() assertThat(state.paymentMethodMetadata.cbcEligibility).isEqualTo(CardBrandChoiceEligibility.Ineligible) assertThat(state.validationError).isNull() diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/CustomerSheetTestHelper.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/CustomerSheetTestHelper.kt index f250a5746cd..238de2fb523 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/CustomerSheetTestHelper.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/CustomerSheetTestHelper.kt @@ -190,7 +190,9 @@ internal object CustomerSheetTestHelper { ).apply { registerFromActivity(DummyActivityResultCaller(), TestLifecycleOwner()) - paymentMethodMetadata = PaymentMethodMetadataFactory.create() + paymentMethodMetadata = PaymentMethodMetadataFactory.create( + isGooglePayReady = isGooglePayAvailable, + ) } } diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/FakeCustomerSheetLoader.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/FakeCustomerSheetLoader.kt index 0cae6b07f7f..fd3e9c506a2 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/FakeCustomerSheetLoader.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/utils/FakeCustomerSheetLoader.kt @@ -43,11 +43,11 @@ internal class FakeCustomerSheetLoader( stripeIntent = stripeIntent, cbcEligibility = cbcEligibility, financialConnectionsAvailable = financialConnectionsAvailable, - paymentMethodOrder = configuration.paymentMethodOrder + paymentMethodOrder = configuration.paymentMethodOrder, + isGooglePayReady = isGooglePayAvailable, ), supportedPaymentMethods = supportedPaymentMethods, customerPaymentMethods = customerPaymentMethods, - isGooglePayReady = isGooglePayAvailable, paymentSelection = paymentSelection, validationError = null, ) diff --git a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataFactory.kt b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataFactory.kt index 83d18883097..c1146b07a73 100644 --- a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataFactory.kt +++ b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataFactory.kt @@ -23,7 +23,8 @@ internal object PaymentMethodMetadataFactory { cbcEligibility: CardBrandChoiceEligibility = CardBrandChoiceEligibility.Ineligible, hasCustomerConfiguration: Boolean = false, sharedDataSpecs: List = createSharedDataSpecs(), - externalPaymentMethodSpecs: List = emptyList() + externalPaymentMethodSpecs: List = emptyList(), + isGooglePayReady: Boolean = false, ): PaymentMethodMetadata { return PaymentMethodMetadata( stripeIntent = stripeIntent, @@ -39,6 +40,7 @@ internal object PaymentMethodMetadataFactory { hasCustomerConfiguration = hasCustomerConfiguration, sharedDataSpecs = sharedDataSpecs, externalPaymentMethodSpecs = externalPaymentMethodSpecs, + isGooglePayReady = isGooglePayReady, ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt index c02a853293f..9ca9d0d58d8 100644 --- a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt @@ -751,6 +751,7 @@ internal class PaymentMethodMetadataTest { ), sharedDataSpecs = listOf(SharedDataSpec("card")), externalPaymentMethodSpecs = listOf(PaymentMethodFixtures.PAYPAL_EXTERNAL_PAYMENT_METHOD_SPEC), + isGooglePayReady = false, ) assertThat(metadata).isEqualTo( @@ -769,6 +770,7 @@ internal class PaymentMethodMetadataTest { sharedDataSpecs = listOf(SharedDataSpec("card")), externalPaymentMethodSpecs = listOf(PaymentMethodFixtures.PAYPAL_EXTERNAL_PAYMENT_METHOD_SPEC), hasCustomerConfiguration = true, + isGooglePayReady = false, ) ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt index bf9198a7daa..0288518fc4e 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt @@ -631,7 +631,6 @@ internal class PaymentOptionsViewModelTest { config = PAYMENT_OPTION_CONTRACT_ARGS.state.config.copy( allowsDelayedPaymentMethods = false, ), - isGooglePayReady = false, paymentMethodMetadata = PaymentMethodMetadataFactory.create( stripeIntent = PAYMENT_INTENT.copy( paymentMethodTypes = listOf( @@ -901,12 +900,13 @@ internal class PaymentOptionsViewModelTest { state = PaymentSheetState.Full( customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE, config = PaymentSheetFixtures.CONFIG_CUSTOMER_WITH_GOOGLEPAY, - isGooglePayReady = true, paymentSelection = null, linkState = null, - isEligibleForCardBrandChoice = false, validationError = null, - paymentMethodMetadata = PaymentMethodMetadataFactory.create(stripeIntent = PAYMENT_INTENT), + paymentMethodMetadata = PaymentMethodMetadataFactory.create( + stripeIntent = PAYMENT_INTENT, + isGooglePayReady = true, + ), ), statusBarColor = PaymentSheetFixtures.STATUS_BAR_COLOR, enableLogging = false, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt index a90700c984c..fc1ff8bf916 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt @@ -127,10 +127,8 @@ internal object PaymentSheetFixtures { state = PaymentSheetState.Full( customer = EMPTY_CUSTOMER_STATE, config = CONFIG_GOOGLEPAY, - isGooglePayReady = false, paymentSelection = null, linkState = null, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create(), ), @@ -141,7 +139,7 @@ internal object PaymentSheetFixtures { internal fun PaymentOptionContract.Args.updateState( paymentMethods: List = state.customer?.paymentMethods ?: emptyList(), - isGooglePayReady: Boolean = state.isGooglePayReady, + isGooglePayReady: Boolean = state.paymentMethodMetadata.isGooglePayReady, stripeIntent: StripeIntent = state.stripeIntent, config: PaymentSheet.Configuration = state.config, paymentSelection: PaymentSelection? = state.paymentSelection, @@ -158,11 +156,13 @@ internal object PaymentSheetFixtures { canRemoveDuplicates = false, ) ), - isGooglePayReady = isGooglePayReady, config = config, paymentSelection = paymentSelection, linkState = linkState, - paymentMethodMetadata = PaymentMethodMetadataFactory.create(stripeIntent = stripeIntent) + paymentMethodMetadata = PaymentMethodMetadataFactory.create( + stripeIntent = stripeIntent, + isGooglePayReady = isGooglePayReady, + ), ), ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt index d3f59a3d336..d2db5ad558f 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt @@ -81,7 +81,6 @@ import com.stripe.android.paymentsheet.paymentdatacollection.bacs.BacsMandateCon import com.stripe.android.paymentsheet.paymentdatacollection.bacs.BacsMandateData import com.stripe.android.paymentsheet.repositories.CustomerRepository import com.stripe.android.paymentsheet.state.CustomerState -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.paymentsheet.state.LinkState import com.stripe.android.paymentsheet.state.PaymentSheetLoader import com.stripe.android.paymentsheet.state.PaymentSheetLoadingException @@ -1200,16 +1199,16 @@ internal class PaymentSheetViewModelTest { @Test fun `Google Pay is not available if it's not ready`() = runTest { val viewModel = createViewModel(isGooglePayReady = false) - viewModel.googlePayState.test { - assertThat(awaitItem()).isEqualTo(GooglePayState.NotAvailable) + viewModel.paymentMethodMetadata.test { + assertThat(awaitItem()?.isGooglePayReady).isFalse() } } @Test fun `Google Pay is available if it is ready`() = runTest { val viewModel = createViewModel(isGooglePayReady = true) - viewModel.googlePayState.test { - assertThat(awaitItem()).isEqualTo(GooglePayState.Available) + viewModel.paymentMethodMetadata.test { + assertThat(awaitItem()?.isGooglePayReady).isTrue() } } 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 1db2d6dc11f..28579b9a77a 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/SavedPaymentMethodMutatorTest.kt @@ -5,7 +5,6 @@ import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import com.stripe.android.model.PaymentMethodFixtures import com.stripe.android.paymentsheet.state.CustomerState -import com.stripe.android.paymentsheet.state.GooglePayState import com.stripe.android.uicore.utils.stateFlowOf import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -150,7 +149,7 @@ class SavedPaymentMethodMutatorTest { addFirstPaymentMethodScreenFactory = { throw AssertionError("Not implemented") }, updateSelection = { throw AssertionError("Not implemented") }, isCbcEligible = isCbcEligible, - googlePayState = stateFlowOf(GooglePayState.NotAvailable), + isGooglePayReady = stateFlowOf(false), isLinkEnabled = stateFlowOf(false), isNotPaymentFlow = true, isLiveModeProvider = { true }, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt index d7c7a7ca96a..c9f5cc6a53e 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt @@ -431,10 +431,8 @@ internal class DefaultFlowControllerTest { state = PaymentSheetState.Full( customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE, config = PaymentSheet.Configuration("com.stripe.android.paymentsheet.test"), - isGooglePayReady = false, paymentSelection = null, linkState = null, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create(allowsDelayedPaymentMethods = false), ), @@ -646,10 +644,8 @@ internal class DefaultFlowControllerTest { customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE.copy( paymentMethods = PAYMENT_METHODS ), - isGooglePayReady = false, linkState = null, paymentSelection = initialSelection, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create(), ) @@ -687,10 +683,8 @@ internal class DefaultFlowControllerTest { customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE.copy( paymentMethods = PAYMENT_METHODS ), - isGooglePayReady = false, linkState = null, paymentSelection = initialSelection, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create(), ) @@ -731,10 +725,8 @@ internal class DefaultFlowControllerTest { customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE.copy( paymentMethods = PAYMENT_METHODS ), - isGooglePayReady = false, linkState = null, paymentSelection = initialSelection, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create(), ) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdaterTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdaterTest.kt index d51e2bf7729..62a74e9f329 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdaterTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/PaymentSelectionUpdaterTest.kt @@ -344,10 +344,8 @@ class PaymentSelectionUpdaterTest { customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE.copy( paymentMethods = customerPaymentMethods ), - isGooglePayReady = true, linkState = null, paymentSelection = paymentSelection, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create( stripeIntent = intent.copy( @@ -359,6 +357,7 @@ class PaymentSelectionUpdaterTest { SharedDataSpec("sofort"), ), externalPaymentMethodSpecs = externalPaymentMethodSpecs, + isGooglePayReady = true, ), ) } @@ -376,15 +375,14 @@ class PaymentSelectionUpdaterTest { customer = PaymentSheetFixtures.EMPTY_CUSTOMER_STATE.copy( paymentMethods = customerPaymentMethods ), - isGooglePayReady = true, linkState = null, paymentSelection = paymentSelection, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create( stripeIntent = intent.copy( paymentMethodTypes = paymentMethodTypes ?: intent.paymentMethodTypes, - ) + ), + isGooglePayReady = true, ), ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentSheetLoaderTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentSheetLoaderTest.kt index 0e476b1a83e..9b0b9d11ccd 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentSheetLoaderTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentSheetLoaderTest.kt @@ -36,6 +36,7 @@ import com.stripe.android.paymentsheet.state.PaymentSheetLoadingException.Paymen import com.stripe.android.paymentsheet.utils.FakeUserFacingLogger import com.stripe.android.testing.FakeErrorReporter import com.stripe.android.testing.PaymentMethodFactory +import com.stripe.android.ui.core.cbc.CardBrandChoiceEligibility import com.stripe.android.ui.core.elements.ExternalPaymentMethodsRepository import com.stripe.android.utils.FakeCustomerRepository import com.stripe.android.utils.FakeElementsSessionRepository @@ -121,18 +122,17 @@ internal class DefaultPaymentSheetLoaderTest { canRemoveDuplicates = false, ), ), - isGooglePayReady = true, paymentSelection = PaymentSelection.Saved( paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, ), linkState = null, - isEligibleForCardBrandChoice = false, validationError = null, paymentMethodMetadata = PaymentMethodMetadataFactory.create( stripeIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD_WITHOUT_LINK, allowsDelayedPaymentMethods = false, sharedDataSpecs = emptyList(), hasCustomerConfiguration = true, + isGooglePayReady = true, ), ) ) @@ -173,7 +173,7 @@ internal class DefaultPaymentSheetLoaderTest { ), PaymentSheetFixtures.CONFIG_CUSTOMER_WITH_GOOGLEPAY, initializedViaCompose = false, - ).getOrThrow().isGooglePayReady + ).getOrThrow().paymentMethodMetadata.isGooglePayReady ).isFalse() } @@ -970,7 +970,8 @@ internal class DefaultPaymentSheetLoaderTest { initializedViaCompose = false, ).getOrThrow() - assertThat(result.isEligibleForCardBrandChoice).isTrue() + assertThat(result.paymentMethodMetadata.cbcEligibility) + .isEqualTo(CardBrandChoiceEligibility.Eligible(listOf())) } @Test diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapperTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapperTest.kt index af4203ad2d5..b8b6f6743a8 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapperTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PaymentOptionsItemsMapperTest.kt @@ -6,7 +6,6 @@ import com.google.common.truth.Truth.assertThat import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodFixtures import com.stripe.android.paymentsheet.PaymentOptionsItem -import com.stripe.android.paymentsheet.state.GooglePayState import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.runTest import org.junit.Rule @@ -18,14 +17,14 @@ class PaymentOptionsItemsMapperTest { val instantTaskExecutorRule = InstantTaskExecutorRule() private val paymentMethodsFlow = MutableStateFlow>(emptyList()) - private val googlePayStateFlow = MutableStateFlow(GooglePayState.Indeterminate) + private val isGooglePayReadyFlow = MutableStateFlow(false) private val isLinkEnabledFlow = MutableStateFlow(null) @Test fun `Only emits value if required flows have emitted values`() = runTest { val mapper = PaymentOptionsItemsMapper( paymentMethods = paymentMethodsFlow, - googlePayState = googlePayStateFlow, + isGooglePayReady = isGooglePayReadyFlow, isLinkEnabled = isLinkEnabledFlow, isNotPaymentFlow = true, nameProvider = { it!! }, @@ -36,7 +35,7 @@ class PaymentOptionsItemsMapperTest { assertThat(awaitItem()).isEqualTo(emptyList()) paymentMethodsFlow.value = PaymentMethodFixtures.createCards(2) - googlePayStateFlow.value = GooglePayState.Available + isGooglePayReadyFlow.value = true isLinkEnabledFlow.value = true val state = awaitItem() @@ -53,7 +52,7 @@ class PaymentOptionsItemsMapperTest { fun `Doesn't include Google Pay and Link in payment flow`() = runTest { val mapper = PaymentOptionsItemsMapper( paymentMethods = paymentMethodsFlow, - googlePayState = googlePayStateFlow, + isGooglePayReady = isGooglePayReadyFlow, isLinkEnabled = isLinkEnabledFlow, isNotPaymentFlow = false, nameProvider = { it!! }, @@ -65,7 +64,7 @@ class PaymentOptionsItemsMapperTest { val cards = PaymentMethodFixtures.createCards(2) paymentMethodsFlow.value = cards - googlePayStateFlow.value = GooglePayState.Available + isGooglePayReadyFlow.value = true isLinkEnabledFlow.value = true assertThat(awaitItem()).containsNoneOf( diff --git a/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt b/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt index c66ec505b14..07163eee4bb 100644 --- a/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt +++ b/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt @@ -48,10 +48,8 @@ internal class FakePaymentSheetLoader( PaymentSheetState.Full( config = paymentSheetConfiguration, customer = customer, - isGooglePayReady = isGooglePayAvailable, linkState = linkState, paymentSelection = paymentSelection, - isEligibleForCardBrandChoice = false, validationError = validationError, paymentMethodMetadata = PaymentMethodMetadataFactory.create( stripeIntent = stripeIntent, @@ -60,6 +58,7 @@ internal class FakePaymentSheetLoader( allowsDelayedPaymentMethods = paymentSheetConfiguration.allowsDelayedPaymentMethods, allowsPaymentMethodsRequiringShippingAddress = paymentSheetConfiguration .allowsPaymentMethodsRequiringShippingAddress, + isGooglePayReady = isGooglePayAvailable, ), ) ) diff --git a/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt b/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt index fd11b2d8265..0a41f32000b 100644 --- a/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt +++ b/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt @@ -22,10 +22,8 @@ internal class RelayingPaymentSheetLoader : PaymentSheetLoader { PaymentSheetState.Full( customer = null, config = PaymentSheet.Configuration("Example"), - isGooglePayReady = false, paymentSelection = null, linkState = null, - isEligibleForCardBrandChoice = false, validationError = validationError, paymentMethodMetadata = PaymentMethodMetadataFactory.create(stripeIntent = stripeIntent), ),