diff --git a/payments-core/src/test/java/com/stripe/android/PaymentConfigurationTest.kt b/payments-core/src/test/java/com/stripe/android/PaymentConfigurationTest.kt index e7acf1be2d7..48dc2ad8162 100644 --- a/payments-core/src/test/java/com/stripe/android/PaymentConfigurationTest.kt +++ b/payments-core/src/test/java/com/stripe/android/PaymentConfigurationTest.kt @@ -71,4 +71,15 @@ class PaymentConfigurationTest { assertThat(ParcelUtils.create(paymentConfig)) .isEqualTo(paymentConfig) } + + @Test + fun `isLiveMode is true when publishable key is live`() { + assertThat(PaymentConfiguration(publishableKey = "pk_test_123").isLiveMode()).isFalse() + assertThat(PaymentConfiguration(publishableKey = "pk_live_123").isLiveMode()).isTrue() + assertThat( + PaymentConfiguration( + publishableKey = "pk_test_51HvTI7Lu5o3livep6t5AgBSkMvWoTtA0nyA7pV" + ).isLiveMode() + ).isFalse() + } } diff --git a/paymentsheet/src/main/java/com/stripe/android/common/model/CommonConfiguration.kt b/paymentsheet/src/main/java/com/stripe/android/common/model/CommonConfiguration.kt index 29afbba5be1..7dc70c51f15 100644 --- a/paymentsheet/src/main/java/com/stripe/android/common/model/CommonConfiguration.kt +++ b/paymentsheet/src/main/java/com/stripe/android/common/model/CommonConfiguration.kt @@ -42,10 +42,10 @@ internal data class CommonConfiguration( val appearance: PaymentSheet.Appearance, ) : Parcelable { - fun validate(isLiveMode: Boolean, @PaymentElementCallbackIdentifier callbackIdentifier: String) { + fun validate(@PaymentElementCallbackIdentifier callbackIdentifier: String) { customerAndMerchantValidate() - externalPaymentMethodsValidate(isLiveMode) - confirmationTokenValidate(isLiveMode, callbackIdentifier) + externalPaymentMethodsValidate() + confirmationTokenValidate(callbackIdentifier) customer?.accessType?.let { customerAccessType -> customerAccessTypeValidate(customerAccessType) @@ -73,9 +73,9 @@ internal data class CommonConfiguration( // These exception messages are not localized as they are not intended to be displayed to a user. @Suppress("ThrowsCount") - private fun externalPaymentMethodsValidate(isLiveMode: Boolean) { + private fun externalPaymentMethodsValidate() { externalPaymentMethods.forEach { externalPaymentMethod -> - if (!externalPaymentMethod.startsWith("external_") && isLiveMode.not()) { + if (!externalPaymentMethod.startsWith("external_")) { throw IllegalArgumentException( "External payment method '$externalPaymentMethod' does not start with 'external_'. " + "All external payment methods must use the 'external_' prefix. " + @@ -89,13 +89,11 @@ internal data class CommonConfiguration( // These exception messages are not localized as they are not intended to be displayed to a user. @Suppress("ThrowsCount") private fun confirmationTokenValidate( - isLiveMode: Boolean, @PaymentElementCallbackIdentifier callbackIdentifier: String ) { if ( PaymentElementCallbackReferences[callbackIdentifier]?.createIntentWithConfirmationTokenCallback != null && - customer?.accessType is PaymentSheet.CustomerAccessType.LegacyCustomerEphemeralKey && - isLiveMode.not() + customer?.accessType is PaymentSheet.CustomerAccessType.LegacyCustomerEphemeralKey ) { throw IllegalArgumentException( "createIntentWithConfirmationTokenCallback must be used with CustomerSession." 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 af39ed0b72f..f54279aa6b7 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetLoader.kt @@ -5,7 +5,6 @@ import com.stripe.android.common.coroutines.awaitWithTimeout import com.stripe.android.common.validation.isSupportedWithBillingConfig import com.stripe.android.core.exception.StripeException import com.stripe.android.core.injection.IOContext -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.customersheet.analytics.CustomerSheetEventReporter import com.stripe.android.customersheet.data.CustomerSheetInitializationDataSource import com.stripe.android.customersheet.data.CustomerSheetSession @@ -29,7 +28,6 @@ import com.stripe.android.paymentsheet.model.SavedSelection import com.stripe.android.paymentsheet.model.validate import kotlinx.coroutines.flow.first import javax.inject.Inject -import javax.inject.Named import kotlin.coroutines.CoroutineContext import kotlin.time.Duration.Companion.seconds @@ -38,7 +36,6 @@ internal interface CustomerSheetLoader { } internal class DefaultCustomerSheetLoader( - @Named(IS_LIVE_MODE) private val isLiveModeProvider: () -> Boolean, private val googlePayRepositoryFactory: @JvmSuppressWildcards (GooglePayEnvironment) -> GooglePayRepository, private val isFinancialConnectionsAvailable: IsFinancialConnectionsSdkAvailable, private val lpmRepository: LpmRepository, @@ -49,7 +46,6 @@ internal class DefaultCustomerSheetLoader( ) : CustomerSheetLoader { @Inject constructor( - @Named(IS_LIVE_MODE) isLiveModeProvider: () -> Boolean, googlePayRepositoryFactory: @JvmSuppressWildcards (GooglePayEnvironment) -> GooglePayRepository, isFinancialConnectionsAvailable: IsFinancialConnectionsSdkAvailable, lpmRepository: LpmRepository, @@ -57,7 +53,6 @@ internal class DefaultCustomerSheetLoader( errorReporter: ErrorReporter, @IOContext workContext: CoroutineContext ) : this( - isLiveModeProvider = isLiveModeProvider, googlePayRepositoryFactory = googlePayRepositoryFactory, isFinancialConnectionsAvailable = isFinancialConnectionsAvailable, lpmRepository = lpmRepository, @@ -143,7 +138,7 @@ internal class DefaultCustomerSheetLoader( ).sharedDataSpecs val isGooglePaySupportedOnDevice = googlePayRepositoryFactory( - if (isLiveModeProvider()) GooglePayEnvironment.Production else GooglePayEnvironment.Test + if (elementsSession.stripeIntent.isLiveMode) GooglePayEnvironment.Production else GooglePayEnvironment.Test ).isReady().first() val isGooglePayReadyAndEnabled = configuration.googlePayEnabled && isGooglePaySupportedOnDevice 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 334db2308af..943a3836d55 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -17,7 +17,6 @@ import com.stripe.android.common.model.PaymentMethodRemovePermission import com.stripe.android.core.Logger import com.stripe.android.core.exception.StripeException import com.stripe.android.core.injection.IOContext -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.core.networking.AnalyticsEvent import com.stripe.android.core.networking.ApiRequest import com.stripe.android.core.strings.ResolvableString @@ -109,7 +108,6 @@ internal class CustomerSheetViewModel( private val stripeRepository: StripeRepository, private val eventReporter: CustomerSheetEventReporter, private val workContext: CoroutineContext = Dispatchers.IO, - private val isLiveModeProvider: () -> Boolean, private val productUsage: Set, confirmationHandlerFactory: ConfirmationHandler.Factory, private val customerSheetLoader: CustomerSheetLoader, @@ -129,7 +127,6 @@ internal class CustomerSheetViewModel( stripeRepository: StripeRepository, eventReporter: CustomerSheetEventReporter, @IOContext workContext: CoroutineContext = Dispatchers.IO, - @Named(IS_LIVE_MODE) isLiveModeProvider: () -> Boolean, @Named(PRODUCT_USAGE) productUsage: Set, confirmationHandlerFactory: ConfirmationHandler.Factory, customerSheetLoader: CustomerSheetLoader, @@ -150,7 +147,6 @@ internal class CustomerSheetViewModel( eventReporter = eventReporter, workContext = workContext, productUsage = productUsage, - isLiveModeProvider = isLiveModeProvider, confirmationHandlerFactory = confirmationHandlerFactory, customerSheetLoader = customerSheetLoader, errorReporter = errorReporter, @@ -163,10 +159,28 @@ internal class CustomerSheetViewModel( productUsageTokens = productUsage, ) + private val customerState = MutableStateFlow( + CustomerState( + paymentMethods = listOf(), + configuration = configuration, + currentSelection = originalPaymentSelection, + permissions = CustomerPermissions( + removePaymentMethod = PaymentMethodRemovePermission.None, + canRemoveLastPaymentMethod = false, + canUpdateFullPaymentMethodDetails = false, + ), + metadata = null, + ) + ) + + private val isLiveMode + get() = customerState.value.metadata?.stripeIntent?.isLiveMode + ?: paymentConfigurationProvider.get().isLiveMode() + private val backStack = MutableStateFlow>( listOf( CustomerSheetViewState.Loading( - isLiveMode = isLiveModeProvider() + isLiveMode = isLiveMode ) ) ) @@ -184,20 +198,6 @@ internal class CustomerSheetViewModel( error = null, ) ) - private val customerState = MutableStateFlow( - CustomerState( - paymentMethods = listOf(), - configuration = configuration, - currentSelection = originalPaymentSelection, - permissions = CustomerPermissions( - removePaymentMethod = PaymentMethodRemovePermission.None, - canRemoveLastPaymentMethod = false, - canUpdateFullPaymentMethodDetails = false, - ), - metadata = null, - ) - ) - private val selectPaymentMethodState = combineAsStateFlow( customerState, selectionConfirmationState, @@ -214,7 +214,7 @@ internal class CustomerSheetViewModel( title = configuration.headerTextForSelectionScreen, savedPaymentMethods = paymentMethods, paymentSelection = paymentSelection, - isLiveMode = isLiveModeProvider(), + isLiveMode = isLiveMode, canRemovePaymentMethods = customerState.canRemove, primaryButtonVisible = primaryButtonVisible, showGooglePay = shouldShowGooglePay(paymentMethodMetadata), @@ -577,7 +577,7 @@ internal class CustomerSheetViewModel( transition( to = CustomerSheetViewState.UpdatePaymentMethod( updatePaymentMethodInteractor = DefaultUpdatePaymentMethodInteractor( - isLiveMode = isLiveModeProvider(), + isLiveMode = isLiveMode, canRemove = customerState.canRemove, canUpdateFullPaymentMethodDetails = customerState.canUpdateFullPaymentMethodDetails, displayableSavedPaymentMethod = paymentMethod, @@ -610,7 +610,7 @@ internal class CustomerSheetViewModel( ) }, ), - isLiveMode = isLiveModeProvider(), + isLiveMode = isLiveMode, ) ) } @@ -855,7 +855,7 @@ internal class CustomerSheetViewModel( ), draftPaymentSelection = null, enabled = true, - isLiveMode = isLiveModeProvider(), + isLiveMode = isLiveMode, isProcessing = false, isFirstPaymentMethod = isFirstPaymentMethod, primaryButtonLabel = R.string.stripe_paymentsheet_save.resolvableString, diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/injection/CustomerSheetViewModelModule.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/injection/CustomerSheetViewModelModule.kt index bcdc69efcd9..8ddcfc8f672 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/injection/CustomerSheetViewModelModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/injection/CustomerSheetViewModelModule.kt @@ -9,7 +9,6 @@ import com.stripe.android.PaymentConfiguration import com.stripe.android.core.Logger import com.stripe.android.core.injection.ENABLE_LOGGING import com.stripe.android.core.injection.IOContext -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.core.injection.PUBLISHABLE_KEY import com.stripe.android.core.injection.STRIPE_ACCOUNT_ID import com.stripe.android.core.injection.UIContext @@ -113,12 +112,6 @@ internal interface CustomerSheetViewModelModule { paymentConfiguration: Provider ): () -> String? = { paymentConfiguration.get().stripeAccountId } - @Provides - @Named(IS_LIVE_MODE) - fun isLiveMode( - paymentConfiguration: Provider - ): () -> Boolean = { paymentConfiguration.get().isLiveMode() } - @Provides internal fun providesErrorReporter( analyticsRequestFactory: AnalyticsRequestFactory, diff --git a/paymentsheet/src/main/java/com/stripe/android/link/injection/LinkControllerModule.kt b/paymentsheet/src/main/java/com/stripe/android/link/injection/LinkControllerModule.kt index 75dae6953d8..cba5169ed14 100644 --- a/paymentsheet/src/main/java/com/stripe/android/link/injection/LinkControllerModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/link/injection/LinkControllerModule.kt @@ -2,12 +2,10 @@ package com.stripe.android.link.injection import android.app.Application import android.content.Context -import com.stripe.android.PaymentConfiguration import com.stripe.android.common.di.ApplicationIdModule import com.stripe.android.common.di.MobileSessionIdModule import com.stripe.android.core.injection.CoreCommonModule import com.stripe.android.core.injection.CoroutineContextModule -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.googlepaylauncher.injection.GooglePayLauncherModule import com.stripe.android.link.DefaultLinkConfigurationLoader import com.stripe.android.link.LinkConfigurationLoader @@ -24,7 +22,6 @@ import dagger.Binds import dagger.Module import dagger.Provides import javax.inject.Named -import javax.inject.Provider import javax.inject.Singleton @Module( @@ -71,11 +68,5 @@ internal interface LinkControllerModule { @Singleton @Named(PRODUCT_USAGE) fun provideProductUsageTokens() = setOf("LinkPaymentMethodLauncher") - - @Provides - @Named(IS_LIVE_MODE) - fun isLiveMode( - paymentConfiguration: Provider - ): () -> Boolean = { paymentConfiguration.get().isLiveMode() } } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementSubcomponent.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementSubcomponent.kt index 9abc79d9ae7..e3ac82ca3f2 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementSubcomponent.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementSubcomponent.kt @@ -4,7 +4,6 @@ import android.app.Application import androidx.activity.result.ActivityResultCaller import androidx.lifecycle.LifecycleOwner import com.stripe.android.PaymentConfiguration -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.paymentelement.EmbeddedPaymentElement import com.stripe.android.paymentelement.embedded.DefaultEmbeddedResultCallbackHelper import com.stripe.android.paymentelement.embedded.EmbeddedResultCallbackHelper @@ -13,8 +12,6 @@ import dagger.BindsInstance import dagger.Module import dagger.Provides import dagger.Subcomponent -import javax.inject.Named -import javax.inject.Provider @Subcomponent( modules = [ @@ -56,11 +53,5 @@ internal interface EmbeddedPaymentElementModule { fun paymentConfiguration(application: Application): PaymentConfiguration { return PaymentConfiguration.getInstance(application) } - - @Provides - @Named(IS_LIVE_MODE) - fun isLiveMode( - paymentConfiguration: Provider - ): () -> Boolean = { paymentConfiguration.get().isLiveMode() } } } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementViewModelComponent.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementViewModelComponent.kt index b6810906854..08f29fcef04 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementViewModelComponent.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/content/EmbeddedPaymentElementViewModelComponent.kt @@ -4,12 +4,10 @@ import android.app.Application import android.content.Context import android.content.res.Resources import androidx.lifecycle.SavedStateHandle -import com.stripe.android.PaymentConfiguration import com.stripe.android.cards.CardAccountRangeRepository import com.stripe.android.cards.DefaultCardAccountRangeRepositoryFactory import com.stripe.android.common.di.ApplicationIdModule import com.stripe.android.common.di.MobileSessionIdModule -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.core.injection.ViewModelScope import com.stripe.android.core.utils.RealUserFacingLogger import com.stripe.android.core.utils.UserFacingLogger @@ -52,7 +50,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.StateFlow import javax.inject.Named -import javax.inject.Provider import javax.inject.Singleton @Singleton @@ -182,12 +179,6 @@ internal interface EmbeddedPaymentElementViewModelModule { return confirmationStateHolder.state?.paymentMethodMetadata } - @Provides - @Named(IS_LIVE_MODE) - fun providesIsLiveMode( - paymentConfiguration: Provider - ): () -> Boolean = { paymentConfiguration.get().isLiveMode() } - @Provides @Singleton fun providesLinkAccountHolder(savedStateHandle: SavedStateHandle): LinkAccountHolder { diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt index 912412a3a69..047efb78311 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt @@ -44,10 +44,7 @@ internal class PaymentSheetActivity : BaseSheetActivity() { } else { try { starterArgs.initializationMode.validate() - starterArgs.config.asCommonConfiguration().validate( - viewModel.isLiveModeProvider(), - starterArgs.paymentElementCallbackIdentifier - ) + starterArgs.config.asCommonConfiguration().validate(starterArgs.paymentElementCallbackIdentifier) } catch (e: IllegalArgumentException) { finishWithError(e) return 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 332cd252757..a5224a351d2 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt @@ -16,7 +16,6 @@ import com.stripe.android.common.model.asCommonConfiguration import com.stripe.android.core.Logger import com.stripe.android.core.exception.StripeException import com.stripe.android.core.injection.IOContext -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.core.strings.ResolvableString import com.stripe.android.core.utils.requireApplication import com.stripe.android.googlepaylauncher.GooglePayEnvironment @@ -68,7 +67,6 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import javax.inject.Inject -import javax.inject.Named import javax.inject.Singleton import kotlin.coroutines.CoroutineContext @@ -88,7 +86,6 @@ internal class PaymentSheetViewModel @Inject internal constructor( private val errorReporter: ErrorReporter, internal val cvcRecollectionHandler: CvcRecollectionHandler, private val cvcRecollectionInteractorFactory: CvcRecollectionInteractor.Factory, - @Named(IS_LIVE_MODE) val isLiveModeProvider: () -> Boolean, ) : BaseSheetViewModel( config = args.config, eventReporter = eventReporter, @@ -413,7 +410,7 @@ internal class PaymentSheetViewModel @Inject internal constructor( lastFour = cvcRecollectionData.lastFour ?: "", cardBrand = cvcRecollectionData.brand, cvc = "", - isTestMode = paymentMethodMetadata.value?.stripeIntent?.isLiveMode?.not() ?: false, + isTestMode = paymentMethodMetadata.value?.stripeIntent?.isLiveMode?.not() ?: false ), processing = processing, coroutineScope = viewModelScope, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerModule.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerModule.kt index 59c14283f85..b0f77afcd9b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerModule.kt @@ -4,8 +4,6 @@ import android.app.Application import android.content.Context import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope -import com.stripe.android.PaymentConfiguration -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.link.LinkActivityContract import com.stripe.android.link.LinkPaymentLauncher import com.stripe.android.link.account.LinkStore @@ -26,7 +24,6 @@ import dagger.Module import dagger.Provides import kotlinx.coroutines.CoroutineScope import javax.inject.Named -import javax.inject.Provider import javax.inject.Singleton @Module( @@ -123,13 +120,6 @@ internal object FlowControllerModule { @Named(ALLOWS_MANUAL_CONFIRMATION) fun provideAllowsManualConfirmation() = true - @Provides - @Singleton - @Named(IS_LIVE_MODE) - fun provideIsLiveMode(paymentConfiguration: Provider): () -> Boolean { - return { paymentConfiguration.get().isLiveMode() } - } - @Provides fun providePaymentMethodMetadata(viewModel: FlowControllerViewModel): PaymentMethodMetadata? { return viewModel.state?.paymentSheetState?.paymentMethodMetadata diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetLauncherModule.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetLauncherModule.kt index f7718de781f..22c04061749 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetLauncherModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetLauncherModule.kt @@ -2,8 +2,6 @@ package com.stripe.android.paymentsheet.injection import android.app.Application import android.content.Context -import com.stripe.android.PaymentConfiguration -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.lpmfoundations.paymentmethod.PaymentMethodMetadata import com.stripe.android.paymentelement.confirmation.ALLOWS_MANUAL_CONFIRMATION import com.stripe.android.payments.core.injection.PRODUCT_USAGE @@ -15,7 +13,6 @@ import dagger.Binds import dagger.Module import dagger.Provides import javax.inject.Named -import javax.inject.Provider import javax.inject.Singleton @Module @@ -44,12 +41,6 @@ internal abstract class PaymentSheetLauncherModule { return CvcRecollectionHandlerImpl() } - @Provides - @Named(IS_LIVE_MODE) - fun isLiveMode( - paymentConfiguration: Provider - ): () -> Boolean = { paymentConfiguration.get().isLiveMode() } - @Provides fun providePaymentMethodMetadata(viewModel: PaymentSheetViewModel): PaymentMethodMetadata? { return viewModel.paymentMethodMetadata.value diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt index d3eaf00222b..f4510585967 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt @@ -10,7 +10,6 @@ import com.stripe.android.common.validation.isSupportedWithBillingConfig import com.stripe.android.core.Logger import com.stripe.android.core.exception.StripeException import com.stripe.android.core.injection.IOContext -import com.stripe.android.core.injection.IS_LIVE_MODE import com.stripe.android.core.utils.FeatureFlag import com.stripe.android.core.utils.FeatureFlags import com.stripe.android.core.utils.UserFacingLogger @@ -56,7 +55,6 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.parcelize.Parcelize import javax.inject.Inject -import javax.inject.Named import javax.inject.Singleton import kotlin.coroutines.CoroutineContext @@ -213,7 +211,6 @@ internal class DefaultPaymentElementLoader @Inject constructor( private val externalPaymentMethodsRepository: ExternalPaymentMethodsRepository, private val userFacingLogger: UserFacingLogger, private val integrityRequestManager: IntegrityRequestManager, - @Named(IS_LIVE_MODE) private val isLiveModeProvider: () -> Boolean, @PaymentElementCallbackIdentifier private val paymentElementCallbackIdentifier: String, private val analyticsMetadataFactory: AnalyticsMetadataFactory, ) : PaymentElementLoader { @@ -239,7 +236,7 @@ internal class DefaultPaymentElementLoader @Inject constructor( val configuration = integrationConfiguration.commonConfiguration // Validate configuration before loading initializationMode.validate() - configuration.validate(isLiveModeProvider(), paymentElementCallbackIdentifier) + configuration.validate(paymentElementCallbackIdentifier) eventReporter.onLoadStarted(metadata.initializedViaCompose) 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 43f12746d43..b989be1ca79 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt @@ -18,7 +18,6 @@ import com.stripe.android.customersheet.data.CustomerSheetDataResult import com.stripe.android.customersheet.data.FakeCustomerSheetIntentDataSource import com.stripe.android.customersheet.data.FakeCustomerSheetPaymentMethodDataSource import com.stripe.android.customersheet.data.FakeCustomerSheetSavedSelectionDataSource -import com.stripe.android.customersheet.injection.CustomerSheetViewModelModule import com.stripe.android.customersheet.utils.CustomerSheetTestHelper.createViewModel import com.stripe.android.customersheet.utils.FakeCustomerSheetLoader import com.stripe.android.isInstanceOf @@ -83,33 +82,6 @@ class CustomerSheetViewModelTest { @get:Rule val coroutineTestRule = CoroutineTestRule(testDispatcher) - @Test - fun `isLiveMode is true when publishable key is live`() { - var isLiveMode = CustomerSheetViewModelModule.isLiveMode { - PaymentConfiguration( - publishableKey = "pk_test_123" - ) - } - - assertThat(isLiveMode()).isFalse() - - isLiveMode = CustomerSheetViewModelModule.isLiveMode { - PaymentConfiguration( - publishableKey = "pk_live_123" - ) - } - - assertThat(isLiveMode()).isTrue() - - isLiveMode = CustomerSheetViewModelModule.isLiveMode { - PaymentConfiguration( - publishableKey = "pk_test_51HvTI7Lu5o3livep6t5AgBSkMvWoTtA0nyA7pVYDqpfLkRtWun7qZTYCOHCReprfLM464yaBeF72UFfB7cY9WG4a00ZnDtiC2C" - ) - } - - assertThat(isLiveMode()).isFalse() - } - @Test fun `init emits CustomerSheetViewState#AddPaymentMethod when no payment methods available`() = runTest(testDispatcher) { val viewModel = createViewModel( 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 8ba84a9a6a2..f3a1c3139de 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 @@ -420,7 +420,6 @@ internal class DefaultCustomerSheetLoaderTest { val configuration = CustomerSheet.Configuration(merchantDisplayName = "Merchant, Inc.") val loader = DefaultCustomerSheetLoader( - isLiveModeProvider = { false }, googlePayRepositoryFactory = { readyGooglePayRepository }, initializationDataSourceProvider = initDataSource, lpmRepository = lpmRepository, @@ -461,7 +460,6 @@ internal class DefaultCustomerSheetLoaderTest { fun `Fails if awaiting InitializationDataSource times out`() = runTest { val configuration = CustomerSheet.Configuration(merchantDisplayName = "Merchant, Inc.") val loader = DefaultCustomerSheetLoader( - isLiveModeProvider = { false }, googlePayRepositoryFactory = { readyGooglePayRepository }, lpmRepository = lpmRepository, isFinancialConnectionsAvailable = { false }, @@ -631,7 +629,6 @@ internal class DefaultCustomerSheetLoaderTest { private fun createCustomerSheetLoader( isGooglePayReady: Boolean = true, - isLiveModeProvider: () -> Boolean = { false }, isCbcEligible: Boolean? = null, isFinancialConnectionsAvailable: IsFinancialConnectionsSdkAvailable = IsFinancialConnectionsSdkAvailable { false }, @@ -672,7 +669,6 @@ internal class DefaultCustomerSheetLoaderTest { return createCustomerSheetLoader( initializationDataSourceProvider = CompletableSingle(initializationDataSource), isGooglePayReady = isGooglePayReady, - isLiveModeProvider = isLiveModeProvider, isFinancialConnectionsAvailable = isFinancialConnectionsAvailable, lpmRepository = lpmRepository, errorReporter = errorReporter, @@ -730,7 +726,6 @@ internal class DefaultCustomerSheetLoaderTest { private fun createCustomerSheetLoader( initializationDataSourceProvider: Single, isGooglePayReady: Boolean = true, - isLiveModeProvider: () -> Boolean = { false }, isFinancialConnectionsAvailable: IsFinancialConnectionsSdkAvailable = IsFinancialConnectionsSdkAvailable { false }, lpmRepository: LpmRepository = this.lpmRepository, @@ -739,7 +734,6 @@ internal class DefaultCustomerSheetLoaderTest { workContext: CoroutineContext = UnconfinedTestDispatcher() ): CustomerSheetLoader { return DefaultCustomerSheetLoader( - isLiveModeProvider = isLiveModeProvider, googlePayRepositoryFactory = { if (isGooglePayReady) readyGooglePayRepository else unreadyGooglePayRepository }, 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 310431b0854..1c9c6129a57 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 @@ -60,7 +60,6 @@ internal object CustomerSheetTestHelper { internal val application = ApplicationProvider.getApplicationContext() internal fun createViewModel( - isLiveMode: Boolean = false, workContext: CoroutineContext = EmptyCoroutineContext, integrationType: CustomerSheetIntegration.Type = CustomerSheetIntegration.Type.CustomerAdapter, isGooglePayAvailable: Boolean = true, @@ -127,7 +126,6 @@ internal object CustomerSheetTestHelper { stripeRepository = stripeRepository, configuration = configuration, integrationType = integrationType, - isLiveModeProvider = { isLiveMode }, logger = Logger.noop(), productUsage = emptySet(), confirmationHandlerFactory = confirmationHandlerFactory ?: createTestConfirmationHandlerFactory( diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/FormHelperOpenCardScanAutomaticallyTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/FormHelperOpenCardScanAutomaticallyTest.kt index 929acfe2abd..eb1b8ee2b01 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/FormHelperOpenCardScanAutomaticallyTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/FormHelperOpenCardScanAutomaticallyTest.kt @@ -199,7 +199,6 @@ internal class FormHelperOpenCardScanAutomaticallyTest { return FakeCvcRecollectionInteractor() } }, - isLiveModeProvider = { false } ) } } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt index c0308ea4350..cf40a49933e 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt @@ -1290,7 +1290,6 @@ internal class PaymentSheetActivityTest { return FakeCvcRecollectionInteractor() } }, - isLiveModeProvider = { false } ) } } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetConfigurationKtxTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetConfigurationKtxTest.kt index 671d9ed68c0..d9ca4809523 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetConfigurationKtxTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetConfigurationKtxTest.kt @@ -34,7 +34,7 @@ class PaymentSheetConfigurationKtxTest { message = "When a CustomerConfiguration is passed to PaymentSheet, " + "the ephemeralKeySecret cannot be an empty string." ) { - configWithBlankEphemeralKeySecret.validate(isLiveMode = false, callbackIdentifier = "") + configWithBlankEphemeralKeySecret.validate(callbackIdentifier = "") } } @@ -50,8 +50,8 @@ class PaymentSheetConfigurationKtxTest { @Test fun `'validate' should succeed when ephemeral key secret is of correct format`() { - getConfig("ek_askljdlkasfhgasdfjls").validate(isLiveMode = false, callbackIdentifier = "") - getConfig("ek_test_iiuwfhdaiuhasdvkcjn32n").validate(isLiveMode = false, callbackIdentifier = "") + getConfig("ek_askljdlkasfhgasdfjls").validate(callbackIdentifier = "") + getConfig("ek_test_iiuwfhdaiuhasdvkcjn32n").validate(callbackIdentifier = "") } @Test @@ -61,7 +61,7 @@ class PaymentSheetConfigurationKtxTest { IllegalArgumentException::class, message = "`ephemeralKeySecret` format does not match expected client secret formatting" ) { - getConfig(ephemeralKeySecret).validate(isLiveMode = false, callbackIdentifier = "") + getConfig(ephemeralKeySecret).validate(callbackIdentifier = "") } } @@ -88,7 +88,7 @@ class PaymentSheetConfigurationKtxTest { message = "When a CustomerConfiguration is passed to PaymentSheet, " + "the customerSessionClientSecret cannot be an empty string." ) { - configWithBlankCustomerSessionClientSecret.validate(isLiveMode = false, callbackIdentifier = "") + configWithBlankCustomerSessionClientSecret.validate(callbackIdentifier = "") } } @@ -108,7 +108,6 @@ class PaymentSheetConfigurationKtxTest { "secret. See CustomerSession API: https://docs.stripe.com/api/customer_sessions/create" ) { configWithEphemeralKeySecretAsCustomerSessionClientSecret.validate( - isLiveMode = false, callbackIdentifier = "" ) } @@ -129,7 +128,7 @@ class PaymentSheetConfigurationKtxTest { message = "Argument does not look like a CustomerSession client secret. " + "See CustomerSession API: https://docs.stripe.com/api/customer_sessions/create" ) { - configWithInvalidCustomerSessionClientSecret.validate(isLiveMode = false, callbackIdentifier = "") + configWithInvalidCustomerSessionClientSecret.validate(callbackIdentifier = "") } } @@ -141,7 +140,7 @@ class PaymentSheetConfigurationKtxTest { .asCommonConfiguration() // Should not throw - configWithValidExternalPaymentMethods.validate(isLiveMode = false, callbackIdentifier = "") + configWithValidExternalPaymentMethods.validate(callbackIdentifier = "") } @Test @@ -158,7 +157,7 @@ class PaymentSheetConfigurationKtxTest { "See https://docs.stripe.com/payments/external-payment-methods?platform=android#available-external-" + "payment-methods" ) { - configWithInvalidExternalPaymentMethod.validate(isLiveMode = false, callbackIdentifier = "") + configWithInvalidExternalPaymentMethod.validate(callbackIdentifier = "") } } @@ -170,7 +169,7 @@ class PaymentSheetConfigurationKtxTest { .asCommonConfiguration() // Should not throw - configWithEmptyExternalPaymentMethods.validate(isLiveMode = false, callbackIdentifier = "") + configWithEmptyExternalPaymentMethods.validate(callbackIdentifier = "") } @Test @@ -187,21 +186,10 @@ class PaymentSheetConfigurationKtxTest { "See https://docs.stripe.com/payments/external-payment-methods?platform=android#available-external" + "-payment-methods" ) { - configWithMultipleInvalidExternalPaymentMethods.validate(isLiveMode = false, callbackIdentifier = "") + configWithMultipleInvalidExternalPaymentMethods.validate(callbackIdentifier = "") } } - @Test - fun `'validate' should succeed when in live mode with invalid external payment methods`() { - val configWithInvalidExternalPaymentMethods = configuration.newBuilder() - .externalPaymentMethods(listOf("paypal", "venmo")) - .build() - .asCommonConfiguration() - - // Should not throw when in live mode - configWithInvalidExternalPaymentMethods.validate(isLiveMode = true, callbackIdentifier = "") - } - @Test fun `'validate' should fail when CT callback is set with LegacyCustomerEphemeralKey in test mode`() { val callbackIdentifier = "test_identifier" @@ -225,36 +213,11 @@ class PaymentSheetConfigurationKtxTest { message = "createIntentWithConfirmationTokenCallback must be used with CustomerSession." ) { configWithLegacyKey.validate( - isLiveMode = false, callbackIdentifier = callbackIdentifier ) } } - @Test - fun `'validate' should succeed when CT callback is set with LegacyCustomerEphemeralKey in live mode`() { - val callbackIdentifier = "test_identifier" - - PaymentElementCallbackReferences[callbackIdentifier] = PaymentElementCallbacks.Builder() - .createIntentCallback { _ -> error("Should not be called!") } - .build() - - val configWithLegacyKey = configuration.newBuilder() - .customer( - PaymentSheet.CustomerConfiguration( - id = "cus_123", - ephemeralKeySecret = "ek_live_123", - ) - ) - .build() - .asCommonConfiguration() - - configWithLegacyKey.validate( - isLiveMode = true, - callbackIdentifier = callbackIdentifier - ) - } - @Test fun `'validate' should succeed when createIntentWithConfirmationTokenCallback is set with CustomerSession`() { val callbackIdentifier = "test_identifier" @@ -274,7 +237,6 @@ class PaymentSheetConfigurationKtxTest { .asCommonConfiguration() configWithCustomerSession.validate( - isLiveMode = false, callbackIdentifier = callbackIdentifier ) } @@ -293,7 +255,6 @@ class PaymentSheetConfigurationKtxTest { .asCommonConfiguration() configWithoutCustomer.validate( - isLiveMode = false, callbackIdentifier = callbackIdentifier ) } 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 957c0bacb23..9ee8043be53 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt @@ -3442,7 +3442,6 @@ internal class PaymentSheetViewModelTest { return cvcRecollectionInteractor } }, - isLiveModeProvider = { false } ) } } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt index a5e5ce71608..3943e5288d7 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt @@ -2757,9 +2757,7 @@ internal class DefaultPaymentElementLoaderTest { val loader = createPaymentElementLoader( errorReporter = errorReporter, - stripeIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD.copy( - isLiveMode = false - ) + stripeIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD ) val exception = loader.load( @@ -2802,7 +2800,6 @@ internal class DefaultPaymentElementLoaderTest { stripeIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD.copy( isLiveMode = true ), - isLiveMode = true, ) val state = loader.load( @@ -4139,7 +4136,6 @@ internal class DefaultPaymentElementLoaderTest { ), userFacingLogger: FakeUserFacingLogger = FakeUserFacingLogger(), integrityRequestManager: IntegrityRequestManager = FakeIntegrityRequestManager(), - isLiveMode: Boolean = false, analyticsMetadataFactory: DefaultPaymentElementLoader.AnalyticsMetadataFactory = FakeDefaultPaymentElementLoaderAnalyticsMetadataFactory { AnalyticsMetadata(emptyMap()) @@ -4170,7 +4166,6 @@ internal class DefaultPaymentElementLoaderTest { externalPaymentMethodsRepository = ExternalPaymentMethodsRepository(errorReporter = FakeErrorReporter()), userFacingLogger = userFacingLogger, integrityRequestManager = integrityRequestManager, - isLiveModeProvider = { isLiveMode }, paymentElementCallbackIdentifier = PAYMENT_ELEMENT_CALLBACKS_IDENTIFIER, analyticsMetadataFactory = analyticsMetadataFactory, ) diff --git a/stripe-core/src/main/java/com/stripe/android/core/injection/NamedConstants.kt b/stripe-core/src/main/java/com/stripe/android/core/injection/NamedConstants.kt index aafc3eecea2..70064ce3e3d 100644 --- a/stripe-core/src/main/java/com/stripe/android/core/injection/NamedConstants.kt +++ b/stripe-core/src/main/java/com/stripe/android/core/injection/NamedConstants.kt @@ -32,12 +32,6 @@ const val INITIAL_VALUES = "initialValues" @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) const val SHIPPING_VALUES = "shippingValues" -/** - * Name for isLiveMode - */ -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -const val IS_LIVE_MODE = "isLiveMode" - /** * Name for linear delay supplier */