diff --git a/link/detekt-baseline.xml b/link/detekt-baseline.xml index db4eafc599d..3a42c33cb25 100644 --- a/link/detekt-baseline.xml +++ b/link/detekt-baseline.xml @@ -7,7 +7,6 @@ MaxLineLength:InjectableActivityScenario.kt$InjectableActivityScenario$delegate ?: throw IllegalStateException("Cannot move to state $newState since the activity hasn't been launched.") MaxLineLength:InjectableActivityScenario.kt$InjectableActivityScenario$val d = delegate ?: throw IllegalStateException("Cannot run onActivity since the activity hasn't been launched.") MaxLineLength:LinkActivityResultTest.kt$LinkActivityResultTest$"link-popup://complete?link_status=complete&pm=eyJpZCI6InBtXzFOSmVFckx1NW8zUDE4WnBtWHBDdElyUiIsIm9iamVjdCI6InBheW1lbnRfbWV0aG9kIiwiYmlsbGluZ19kZXRhaWxzIjp7ImFkZHJlc3MiOnsiY2l0eSI6bnVsbCwiY291bnRyeSI6bnVsbCwibGluZTEiOm51bGwsImxpbmUyIjpudWxsLCJwb3N0YWxfY29kZSI6bnVsbCwic3RhdGUiOm51bGx9LCJlbWFpbCI6bnVsbCwibmFtZSI6bnVsbCwicGhvbmUiOm51bGx9LCJjYXJkIjp7ImJyYW5kIjoidmlzYSIsImNoZWNrcyI6eyJhZGRyZXNzX2xpbmUxX2NoZWNrIjpudWxsLCJhZGRyZXNzX3Bvc3RhbF9jb2RlX2NoZWNrIjpudWxsLCJjdmNfY2hlY2siOm51bGx9LCJjb3VudHJ5IjpudWxsLCJleHBfbW9udGgiOjEyLCJleHBfeWVhciI6MjAzNCwiZnVuZGluZyI6ImNyZWRpdCIsImdlbmVyYXRlZF9mcm9tIjpudWxsLCJsYXN0NCI6IjAwMDAiLCJuZXR3b3JrcyI6eyJhdmFpbGFibGUiOlsidmlzYSJdLCJwcmVmZXJyZWQiOm51bGx9LCJ0aHJlZV9kX3NlY3VyZV91c2FnZSI6eyJzdXBwb3J0ZWQiOnRydWV9LCJ3YWxsZXQiOnsiZHluYW1pY19sYXN0NCI6bnVsbCwibGluayI6e30sInR5cGUiOiJsaW5rIn19LCJjcmVhdGVkIjoxNjg2OTI4MDIxLCJjdXN0b21lciI6bnVsbCwibGl2ZW1vZGUiOmZhbHNlLCJ0eXBlIjoiY2FyZCJ9ICAg" - NoUnusedImports:com.stripe.android.link.theme.Theme.kt:9 SwallowedException:LinkActivityResult.kt$e: Exception TooGenericExceptionCaught:LinkActivityResult.kt$e: Exception TooManyFunctions:DefaultLinkEventsReporter.kt$DefaultLinkEventsReporter : LinkEventsReporter diff --git a/payments-core/src/main/java/com/stripe/android/payments/core/injection/NamedConstants.kt b/payments-core/src/main/java/com/stripe/android/payments/core/injection/NamedConstants.kt index 9dfb158c97c..1d54ca858a8 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/core/injection/NamedConstants.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/core/injection/NamedConstants.kt @@ -20,9 +20,6 @@ const val IS_PAYMENT_INTENT = "isPaymentIntent" */ const val IS_INSTANT_APP = "isInstantApp" -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -const val APP_NAME = "appName" - /** * Status bar color of the host activity. */ diff --git a/paymentsheet/detekt-baseline.xml b/paymentsheet/detekt-baseline.xml index 3229b6b4287..dfed965244f 100644 --- a/paymentsheet/detekt-baseline.xml +++ b/paymentsheet/detekt-baseline.xml @@ -30,7 +30,7 @@ LongMethod:FormViewModelTest.kt$FormViewModelTest$@Test fun `Verify params are set when required address fields are complete`() LongMethod:PaymentOptionFactory.kt$PaymentOptionFactory$fun create(selection: PaymentSelection): PaymentOption LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance() - LongMethod:PaymentSheetLoader.kt$DefaultPaymentSheetLoader$private suspend fun create( elementsSession: ElementsSession, config: PaymentSheet.Configuration?, isGooglePayReady: Boolean, ): PaymentSheetState.Full + LongMethod:PaymentSheetLoader.kt$DefaultPaymentSheetLoader$private suspend fun create( elementsSession: ElementsSession, config: PaymentSheet.Configuration, isGooglePayReady: Boolean, ): PaymentSheetState.Full LongMethod:PlaceholderHelperTest.kt$PlaceholderHelperTest$@Test fun `Test correct placeholder is removed for placeholder spec`() LongMethod:USBankAccountEmitters.kt$@Composable internal fun USBankAccountEmitters( viewModel: USBankAccountFormViewModel, usBankAccountFormArgs: USBankAccountFormArguments, ) LongMethod:USBankAccountForm.kt$@Composable internal fun BillingDetailsForm( formArgs: FormArguments, isProcessing: Boolean, isPaymentFlow: Boolean, nameController: TextFieldController, emailController: TextFieldController, phoneController: PhoneNumberController, addressController: AddressController, lastTextFieldIdentifier: IdentifierSpec?, sameAsShippingElement: SameAsShippingElement?, ) @@ -55,7 +55,6 @@ MagicNumber:StateFlows.kt$5 MagicNumber:StateFlows.kt$6 MagicNumber:USBankAccountForm.kt$0.5f - MaxLineLength:CustomerAdapterTest.kt$CustomerAdapterTest$fun MaxLineLength:CustomerRepositoryTest.kt$CustomerRepositoryTest$fun MaxLineLength:CustomerSheetViewModelTest.kt$CustomerSheetViewModelTest$fun MaxLineLength:CustomerSheetViewModelTest.kt$CustomerSheetViewModelTest$publishableKey = "pk_test_51HvTI7Lu5o3livep6t5AgBSkMvWoTtA0nyA7pVYDqpfLkRtWun7qZTYCOHCReprfLM464yaBeF72UFfB7cY9WG4a00ZnDtiC2C" diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DefaultPaymentSheetLauncher.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DefaultPaymentSheetLauncher.kt index f7a582aa58e..992ab3e5f8e 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DefaultPaymentSheetLauncher.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DefaultPaymentSheetLauncher.kt @@ -84,7 +84,7 @@ internal class DefaultPaymentSheetLauncher( ) { val args = PaymentSheetContractV2.Args( initializationMode = mode, - config = configuration, + config = configuration ?: PaymentSheet.Configuration.default(activity), statusBarColor = activity.window?.statusBarColor, ) 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 0747959694e..305ef53c4af 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt @@ -60,7 +60,7 @@ internal class PaymentOptionsViewModel @Inject constructor( ) : BaseSheetViewModel( application = application, config = args.state.config, - prefsRepository = prefsRepositoryFactory(args.state.config?.customer), + prefsRepository = prefsRepositoryFactory(args.state.config.customer), eventReporter = eventReporter, customerRepository = customerRepository, workContext = workContext, @@ -140,7 +140,7 @@ internal class PaymentOptionsViewModel @Inject constructor( cbcEligibility = when (args.state.isEligibleForCardBrandChoice) { true -> CardBrandChoiceEligibility.Eligible( - preferredNetworks = args.state.config?.preferredNetworks ?: listOf() + preferredNetworks = args.state.config.preferredNetworks ) false -> CardBrandChoiceEligibility.Ineligible } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt index b4af9e401fb..6a6242ca6bc 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt @@ -552,6 +552,13 @@ class PaymentSheet internal constructor( preferredNetworks = preferredNetworks ) } + + internal companion object { + fun default(context: Context): Configuration { + val appName = context.applicationInfo.loadLabel(context.packageManager).toString() + return Configuration(appName) + } + } } @Parcelize 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 94943272780..cda325c12bc 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt @@ -92,8 +92,8 @@ internal class PaymentSheetActivity : BaseSheetActivity() { } else { try { starterArgs.initializationMode.validate() - starterArgs.config?.validate() - starterArgs.config?.appearance?.parseAppearance() + starterArgs.config.validate() + starterArgs.config.appearance.parseAppearance() Result.success(starterArgs) } catch (e: InvalidParameterException) { Result.failure(e) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContract.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContract.kt index 81575c2bbc9..42284925e65 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContract.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContract.kt @@ -30,7 +30,7 @@ class PaymentSheetContract : ): Intent { val statusBarColor = (context as? Activity)?.window?.statusBarColor val args = input.copy(statusBarColor = statusBarColor) - return Intent(context, PaymentSheetActivity::class.java).putExtra(EXTRA_ARGS, args.toV2()) + return Intent(context, PaymentSheetActivity::class.java).putExtra(EXTRA_ARGS, args.toV2(context)) } override fun parseResult( @@ -54,7 +54,7 @@ class PaymentSheetContract : val googlePayConfig: PaymentSheet.GooglePayConfiguration? get() = config?.googlePay - internal fun toV2(): PaymentSheetContractV2.Args { + internal fun toV2(context: Context): PaymentSheetContractV2.Args { return PaymentSheetContractV2.Args( initializationMode = when (clientSecret) { is PaymentIntentClientSecret -> { @@ -64,7 +64,7 @@ class PaymentSheetContract : PaymentSheet.InitializationMode.SetupIntent(clientSecret.value) } }, - config = config, + config = config ?: PaymentSheet.Configuration.default(context), statusBarColor = statusBarColor, ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContractV2.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContractV2.kt index ccf7ceeb3a7..b0ef26d87db 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContractV2.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetContractV2.kt @@ -34,11 +34,11 @@ internal class PaymentSheetContractV2 : @Parcelize data class Args( internal val initializationMode: PaymentSheet.InitializationMode, - internal val config: PaymentSheet.Configuration?, + internal val config: PaymentSheet.Configuration, @ColorInt internal val statusBarColor: Int?, ) : ActivityStarter.Args { - val googlePayConfig: PaymentSheet.GooglePayConfiguration? get() = config?.googlePay + val googlePayConfig: PaymentSheet.GooglePayConfiguration? get() = config.googlePay companion object { internal fun fromIntent(intent: Intent): Args? { 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 b8a614d5b03..22b3603214b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt @@ -308,7 +308,7 @@ internal class PaymentSheetViewModel @Inject internal constructor( private fun handlePaymentSheetStateLoaded(state: PaymentSheetState.Full) { cbcEligibility = when (state.isEligibleForCardBrandChoice) { true -> CardBrandChoiceEligibility.Eligible( - preferredNetworks = state.config?.preferredNetworks ?: listOf() + preferredNetworks = state.config.preferredNetworks ) false -> CardBrandChoiceEligibility.Ineligible } @@ -494,7 +494,7 @@ internal class PaymentSheetViewModel @Inject internal constructor( val nextStep = intentConfirmationInterceptor.intercept( initializationMode = args.initializationMode, paymentSelection = paymentSelection, - shippingValues = args.config?.shippingDetails?.toConfirmPaymentIntentShipping(), + shippingValues = args.config.shippingDetails?.toConfirmPaymentIntentShipping(), ) deferredIntentConfirmationType = nextStep.deferredIntentConfirmationType diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/DefaultEventReporter.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/DefaultEventReporter.kt index 15755f239c9..add76f7ff6b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/DefaultEventReporter.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/DefaultEventReporter.kt @@ -25,7 +25,7 @@ internal class DefaultEventReporter @Inject internal constructor( ) : EventReporter { override fun onInit( - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, isDecoupling: Boolean, ) { fireEvent( diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/EventReporter.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/EventReporter.kt index 019b4f57209..fc7c6553df5 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/EventReporter.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/EventReporter.kt @@ -12,7 +12,7 @@ internal interface EventReporter { * PaymentSheet has been instantiated or FlowController has finished its configuration. */ fun onInit( - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, isDecoupling: Boolean, ) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt index c7800299d40..de4f4b865aa 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt @@ -47,55 +47,55 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent { class Init( private val mode: EventReporter.Mode, - private val configuration: PaymentSheet.Configuration?, + private val configuration: PaymentSheet.Configuration, override val isDecoupled: Boolean, ) : PaymentSheetEvent() { override val eventName: String get() { val configValue = listOfNotNull( - FIELD_CUSTOMER.takeIf { configuration?.customer != null }, - FIELD_GOOGLE_PAY.takeIf { configuration?.googlePay != null } + FIELD_CUSTOMER.takeIf { configuration.customer != null }, + FIELD_GOOGLE_PAY.takeIf { configuration.googlePay != null } ).takeUnless { it.isEmpty() }?.joinToString(separator = "_") ?: "default" return formatEventName(mode, "init_$configValue") } override val additionalParams: Map get() { - val primaryButtonConfig = configuration?.appearance?.primaryButton + val primaryButtonConfig = configuration.appearance.primaryButton val primaryButtonConfigMap = mapOf( FIELD_COLORS_LIGHT to ( - primaryButtonConfig?.colorsLight + primaryButtonConfig.colorsLight != PaymentSheet.PrimaryButtonColors.defaultLight ), FIELD_COLORS_DARK to ( - primaryButtonConfig?.colorsDark + primaryButtonConfig.colorsDark != PaymentSheet.PrimaryButtonColors.defaultDark ), - FIELD_CORNER_RADIUS to (primaryButtonConfig?.shape?.cornerRadiusDp != null), - FIELD_BORDER_WIDTH to (primaryButtonConfig?.shape?.borderStrokeWidthDp != null), - FIELD_FONT to (primaryButtonConfig?.typography?.fontResId != null) + FIELD_CORNER_RADIUS to (primaryButtonConfig.shape.cornerRadiusDp != null), + FIELD_BORDER_WIDTH to (primaryButtonConfig.shape.borderStrokeWidthDp != null), + FIELD_FONT to (primaryButtonConfig.typography.fontResId != null) ) val appearanceConfigMap = mutableMapOf( FIELD_COLORS_LIGHT to ( - configuration?.appearance?.colorsLight + configuration.appearance.colorsLight != PaymentSheet.Colors.defaultLight ), FIELD_COLORS_DARK to ( - configuration?.appearance?.colorsDark + configuration.appearance.colorsDark != PaymentSheet.Colors.defaultDark ), FIELD_CORNER_RADIUS to ( - configuration?.appearance?.shapes?.cornerRadiusDp + configuration.appearance.shapes.cornerRadiusDp != StripeThemeDefaults.shapes.cornerRadius ), FIELD_BORDER_WIDTH to ( - configuration?.appearance?.shapes?.borderStrokeWidthDp + configuration.appearance.shapes.borderStrokeWidthDp != StripeThemeDefaults.shapes.borderStrokeWidth ), - FIELD_FONT to (configuration?.appearance?.typography?.fontResId != null), + FIELD_FONT to (configuration.appearance.typography.fontResId != null), FIELD_SIZE_SCALE_FACTOR to ( - configuration?.appearance?.typography?.sizeScaleFactor + configuration.appearance.typography.sizeScaleFactor != StripeThemeDefaults.typography.fontSizeMultiplier ), FIELD_PRIMARY_BUTTON to primaryButtonConfigMap @@ -110,33 +110,33 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent { val billingDetailsCollectionConfigMap = mapOf( FIELD_ATTACH_DEFAULTS to configuration - ?.billingDetailsCollectionConfiguration - ?.attachDefaultsToPaymentMethod, + .billingDetailsCollectionConfiguration + .attachDefaultsToPaymentMethod, FIELD_COLLECT_NAME to configuration - ?.billingDetailsCollectionConfiguration - ?.name - ?.name, + .billingDetailsCollectionConfiguration + .name + .name, FIELD_COLLECT_EMAIL to configuration - ?.billingDetailsCollectionConfiguration - ?.email - ?.name, + .billingDetailsCollectionConfiguration + .email + .name, FIELD_COLLECT_PHONE to configuration - ?.billingDetailsCollectionConfiguration - ?.phone - ?.name, + .billingDetailsCollectionConfiguration + .phone + .name, FIELD_COLLECT_ADDRESS to configuration - ?.billingDetailsCollectionConfiguration - ?.address - ?.name, + .billingDetailsCollectionConfiguration + .address + .name, ) @Suppress("DEPRECATION") val configurationMap = mapOf( - FIELD_CUSTOMER to (configuration?.customer != null), - FIELD_GOOGLE_PAY to (configuration?.googlePay != null), - FIELD_PRIMARY_BUTTON_COLOR to (configuration?.primaryButtonColor != null), - FIELD_BILLING to (configuration?.defaultBillingDetails != null), - FIELD_DELAYED_PMS to (configuration?.allowsDelayedPaymentMethods), + FIELD_CUSTOMER to (configuration.customer != null), + FIELD_GOOGLE_PAY to (configuration.googlePay != null), + FIELD_PRIMARY_BUTTON_COLOR to (configuration.primaryButtonColor != null), + FIELD_BILLING to (configuration.defaultBillingDetails != null), + FIELD_DELAYED_PMS to (configuration.allowsDelayedPaymentMethods), FIELD_APPEARANCE to appearanceConfigMap, FIELD_BILLING_DETAILS_COLLECTION_CONFIGURATION to billingDetailsCollectionConfigMap, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt index 1102833b9aa..31614dfafa4 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt @@ -1,6 +1,7 @@ package com.stripe.android.paymentsheet.flowcontroller import android.app.Activity +import android.content.Context import android.os.Parcelable import androidx.activity.result.ActivityResultCallback import androidx.activity.result.ActivityResultLauncher @@ -72,6 +73,7 @@ internal class DefaultFlowController @Inject internal constructor( private val paymentResultCallback: PaymentSheetResultCallback, activityResultRegistryOwner: ActivityResultRegistryOwner, // Properties provided through injection + private val context: Context, private val eventReporter: EventReporter, private val viewModel: FlowControllerViewModel, private val paymentLauncherFactory: StripePaymentLauncherAssistedFactory, @@ -109,11 +111,14 @@ internal class DefaultFlowController @Inject internal constructor( override var shippingDetails: AddressDetails? get() = viewModel.state?.config?.shippingDetails set(value) { - viewModel.state = viewModel.state?.copy( - config = viewModel.state?.config?.copy( - shippingDetails = value + val state = viewModel.state + if (state != null) { + viewModel.state = state.copy( + config = state.config.copy( + shippingDetails = value + ) ) - ) + } } init { @@ -177,7 +182,7 @@ internal class DefaultFlowController @Inject internal constructor( ) { configure( mode = PaymentSheet.InitializationMode.PaymentIntent(paymentIntentClientSecret), - configuration = configuration, + configuration = configuration ?: PaymentSheet.Configuration.default(context), callback = callback, ) } @@ -189,7 +194,7 @@ internal class DefaultFlowController @Inject internal constructor( ) { configure( mode = PaymentSheet.InitializationMode.SetupIntent(setupIntentClientSecret), - configuration = configuration, + configuration = configuration ?: PaymentSheet.Configuration.default(context), callback = callback, ) } @@ -201,14 +206,14 @@ internal class DefaultFlowController @Inject internal constructor( ) { configure( mode = PaymentSheet.InitializationMode.DeferredIntent(intentConfiguration), - configuration = configuration, + configuration = configuration ?: PaymentSheet.Configuration.default(context), callback = callback, ) } private fun configure( mode: PaymentSheet.InitializationMode, - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, callback: PaymentSheet.FlowController.ConfigCallback ) { configurationHandler.configure( @@ -286,7 +291,7 @@ internal class DefaultFlowController @Inject internal constructor( // we present the mandate directly. sepaMandateActivityLauncher.launch( SepaMandateContract.Args( - merchantName = state.config?.merchantDisplayName ?: "" + merchantName = state.config.merchantDisplayName ) ) } else { @@ -307,7 +312,7 @@ internal class DefaultFlowController @Inject internal constructor( val nextStep = intentConfirmationInterceptor.intercept( initializationMode = initializationMode!!, paymentSelection = paymentSelection, - shippingValues = state.config?.shippingDetails?.toConfirmPaymentIntentShipping(), + shippingValues = state.config.shippingDetails?.toConfirmPaymentIntentShipping(), ) viewModel.deferredIntentConfirmationType = nextStep.deferredIntentConfirmationType @@ -563,8 +568,7 @@ internal class DefaultFlowController @Inject internal constructor( private fun launchGooglePay(state: PaymentSheetState.Full) { // state.config.googlePay is guaranteed not to be null or GooglePay would be disabled - val config = requireNotNull(state.config) - val googlePayConfig = requireNotNull(config.googlePay) + val googlePayConfig = requireNotNull(state.config.googlePay) val googlePayPaymentLauncherConfig = GooglePayPaymentMethodLauncher.Config( environment = when (googlePayConfig.environment) { PaymentSheet.GooglePayConfiguration.Environment.Production -> @@ -573,7 +577,7 @@ internal class DefaultFlowController @Inject internal constructor( GooglePayEnvironment.Test }, merchantCountryCode = googlePayConfig.countryCode, - merchantName = config.merchantDisplayName + merchantName = state.config.merchantDisplayName ) googlePayPaymentMethodLauncherFactory.create( diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandler.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandler.kt index 274551ca0cf..91df0746015 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandler.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandler.kt @@ -40,7 +40,7 @@ internal class FlowControllerConfigurationHandler @Inject constructor( fun configure( scope: CoroutineScope, initializationMode: PaymentSheet.InitializationMode, - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, callback: PaymentSheet.FlowController.ConfigCallback, ) { val oldJob = job.getAndSet( @@ -57,7 +57,7 @@ internal class FlowControllerConfigurationHandler @Inject constructor( private suspend fun configureInternal( initializationMode: PaymentSheet.InitializationMode, - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, callback: PaymentSheet.FlowController.ConfigCallback, ) { suspend fun onConfigured(error: Throwable? = null) { @@ -70,7 +70,7 @@ internal class FlowControllerConfigurationHandler @Inject constructor( try { initializationMode.validate() - configuration?.validate() + configuration.validate() } catch (e: InvalidParameterException) { onConfigured(error = e) return @@ -126,6 +126,6 @@ internal class FlowControllerConfigurationHandler @Inject constructor( data class ConfigureRequest( val initializationMode: PaymentSheet.InitializationMode, - val configuration: PaymentSheet.Configuration?, + val configuration: PaymentSheet.Configuration, ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/FormArgumentsFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/FormArgumentsFactory.kt index 6e994e7130c..857b1c32ba3 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/FormArgumentsFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/FormArgumentsFactory.kt @@ -17,7 +17,7 @@ internal object FormArgumentsFactory { fun create( paymentMethod: LpmRepository.SupportedPaymentMethod, stripeIntent: StripeIntent, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, merchantName: String, amount: Amount? = null, newLpm: PaymentSelection.New?, @@ -56,11 +56,10 @@ internal object FormArgumentsFactory { showCheckboxControlledFields = showCheckboxControlledFields, merchantName = merchantName, amount = amount, - billingDetails = config?.defaultBillingDetails, - shippingDetails = config?.shippingDetails, + billingDetails = config.defaultBillingDetails, + shippingDetails = config.shippingDetails, initialPaymentMethodCreateParams = initialParams, - billingDetailsCollectionConfiguration = config?.billingDetailsCollectionConfiguration - ?: PaymentSheet.BillingDetailsCollectionConfiguration(), + billingDetailsCollectionConfiguration = config.billingDetailsCollectionConfiguration, cbcEligibility = cbcEligibility, requiresMandate = paymentMethod.requiresMandate, requiredFields = paymentMethod.placeholderOverrideList, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetCommonModule.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetCommonModule.kt index a42adbf4f39..07d0fa8d876 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetCommonModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetCommonModule.kt @@ -1,6 +1,5 @@ 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.ENABLE_LOGGING @@ -11,7 +10,6 @@ import com.stripe.android.core.utils.DefaultDurationProvider import com.stripe.android.core.utils.DurationProvider import com.stripe.android.link.injection.LinkAnalyticsComponent import com.stripe.android.link.injection.LinkComponent -import com.stripe.android.payments.core.injection.APP_NAME import com.stripe.android.paymentsheet.BuildConfig import com.stripe.android.paymentsheet.DefaultIntentConfirmationInterceptor import com.stripe.android.paymentsheet.DefaultPrefsRepository @@ -122,16 +120,6 @@ internal abstract class PaymentSheetCommonModule { ) } - @Provides - @Singleton - @Named(APP_NAME) - fun provideAppName( - appContext: Context, - ): String { - val application = appContext as Application - return application.applicationInfo.loadLabel(application.packageManager).toString() - } - @Provides @Singleton fun provideDurationProvider(): DurationProvider { diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetViewModelModule.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetViewModelModule.kt index e7ce93983e8..d25a28d1bdb 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetViewModelModule.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/PaymentSheetViewModelModule.kt @@ -24,7 +24,7 @@ internal class PaymentSheetViewModelModule(private val starterArgs: PaymentSheet ): PrefsRepository { return DefaultPrefsRepository( appContext, - customerId = starterArgs.config?.customer?.id, + customerId = starterArgs.config.customer?.id, workContext = workContext ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodKtx.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodKtx.kt index 51a24754568..5ba3559b16c 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodKtx.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodKtx.kt @@ -28,7 +28,7 @@ import com.stripe.android.ui.core.forms.resources.LpmRepository.SupportedPayment */ internal fun SupportedPaymentMethod.getPMAddForm( stripeIntent: StripeIntent, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ) = requireNotNull(getSpecWithFullfilledRequirements(stripeIntent, config)) /** @@ -37,7 +37,7 @@ internal fun SupportedPaymentMethod.getPMAddForm( */ internal fun SupportedPaymentMethod.getSpecWithFullfilledRequirements( stripeIntent: StripeIntent, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ): LayoutFormDescriptor? { val formSpec = formSpec val oneTimeUse = LayoutFormDescriptor( @@ -99,7 +99,7 @@ internal fun SupportedPaymentMethod.getSpecWithFullfilledRequirements( * This checks to see if the payment method is supported from a SetupIntent. */ private fun SupportedPaymentMethod.supportsSetupIntent( - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ) = requirement.getConfirmPMFromCustomer(code) && checkSetupIntentRequirements(requirement.siRequirements, config) @@ -111,7 +111,7 @@ private fun SupportedPaymentMethod.supportsSetupIntent( */ private fun SupportedPaymentMethod.supportsPaymentIntentSfuSet( paymentIntent: PaymentIntent, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ) = requirement.getConfirmPMFromCustomer(code) && checkSetupIntentRequirements(requirement.siRequirements, config) && checkPaymentIntentRequirements(requirement.piRequirements, paymentIntent, config) @@ -122,7 +122,7 @@ private fun SupportedPaymentMethod.supportsPaymentIntentSfuSet( */ private fun SupportedPaymentMethod.supportsPaymentIntentSfuNotSettable( paymentIntent: PaymentIntent, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ) = checkPaymentIntentRequirements(requirement.piRequirements, paymentIntent, config) /** @@ -137,8 +137,8 @@ private fun SupportedPaymentMethod.supportsPaymentIntentSfuNotSettable( */ private fun SupportedPaymentMethod.supportsPaymentIntentSfuSettable( paymentIntent: PaymentIntent, - config: PaymentSheet.Configuration? -) = config?.customer != null && + config: PaymentSheet.Configuration +) = config.customer != null && requirement.getConfirmPMFromCustomer(code) && checkPaymentIntentRequirements(requirement.piRequirements, paymentIntent, config) && checkSetupIntentRequirements(requirement.siRequirements, config) @@ -148,11 +148,11 @@ private fun SupportedPaymentMethod.supportsPaymentIntentSfuSettable( */ private fun checkSetupIntentRequirements( requirements: Set?, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ): Boolean { return requirements?.map { requirement -> when (requirement) { - Delayed -> config?.allowsDelayedPaymentMethods == true + Delayed -> config.allowsDelayedPaymentMethods } }?.contains(false) == false } @@ -163,15 +163,15 @@ private fun checkSetupIntentRequirements( private fun checkPaymentIntentRequirements( requirements: Set?, paymentIntent: PaymentIntent, - config: PaymentSheet.Configuration? + config: PaymentSheet.Configuration ): Boolean { return requirements?.map { requirement -> when (requirement) { Delayed -> { - config?.allowsDelayedPaymentMethods == true + config.allowsDelayedPaymentMethods } ShippingAddress -> { - val forceAllow = config?.allowsPaymentMethodsRequiringShippingAddress == true + val forceAllow = config.allowsPaymentMethodsRequiringShippingAddress paymentIntent.containsValidShippingInfo || forceAllow } } @@ -190,7 +190,7 @@ private val PaymentIntent.containsValidShippingInfo: Boolean */ internal fun getSupportedSavedCustomerPMs( stripeIntent: StripeIntent?, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, lpmRepository: LpmRepository ) = stripeIntent?.paymentMethodTypes?.mapNotNull { lpmRepository.fromCode(it) @@ -201,7 +201,7 @@ internal fun getSupportedSavedCustomerPMs( internal fun getPMsToAdd( stripeIntent: StripeIntent?, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, lpmRepository: LpmRepository, isFinancialConnectionsAvailable: IsFinancialConnectionsAvailable = DefaultIsFinancialConnectionsAvailable() ) = stripeIntent?.paymentMethodTypes?.mapNotNull { 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 675f89bfdf1..4e12cd91335 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 @@ -11,7 +11,6 @@ import com.stripe.android.model.ElementsSession import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethod.Type.Link import com.stripe.android.model.StripeIntent -import com.stripe.android.payments.core.injection.APP_NAME import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.PaymentSheet.InitializationMode.DeferredIntent import com.stripe.android.paymentsheet.PrefsRepository @@ -33,7 +32,6 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.first import kotlinx.coroutines.withContext import javax.inject.Inject -import javax.inject.Named import javax.inject.Singleton import kotlin.coroutines.CoroutineContext @@ -45,13 +43,12 @@ internal interface PaymentSheetLoader { suspend fun load( initializationMode: PaymentSheet.InitializationMode, - paymentSheetConfiguration: PaymentSheet.Configuration? = null + paymentSheetConfiguration: PaymentSheet.Configuration ): Result } @Singleton internal class DefaultPaymentSheetLoader @Inject constructor( - @Named(APP_NAME) private val appName: String, private val prefsRepositoryFactory: @JvmSuppressWildcards (PaymentSheet.CustomerConfiguration?) -> PrefsRepository, private val googlePayRepositoryFactory: @JvmSuppressWildcards (GooglePayEnvironment) -> GooglePayRepository, private val elementsSessionRepository: ElementsSessionRepository, @@ -65,7 +62,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( override suspend fun load( initializationMode: PaymentSheet.InitializationMode, - paymentSheetConfiguration: PaymentSheet.Configuration? + paymentSheetConfiguration: PaymentSheet.Configuration ): Result = withContext(workContext) { val isDecoupling = initializationMode is DeferredIntent @@ -86,14 +83,14 @@ internal class DefaultPaymentSheetLoader @Inject constructor( } private suspend fun isGooglePayReady( - paymentSheetConfiguration: PaymentSheet.Configuration?, + paymentSheetConfiguration: PaymentSheet.Configuration, elementsSession: ElementsSession, ): Boolean { return elementsSession.isGooglePayEnabled && paymentSheetConfiguration.isGooglePayReady() } - private suspend fun PaymentSheet.Configuration?.isGooglePayReady(): Boolean { - return this?.googlePay?.environment?.let { environment -> + private suspend fun PaymentSheet.Configuration.isGooglePayReady(): Boolean { + return googlePay?.environment?.let { environment -> googlePayRepositoryFactory( when (environment) { PaymentSheet.GooglePayConfiguration.Environment.Production -> @@ -107,10 +104,10 @@ internal class DefaultPaymentSheetLoader @Inject constructor( private suspend fun create( elementsSession: ElementsSession, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, isGooglePayReady: Boolean, ): PaymentSheetState.Full = coroutineScope { - val customerConfig = config?.customer + val customerConfig = config.customer val prefsRepository = prefsRepositoryFactory(customerConfig) val stripeIntent = elementsSession.stripeIntent @@ -202,7 +199,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( private suspend fun retrieveCustomerPaymentMethods( stripeIntent: StripeIntent, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, customerConfig: PaymentSheet.CustomerConfiguration, ): List { val paymentMethodTypes = getSupportedSavedCustomerPMs( @@ -228,12 +225,11 @@ internal class DefaultPaymentSheetLoader @Inject constructor( private suspend fun retrieveElementsSession( initializationMode: PaymentSheet.InitializationMode, - configuration: PaymentSheet.Configuration?, + configuration: PaymentSheet.Configuration, ): Result { return elementsSessionRepository.get(initializationMode).mapCatching { elementsSession -> val billingDetailsCollectionConfig = - configuration?.billingDetailsCollectionConfiguration?.toInternal() - ?: BillingDetailsCollectionConfiguration() + configuration.billingDetailsCollectionConfiguration.toInternal() val didParseServerResponse = lpmRepository.update( stripeIntent = elementsSession.stripeIntent, @@ -253,7 +249,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( } private suspend fun loadLinkState( - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, stripeIntent: StripeIntent, merchantCountry: String?, passthroughModeEnabled: Boolean, @@ -280,17 +276,17 @@ internal class DefaultPaymentSheetLoader @Inject constructor( } private suspend fun createLinkConfiguration( - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, stripeIntent: StripeIntent, merchantCountry: String?, passthroughModeEnabled: Boolean, ): LinkConfiguration { - val shippingDetails: AddressDetails? = config?.shippingDetails + val shippingDetails: AddressDetails? = config.shippingDetails val customerPhone = if (shippingDetails?.isCheckboxSelected == true) { shippingDetails.phoneNumber } else { - config?.defaultBillingDetails?.phone + config.defaultBillingDetails?.phone } val shippingAddress = if (shippingDetails?.isCheckboxSelected == true) { @@ -299,14 +295,14 @@ internal class DefaultPaymentSheetLoader @Inject constructor( null } - val customerEmail = config?.defaultBillingDetails?.email ?: config?.customer?.let { + val customerEmail = config.defaultBillingDetails?.email ?: config.customer?.let { customerRepository.retrieveCustomer( it.id, it.ephemeralKeySecret ) }?.email - val merchantName = config?.merchantDisplayName ?: appName + val merchantName = config.merchantDisplayName return LinkConfiguration( stripeIntent = stripeIntent, @@ -314,8 +310,8 @@ internal class DefaultPaymentSheetLoader @Inject constructor( merchantCountryCode = merchantCountry, customerEmail = customerEmail, customerPhone = customerPhone, - customerName = config?.defaultBillingDetails?.name, - customerBillingCountryCode = config?.defaultBillingDetails?.address?.country, + customerName = config.defaultBillingDetails?.name, + customerBillingCountryCode = config.defaultBillingDetails?.address?.country, shippingValues = shippingAddress, passthroughModeEnabled = passthroughModeEnabled, ) @@ -338,7 +334,7 @@ internal class DefaultPaymentSheetLoader @Inject constructor( private fun supportsIntent( stripeIntent: StripeIntent, - config: PaymentSheet.Configuration?, + config: PaymentSheet.Configuration, ): Boolean { val availablePaymentMethods = getPMsToAdd(stripeIntent, config, lpmRepository) val requestedTypes = stripeIntent.paymentMethodTypes.toSet() 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 2cd4294fe0f..465e3378b27 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 @@ -14,7 +14,7 @@ internal sealed interface PaymentSheetState : Parcelable { @Parcelize data class Full( - val config: PaymentSheet.Configuration?, + val config: PaymentSheet.Configuration, val stripeIntent: StripeIntent, val customerPaymentMethods: List, val isGooglePayReady: Boolean, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt index bb609ef62a4..22722d77332 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt @@ -124,7 +124,7 @@ internal fun AddPaymentMethod( isPaymentFlow = stripeIntent.value is PaymentIntent, stripeIntentId = stripeIntent.value?.id, clientSecret = stripeIntent.value?.clientSecret, - shippingDetails = sheetViewModel.config?.shippingDetails, + shippingDetails = sheetViewModel.config.shippingDetails, draftPaymentSelection = sheetViewModel.newPaymentSelection, onMandateTextChanged = sheetViewModel::updateMandateText, onConfirmUSBankAccount = sheetViewModel::handleConfirmUSBankAccount, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButtonContainerFragment.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButtonContainerFragment.kt index d3bdd8762da..bf44f4c3e20 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButtonContainerFragment.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButtonContainerFragment.kt @@ -46,7 +46,7 @@ internal abstract class BasePrimaryButtonContainerFragment : Fragment() { @Suppress("DEPRECATION") viewBinding.primaryButton.setAppearanceConfiguration( StripeTheme.primaryButtonStyle, - tintList = viewModel.config?.primaryButtonColor ?: ColorStateList.valueOf( + tintList = viewModel.config.primaryButtonColor ?: ColorStateList.valueOf( StripeTheme.primaryButtonStyle.getBackgroundColor(requireActivity().baseContext) ) ) 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 f17fc69a751..8160cde3951 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 @@ -71,7 +71,7 @@ import kotlin.coroutines.CoroutineContext @Suppress("TooManyFunctions") internal abstract class BaseSheetViewModel( application: Application, - internal val config: PaymentSheet.Configuration?, + internal val config: PaymentSheet.Configuration, internal val eventReporter: EventReporter, protected val customerRepository: CustomerRepository, protected val prefsRepository: PrefsRepository, @@ -86,9 +86,8 @@ internal abstract class BaseSheetViewModel( private val editInteractorFactory: ModifiableEditPaymentMethodViewInteractor.Factory ) : AndroidViewModel(application) { - internal val customerConfig = config?.customer - internal val merchantName = config?.merchantDisplayName - ?: application.applicationInfo.loadLabel(application.packageManager).toString() + internal val customerConfig = config.customer + internal val merchantName = config.merchantDisplayName protected var mostRecentError: Throwable? = null protected var cbcEligibility: CardBrandChoiceEligibility = CardBrandChoiceEligibility.Ineligible diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapper.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapper.kt index 55dc9c8477d..ea39d1f4c96 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapper.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapper.kt @@ -13,7 +13,7 @@ import com.stripe.android.ui.core.R as StripeUiCoreR internal class PrimaryButtonUiStateMapper( private val context: Context, - private val config: PaymentSheet.Configuration?, + private val config: PaymentSheet.Configuration, private val isProcessingPayment: Boolean, private val currentScreenFlow: Flow, private val buttonsEnabledFlow: Flow, @@ -59,7 +59,7 @@ internal class PrimaryButtonUiStateMapper( } private fun buyButtonLabel(amount: Amount?): String { - return if (config?.primaryButtonLabel != null) { + return if (config.primaryButtonLabel != null) { config.primaryButtonLabel } else if (isProcessingPayment) { val fallback = context.getString(R.string.stripe_paymentsheet_pay_button_label) @@ -70,7 +70,7 @@ internal class PrimaryButtonUiStateMapper( } private fun continueButtonLabel(): String { - val customLabel = config?.primaryButtonLabel + val customLabel = config.primaryButtonLabel return customLabel ?: context.getString(StripeUiCoreR.string.stripe_continue_button_label) } } 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 19294d4d026..5606e9b06c2 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsViewModelTest.kt @@ -516,7 +516,7 @@ internal class PaymentOptionsViewModelTest { fun `Doesn't consider unsupported payment methods in header text creation`() = runTest { val args = PAYMENT_OPTION_CONTRACT_ARGS.copy( state = PAYMENT_OPTION_CONTRACT_ARGS.state.copy( - config = PAYMENT_OPTION_CONTRACT_ARGS.state.config?.copy( + config = PAYMENT_OPTION_CONTRACT_ARGS.state.config.copy( allowsDelayedPaymentMethods = false, ), isGooglePayReady = 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 b491da722b1..5761887cc3a 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt @@ -845,7 +845,9 @@ internal class PaymentSheetActivityTest { fun `Handles invalid client secret correctly`() { val args = PaymentSheetContractV2.Args( initializationMode = PaymentSheet.InitializationMode.PaymentIntent(clientSecret = ""), - config = null, + config = PaymentSheet.Configuration( + merchantDisplayName = "Some name", + ), statusBarColor = null, ) 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 ef88e6a5986..fb774b8a4f3 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt @@ -121,7 +121,7 @@ internal object PaymentSheetFixtures { paymentMethods: List = state.customerPaymentMethods, isGooglePayReady: Boolean = state.isGooglePayReady, stripeIntent: StripeIntent = state.stripeIntent, - config: PaymentSheet.Configuration? = state.config, + config: PaymentSheet.Configuration = state.config, paymentSelection: PaymentSelection? = state.paymentSelection, linkState: LinkState? = state.linkState, ): PaymentOptionContract.Args { @@ -162,18 +162,9 @@ internal object PaymentSheetFixtures { STATUS_BAR_COLOR ) - internal val ARGS_WITHOUT_CONFIG - get() = PaymentSheetContractV2.Args( - initializationMode = PaymentSheet.InitializationMode.PaymentIntent( - clientSecret = PAYMENT_INTENT_CLIENT_SECRET.value, - ), - config = null, - STATUS_BAR_COLOR - ) - internal val ARGS_WITHOUT_CUSTOMER get() = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( customer = null ) ) 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 1b193cff972..5173824037f 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt @@ -280,7 +280,7 @@ internal class PaymentSheetViewModelTest { createViewModel( stripeIntent = stripeIntent, args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( shippingDetails = AddressDetails( address = PaymentSheet.Address( country = "US" @@ -599,7 +599,7 @@ internal class PaymentSheetViewModelTest { fun `Verify supported payment methods exclude afterpay if no shipping and no allow flag`() { val viewModel = createViewModel( args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( shippingDetails = null, allowsPaymentMethodsRequiringShippingAddress = false, ) @@ -617,7 +617,7 @@ internal class PaymentSheetViewModelTest { fun `Verify supported payment methods include afterpay if allow flag but no shipping`() { val viewModel = createViewModel( args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( allowsPaymentMethodsRequiringShippingAddress = true, ) ), @@ -635,7 +635,7 @@ internal class PaymentSheetViewModelTest { fun `Verify supported payment methods include afterpay if shipping but no allow flag`() { val viewModel = createViewModel( args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( allowsPaymentMethodsRequiringShippingAddress = false, ) ), @@ -689,17 +689,6 @@ internal class PaymentSheetViewModelTest { .isFalse() } - @Test - fun `When configuration is empty, merchant name should reflect the app name`() { - val viewModel = createViewModel( - args = ARGS_WITHOUT_CUSTOMER - ) - - // In a real app, the app name will be used. In tests the package name is returned. - assertThat(viewModel.merchantName) - .isEqualTo("com.stripe.android.paymentsheet.test") - } - @Test fun `getSupportedPaymentMethods() filters payment methods with delayed settlement`() { val viewModel = createViewModel( @@ -1222,7 +1211,7 @@ internal class PaymentSheetViewModelTest { val viewModel = createViewModel( isGooglePayReady = true, args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( allowsDelayedPaymentMethods = true, ), ), @@ -1557,7 +1546,7 @@ internal class PaymentSheetViewModelTest { val expectedAmount = 1099L val args = ARGS_CUSTOMER_WITH_GOOGLEPAY.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY.config.copy( googlePay = PaymentSheet.GooglePayConfiguration( environment = PaymentSheet.GooglePayConfiguration.Environment.Test, countryCode = "CA", @@ -1594,7 +1583,7 @@ internal class PaymentSheetViewModelTest { val expectedAmount = 1234L val args = ARGS_CUSTOMER_WITH_GOOGLEPAY_SETUP.copy( - config = ARGS_CUSTOMER_WITH_GOOGLEPAY_SETUP.config?.copy( + config = ARGS_CUSTOMER_WITH_GOOGLEPAY_SETUP.config.copy( googlePay = PaymentSheet.GooglePayConfiguration( environment = PaymentSheet.GooglePayConfiguration.Environment.Test, countryCode = "CA", @@ -1837,7 +1826,7 @@ internal class PaymentSheetViewModelTest { private val ARGS_CUSTOMER_WITH_GOOGLEPAY_SETUP = PaymentSheetFixtures.ARGS_CUSTOMER_WITH_GOOGLEPAY_SETUP private val ARGS_CUSTOMER_WITH_GOOGLEPAY = PaymentSheetFixtures.ARGS_CUSTOMER_WITH_GOOGLEPAY - private val ARGS_WITHOUT_CUSTOMER = PaymentSheetFixtures.ARGS_WITHOUT_CONFIG + private val ARGS_WITHOUT_CUSTOMER = PaymentSheetFixtures.ARGS_WITHOUT_CUSTOMER private val PAYMENT_METHODS = listOf(PaymentMethodFixtures.CARD_PAYMENT_METHOD) 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 890e48dd219..9a08a075302 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 @@ -394,7 +394,7 @@ internal class DefaultFlowControllerTest { state = PaymentSheetState.Full( stripeIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD, customerPaymentMethods = emptyList(), - config = null, + config = PaymentSheet.Configuration("com.stripe.android.paymentsheet.test"), isGooglePayReady = false, paymentSelection = null, linkState = null, @@ -1579,6 +1579,7 @@ internal class DefaultFlowControllerTest { ), paymentOptionCallback = paymentOptionCallback, paymentResultCallback = paymentResultCallback, + context = context, eventReporter = eventReporter, viewModel = viewModel, paymentLauncherFactory = paymentLauncherAssistedFactory, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandlerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandlerTest.kt index ec0f1c8fd52..565c60cac66 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandlerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerConfigurationHandlerTest.kt @@ -36,10 +36,10 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mockito.isNull import org.mockito.Mockito.mock import org.mockito.Mockito.never import org.mockito.Mockito.verify +import org.mockito.kotlin.any import org.mockito.kotlin.eq import org.robolectric.RobolectricTestRunner import kotlin.time.Duration.Companion.seconds @@ -319,7 +319,7 @@ class FlowControllerConfigurationHandlerTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.CLIENT_SECRET, ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), ) { _, _ -> onInitCallbacks++ } @@ -353,7 +353,7 @@ class FlowControllerConfigurationHandlerTest { ) ) ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), callback = { _, _ -> resultTurbine.add(amount) }, @@ -380,7 +380,7 @@ class FlowControllerConfigurationHandlerTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.CLIENT_SECRET, ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), callback = { _, _ -> resultTurbine.add(Unit) }, @@ -404,7 +404,7 @@ class FlowControllerConfigurationHandlerTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.CLIENT_SECRET, ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), ) { _, exception -> resultTurbine.add(exception) } @@ -421,7 +421,7 @@ class FlowControllerConfigurationHandlerTest { configurationHandler.configure( scope = this, initializationMode = PaymentSheet.InitializationMode.PaymentIntent("pi_123_sk_456"), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), ) { _, _ -> configureTurbine.close() } @@ -429,7 +429,7 @@ class FlowControllerConfigurationHandlerTest { configureTurbine.awaitComplete() verify(eventReporter).onInit( - configuration = isNull(), + configuration = any(), isDecoupling = eq(false), ) } @@ -453,7 +453,7 @@ class FlowControllerConfigurationHandlerTest { ), ), ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), ) { _, _ -> configureTurbine.close() } @@ -461,7 +461,7 @@ class FlowControllerConfigurationHandlerTest { configureTurbine.awaitComplete() verify(eventReporter).onInit( - configuration = isNull(), + configuration = any(), isDecoupling = eq(true), ) } @@ -486,7 +486,7 @@ class FlowControllerConfigurationHandlerTest { ), ), ), - configuration = null, + configuration = PaymentSheet.Configuration("Some name"), ) { _, _ -> configureTurbine.close() } @@ -494,7 +494,7 @@ class FlowControllerConfigurationHandlerTest { configureTurbine.awaitComplete() verify(eventReporter).onInit( - configuration = isNull(), + configuration = any(), isDecoupling = eq(true), ) } 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 c9f4cf8b5a2..55b63e815dc 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 @@ -22,6 +22,8 @@ import com.stripe.android.ui.core.R as StripeUiCoreR @RunWith(RobolectricTestRunner::class) class PaymentSelectionUpdaterTest { + private val defaultPaymentSheetConfiguration: PaymentSheet.Configuration = PaymentSheet.Configuration("Some name") + @Test fun `Uses new payment selection if there's no existing one`() { val newState = mockPaymentSheetStateWithPaymentIntent(paymentSelection = PaymentSelection.GooglePay) @@ -83,7 +85,7 @@ class PaymentSelectionUpdaterTest { val result = updater( currentSelection = existingSelection, - previousConfig = null, + previousConfig = defaultPaymentSheetConfiguration, newState = newState, ) assertThat(result).isEqualTo(existingSelection) @@ -198,7 +200,7 @@ class PaymentSelectionUpdaterTest { val result = updater( currentSelection = existingSelection, - previousConfig = null, + previousConfig = defaultPaymentSheetConfiguration, newState = newState, ) @@ -233,7 +235,7 @@ class PaymentSelectionUpdaterTest { val result = updater( currentSelection = existingSelection, - previousConfig = null, + previousConfig = defaultPaymentSheetConfiguration, newState = newState, ) @@ -244,7 +246,7 @@ class PaymentSelectionUpdaterTest { paymentMethodTypes: List? = null, paymentSelection: PaymentSelection? = null, customerPaymentMethods: List = emptyList(), - config: PaymentSheet.Configuration? = null, + config: PaymentSheet.Configuration = PaymentSheet.Configuration("Some name"), ): PaymentSheetState.Full { val intent = PAYMENT_INTENT @@ -265,7 +267,7 @@ class PaymentSelectionUpdaterTest { paymentMethodTypes: List? = null, paymentSelection: PaymentSelection? = null, customerPaymentMethods: List = emptyList(), - config: PaymentSheet.Configuration? = null, + config: PaymentSheet.Configuration = defaultPaymentSheetConfiguration, ): PaymentSheetState.Full { val intent = SETUP_INTENT diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodTest.kt index 55a5fdbc099..22610119081 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/model/SupportedPaymentMethodTest.kt @@ -122,7 +122,7 @@ class SupportedPaymentMethodTest { val expected = listOf().plus(card) - assertThat(getPMsToAdd(mockIntent, null, lpmRepository)).isEqualTo(expected) + assertThat(getPMsToAdd(mockIntent, PaymentSheet.Configuration("Some Name"), lpmRepository)).isEqualTo(expected) } @Test @@ -147,7 +147,7 @@ class SupportedPaymentMethodTest { val expected = listOf().plus(card) - assertThat(getPMsToAdd(mockIntent, null, lpmRepository)).isEqualTo(expected) + assertThat(getPMsToAdd(mockIntent, PaymentSheet.Configuration("Some Name"), lpmRepository)).isEqualTo(expected) } @Test @@ -172,7 +172,7 @@ class SupportedPaymentMethodTest { val expected = listOf() - assertThat(getPMsToAdd(mockIntent, null, lpmRepository)).isEqualTo(expected) + assertThat(getPMsToAdd(mockIntent, PaymentSheet.Configuration("Some Name"), lpmRepository)).isEqualTo(expected) } @Test @@ -197,7 +197,7 @@ class SupportedPaymentMethodTest { val expected = listOf().plus(card) - assertThat(getPMsToAdd(mockIntent, null, lpmRepository)).isEqualTo(expected) + assertThat(getPMsToAdd(mockIntent, PaymentSheet.Configuration("Some Name"), lpmRepository)).isEqualTo(expected) } @Test @@ -347,11 +347,11 @@ class SupportedPaymentMethodTest { } fun getConfig() = if (hasCustomer) { - PaymentSheetFixtures.ARGS_CUSTOMER_WITHOUT_GOOGLEPAY.config?.copy( + PaymentSheetFixtures.ARGS_CUSTOMER_WITHOUT_GOOGLEPAY.config.copy( allowsDelayedPaymentMethods = allowsDelayedPayment ) } else { - PaymentSheetFixtures.ARGS_WITHOUT_CUSTOMER.config?.copy( + PaymentSheetFixtures.ARGS_WITHOUT_CUSTOMER.config.copy( allowsDelayedPaymentMethods = allowsDelayedPayment ) } 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 0a56711bac1..fded16cc699 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 @@ -416,6 +416,7 @@ internal class DefaultPaymentSheetLoaderTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.PAYMENT_INTENT_CLIENT_SECRET.value, ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ).exceptionOrNull() assertThat(result).isEqualTo(PaymentSheetLoadingException.InvalidConfirmationMethod(Manual)) @@ -642,6 +643,7 @@ internal class DefaultPaymentSheetLoaderTest { val result = loader.load( initializationMode = PaymentSheet.InitializationMode.PaymentIntent("secret"), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ).exceptionOrNull() assertThat(result).isEqualTo( @@ -658,6 +660,7 @@ internal class DefaultPaymentSheetLoaderTest { loader.load( initializationMode = PaymentSheet.InitializationMode.PaymentIntent("secret"), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ) verify(eventReporter).onLoadStarted(isDecoupling = false) @@ -677,6 +680,7 @@ internal class DefaultPaymentSheetLoaderTest { ), ), ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ) verify(eventReporter).onLoadStarted(isDecoupling = true) @@ -690,6 +694,7 @@ internal class DefaultPaymentSheetLoaderTest { loader.load( initializationMode = PaymentSheet.InitializationMode.PaymentIntent("secret"), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ) verify(eventReporter).onLoadStarted(isDecoupling = false) @@ -714,6 +719,7 @@ internal class DefaultPaymentSheetLoaderTest { ), ), ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ) verify(eventReporter).onLoadStarted(isDecoupling = true) @@ -741,6 +747,7 @@ internal class DefaultPaymentSheetLoaderTest { ), ), ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ) verify(eventReporter).onLoadStarted(isDecoupling = true) @@ -759,6 +766,7 @@ internal class DefaultPaymentSheetLoaderTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.PAYMENT_INTENT_CLIENT_SECRET.value, ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ).getOrThrow() assertThat(result.isEligibleForCardBrandChoice).isFalse() @@ -774,6 +782,7 @@ internal class DefaultPaymentSheetLoaderTest { initializationMode = PaymentSheet.InitializationMode.PaymentIntent( clientSecret = PaymentSheetFixtures.PAYMENT_INTENT_CLIENT_SECRET.value, ), + paymentSheetConfiguration = PaymentSheet.Configuration("Some Name"), ).getOrThrow() assertThat(result.isEligibleForCardBrandChoice).isTrue() @@ -789,7 +798,6 @@ internal class DefaultPaymentSheetLoaderTest { isGooglePayEnabledFromBackend: Boolean = true, ): PaymentSheetLoader { return DefaultPaymentSheetLoader( - appName = "App Name", prefsRepositoryFactory = { prefsRepository }, googlePayRepositoryFactory = { if (isGooglePayReady) readyGooglePayRepository else unreadyGooglePayRepository diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapperTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapperTest.kt index 12bb54cd534..fce89e3d8ff 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapperTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/viewmodels/PrimaryButtonUiStateMapperTest.kt @@ -186,7 +186,7 @@ class PrimaryButtonUiStateMapperTest { private fun createMapper( isProcessingPayment: Boolean, - config: PaymentSheet.Configuration? = null, + config: PaymentSheet.Configuration = PaymentSheet.Configuration("Some Name"), currentScreenFlow: Flow, buttonsEnabledFlow: Flow, amountFlow: Flow = flowOf(null), 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 9da6a527c28..1b3a1fa981b 100644 --- a/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt +++ b/paymentsheet/src/test/java/com/stripe/android/utils/FakePaymentSheetLoader.kt @@ -30,7 +30,7 @@ internal class FakePaymentSheetLoader( override suspend fun load( initializationMode: PaymentSheet.InitializationMode, - paymentSheetConfiguration: PaymentSheet.Configuration? + paymentSheetConfiguration: PaymentSheet.Configuration ): Result { delay(delay) return if (shouldFail) { 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 31c0d52eb13..05624d3d39c 100644 --- a/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt +++ b/paymentsheet/src/test/java/com/stripe/android/utils/RelayingPaymentSheetLoader.kt @@ -19,7 +19,7 @@ internal class RelayingPaymentSheetLoader : PaymentSheetLoader { PaymentSheetState.Full( stripeIntent = stripeIntent, customerPaymentMethods = emptyList(), - config = null, + config = PaymentSheet.Configuration("Example"), isGooglePayReady = false, paymentSelection = null, linkState = null, @@ -40,7 +40,7 @@ internal class RelayingPaymentSheetLoader : PaymentSheetLoader { override suspend fun load( initializationMode: PaymentSheet.InitializationMode, - paymentSheetConfiguration: PaymentSheet.Configuration? + paymentSheetConfiguration: PaymentSheet.Configuration ): Result { return results.receive() }