diff --git a/CHANGELOG.md b/CHANGELOG.md index f091932008e..52773cd9b6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### PaymentSheet * [FIXED][7584](https://github.com/stripe/stripe-android/pull/7584) Fixed an issue where PaymentSheet would render with a lightened surface color in dark mode. * [FIXED][7635](https://github.com/stripe/stripe-android/pull/7635) Fixed an issue where PaymentSheet wouldn't accept valid Mexican phone numbers. +* [CHANGED][7627](https://github.com/stripe/stripe-android/pull/7627) Updated the experimental CustomerSheet.Configuration to require a merchant name. ## 20.34.4 - 2023-11-02 diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/CustomerSheetExampleActivity.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/CustomerSheetExampleActivity.kt index eaefd5c445d..0dc3c102fd3 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/CustomerSheetExampleActivity.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/CustomerSheetExampleActivity.kt @@ -98,7 +98,7 @@ internal class CustomerSheetExampleActivity : AppCompatActivity() { } private fun buildConfig(): CustomerSheet.Configuration { - return CustomerSheet.Configuration.builder() + return CustomerSheet.Configuration.builder(merchantDisplayName = "Payment Sheet Example") .defaultBillingDetails( PaymentSheet.BillingDetails( name = "CustomerSheet Testing" diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt index 5308e12dcfb..bd11cab0bdc 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt @@ -54,7 +54,9 @@ class CustomerSheetPlaygroundViewModel( private val _configurationState = MutableStateFlow(CustomerSheetPlaygroundConfigurationState()) val configurationState: StateFlow = _configurationState - private val initialConfiguration = CustomerSheet.Configuration.builder() + private val initialConfiguration = CustomerSheet.Configuration.builder( + merchantDisplayName = "Payment Sheet Example" + ) .defaultBillingDetails( PaymentSheet.BillingDetails( name = "CustomerSheet Testing" diff --git a/paymentsheet/api/paymentsheet.api b/paymentsheet/api/paymentsheet.api index 8f1d4d87a22..558fd76713d 100644 --- a/paymentsheet/api/paymentsheet.api +++ b/paymentsheet/api/paymentsheet.api @@ -88,7 +88,7 @@ public final class com/stripe/android/customersheet/CustomerSheet$Companion { public final class com/stripe/android/customersheet/CustomerSheet$Configuration { public static final field $stable I public static final field Companion Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Companion; - public static final fun builder ()Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; + public static final fun builder (Ljava/lang/String;)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; public final fun getAppearance ()Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance; public final fun getBillingDetailsCollectionConfiguration ()Lcom/stripe/android/paymentsheet/PaymentSheet$BillingDetailsCollectionConfiguration; public final fun getDefaultBillingDetails ()Lcom/stripe/android/paymentsheet/PaymentSheet$BillingDetails; @@ -106,15 +106,14 @@ public final class com/stripe/android/customersheet/CustomerSheet$Configuration$ public final fun defaultBillingDetails (Lcom/stripe/android/paymentsheet/PaymentSheet$BillingDetails;)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; public final fun googlePayEnabled (Z)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; public final fun headerTextForSelectionScreen (Ljava/lang/String;)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; - public final fun merchantDisplayName (Ljava/lang/String;)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; } public final class com/stripe/android/customersheet/CustomerSheet$Configuration$Companion { - public final fun builder ()Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; + public final fun builder (Ljava/lang/String;)Lcom/stripe/android/customersheet/CustomerSheet$Configuration$Builder; } public final class com/stripe/android/customersheet/CustomerSheetComposeKt { - public static final fun rememberCustomerSheet (Lcom/stripe/android/customersheet/CustomerSheet$Configuration;Lcom/stripe/android/customersheet/CustomerAdapter;Lcom/stripe/android/customersheet/CustomerSheetResultCallback;Landroidx/compose/runtime/Composer;II)Lcom/stripe/android/customersheet/CustomerSheet; + public static final fun rememberCustomerSheet (Lcom/stripe/android/customersheet/CustomerSheet$Configuration;Lcom/stripe/android/customersheet/CustomerAdapter;Lcom/stripe/android/customersheet/CustomerSheetResultCallback;Landroidx/compose/runtime/Composer;I)Lcom/stripe/android/customersheet/CustomerSheet; } public abstract class com/stripe/android/customersheet/CustomerSheetResult { diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheet.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheet.kt index 7f87b8c854b..ab35760968e 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheet.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheet.kt @@ -159,34 +159,33 @@ class CustomerSheet @Inject internal constructor( /** * Your customer-facing business name. The default value is the name of your app. */ - val merchantDisplayName: String? = null, + val merchantDisplayName: String, // TODO(tillh-stripe) Add docs internal val preferredNetworks: List = emptyList(), ) { // Hide no-argument constructor init - internal constructor() : this( + internal constructor(merchantDisplayName: String) : this( appearance = PaymentSheet.Appearance(), googlePayEnabled = false, headerTextForSelectionScreen = null, defaultBillingDetails = PaymentSheet.BillingDetails(), billingDetailsCollectionConfiguration = PaymentSheet.BillingDetailsCollectionConfiguration(), - merchantDisplayName = null, + merchantDisplayName = merchantDisplayName, ) fun newBuilder(): Builder { - return Builder() + return Builder(merchantDisplayName) .appearance(appearance) .googlePayEnabled(googlePayEnabled) .headerTextForSelectionScreen(headerTextForSelectionScreen) .defaultBillingDetails(defaultBillingDetails) .billingDetailsCollectionConfiguration(billingDetailsCollectionConfiguration) - .merchantDisplayName(merchantDisplayName) } @ExperimentalCustomerSheetApi - class Builder internal constructor() { + class Builder internal constructor(private val merchantDisplayName: String) { private var appearance: PaymentSheet.Appearance = PaymentSheet.Appearance() private var googlePayEnabled: Boolean = false private var headerTextForSelectionScreen: String? = null @@ -194,7 +193,6 @@ class CustomerSheet @Inject internal constructor( private var billingDetailsCollectionConfiguration: PaymentSheet.BillingDetailsCollectionConfiguration = PaymentSheet.BillingDetailsCollectionConfiguration() - private var merchantDisplayName: String? = null private var preferredNetworks: List = emptyList() fun appearance(appearance: PaymentSheet.Appearance) = apply { @@ -219,10 +217,6 @@ class CustomerSheet @Inject internal constructor( this.billingDetailsCollectionConfiguration = configuration } - fun merchantDisplayName(name: String?) = apply { - this.merchantDisplayName = name - } - // TODO(tillh-stripe): Make this function public prior to release @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun preferredNetworks( @@ -245,8 +239,8 @@ class CustomerSheet @Inject internal constructor( companion object { @JvmStatic - fun builder(): Builder { - return Builder() + fun builder(merchantDisplayName: String): Builder { + return Builder(merchantDisplayName) } } } diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetCompose.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetCompose.kt index 0ebbf47cb29..0c3ad37c6dc 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetCompose.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetCompose.kt @@ -19,7 +19,7 @@ import com.stripe.android.utils.rememberActivityOrNull @ExperimentalCustomerSheetApi @Composable fun rememberCustomerSheet( - configuration: CustomerSheet.Configuration = CustomerSheet.Configuration(), + configuration: CustomerSheet.Configuration, customerAdapter: CustomerAdapter, callback: CustomerSheetResultCallback, ): CustomerSheet { 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 136a636b54a..9e7f56e294f 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -111,9 +111,6 @@ internal class CustomerSheetViewModel @Inject constructor( billingDetailsCollectionConfiguration = configuration.billingDetailsCollectionConfiguration.toInternal() ) - private val merchantName = configuration.merchantDisplayName - ?: application.applicationInfo.loadLabel(application.packageManager).toString() - init { configuration.appearance.parseAppearance() @@ -365,8 +362,7 @@ internal class CustomerSheetViewModel @Inject constructor( formArguments = FormArgumentsFactory.create( paymentMethod = paymentMethod, configuration = configuration, - merchantName = configuration.merchantDisplayName - ?: application.applicationInfo.loadLabel(application.packageManager).toString(), + merchantName = configuration.merchantDisplayName, cbcEligibility = it.cbcEligibility, ), selectedPaymentMethod = paymentMethod, @@ -384,7 +380,7 @@ internal class CustomerSheetViewModel @Inject constructor( }, mandateText = it.draftPaymentSelection?.mandateText( context = application, - merchantName = merchantName, + merchantName = configuration.merchantDisplayName, isSaveForFutureUseSelected = false, isSetupFlow = true, ), @@ -536,7 +532,7 @@ internal class CustomerSheetViewModel @Inject constructor( ), mandateText = paymentSelection.mandateText( context = application, - merchantName = merchantName, + merchantName = configuration.merchantDisplayName, isSaveForFutureUseSelected = false, isSetupFlow = true, )?.takeIf { primaryButtonVisible }, @@ -625,7 +621,7 @@ internal class CustomerSheetViewModel @Inject constructor( val formArguments = FormArgumentsFactory.create( paymentMethod = card, configuration = configuration, - merchantName = merchantName, + merchantName = configuration.merchantDisplayName, cbcEligibility = cbcEligibility, ) diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerAdapterTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerAdapterTest.kt index a3ebfa0f9fa..56682d6ed58 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerAdapterTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerAdapterTest.kt @@ -655,6 +655,7 @@ class CustomerAdapterTest { application = application ).createCustomerSessionComponent( configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true ), customerAdapter = adapter, @@ -686,6 +687,7 @@ class CustomerAdapterTest { application = application ).createCustomerSessionComponent( configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = false ), customerAdapter = adapter, diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSessionViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSessionViewModelTest.kt index cf4756ee1a2..88f8ea42463 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSessionViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSessionViewModelTest.kt @@ -31,7 +31,7 @@ class CustomerSessionViewModelTest { publishableKey = "ek_123", ) val component1 = viewModel.createCustomerSessionComponent( - configuration = CustomerSheet.Configuration(), + configuration = CustomerSheet.Configuration(merchantDisplayName = "Example"), customerAdapter = CustomerAdapter.create( context = application, customerEphemeralKeyProvider = { @@ -50,6 +50,7 @@ class CustomerSessionViewModelTest { val component2 = viewModel.createCustomerSessionComponent( configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true ), customerAdapter = CustomerAdapter.create( @@ -77,6 +78,7 @@ class CustomerSessionViewModelTest { val callback = mock() val component1 = viewModel.createCustomerSessionComponent( configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = false, ), customerAdapter = customerAdapter, @@ -86,6 +88,7 @@ class CustomerSessionViewModelTest { val component2 = viewModel.createCustomerSessionComponent( configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true, ), customerAdapter = customerAdapter, diff --git a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetConfigurationTest.kt b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetConfigurationTest.kt index 79d3f5e2cf0..05d2bf8e1ef 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetConfigurationTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetConfigurationTest.kt @@ -27,9 +27,8 @@ class CustomerSheetConfigurationTest { val headerTextForSelectionScreen = "Test" val preferredNetworks = listOf(CardBrand.AmericanExpress) - val configuration = CustomerSheet.Configuration.builder() + val configuration = CustomerSheet.Configuration.builder(merchantDisplayName) .googlePayEnabled(googlePayEnabled) - .merchantDisplayName(merchantDisplayName) .appearance(appearance) .billingDetailsCollectionConfiguration(billingDetailsCollectionConfiguration) .defaultBillingDetails(defaultBillingDetails) @@ -54,7 +53,7 @@ class CustomerSheetConfigurationTest { @Test fun `newBuilder returns a new builder with previous configuration`() { - val configuration = CustomerSheet.Configuration.builder() + val configuration = CustomerSheet.Configuration.builder(merchantDisplayName = "Example") .googlePayEnabled(true) .build() 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 6bec9214069..8bd12cb7e26 100644 --- a/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetViewModelTest.kt @@ -1200,6 +1200,7 @@ class CustomerSheetViewModelTest { selectPaymentMethodViewState, ), configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true, ), isGooglePayAvailable = false, @@ -1219,6 +1220,7 @@ class CustomerSheetViewModelTest { CustomerSheetViewState.Loading(false), ), configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true, ), customerSheetLoader = FakeCustomerSheetLoader( 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 4047e08fd1a..e43e0cc11eb 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 @@ -114,6 +114,7 @@ class DefaultCustomerSheetLoaderTest { ) val config = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = true ) @@ -156,7 +157,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().stripeIntent @@ -176,7 +177,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow() @@ -212,7 +213,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow() @@ -252,7 +253,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow() @@ -291,7 +292,7 @@ class DefaultCustomerSheetLoaderTest { val loader = createCustomerSheetLoader( lpmRepository = lpmRepository, ) - loader.load(CustomerSheet.Configuration()) + loader.load(CustomerSheet.Configuration(merchantDisplayName = "Example")) card = lpmRepository.fromCode("card") assertThat(card).isNotNull() @@ -315,7 +316,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -340,7 +341,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -365,7 +366,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -390,7 +391,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -415,7 +416,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -440,7 +441,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -465,7 +466,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -490,7 +491,7 @@ class DefaultCustomerSheetLoaderTest { ) ) - val config = CustomerSheet.Configuration() + val config = CustomerSheet.Configuration(merchantDisplayName = "Example") assertThat( loader.load(config).getOrThrow().supportedPaymentMethods @@ -501,7 +502,7 @@ class DefaultCustomerSheetLoaderTest { fun `Loads correct CBC eligibility if feature enabled`() = runTest { cbcFeatureFlagTestRule.setEnabled(true) val loader = createCustomerSheetLoader(isCbcEligible = true) - val state = loader.load(CustomerSheet.Configuration()).getOrThrow() + val state = loader.load(CustomerSheet.Configuration(merchantDisplayName = "Example")).getOrThrow() assertThat(state.cbcEligibility).isEqualTo(CardBrandChoiceEligibility.Eligible(emptyList())) } @@ -512,6 +513,7 @@ class DefaultCustomerSheetLoaderTest { val state = loader.load( CustomerSheet.Configuration( + merchantDisplayName = "Example", preferredNetworks = listOf(CardBrand.CartesBancaires), ) ).getOrThrow() @@ -524,7 +526,7 @@ class DefaultCustomerSheetLoaderTest { @Test fun `Does not load CBC eligibility if feature disabled`() = runTest { val loader = createCustomerSheetLoader(isCbcEligible = true) - val state = loader.load(CustomerSheet.Configuration()).getOrThrow() + val state = loader.load(CustomerSheet.Configuration(merchantDisplayName = "Example")).getOrThrow() assertThat(state.cbcEligibility).isEqualTo(CardBrandChoiceEligibility.Ineligible) } 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 bee903f2fb5..e5c3da07e0a 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 @@ -143,8 +143,7 @@ internal object CustomerSheetTestHelper { showCheckbox = false, showCheckboxControlledFields = false, initialPaymentMethodCreateParams = null, - merchantName = configuration.merchantDisplayName - ?: application.applicationInfo.loadLabel(application.packageManager).toString(), + merchantName = configuration.merchantDisplayName, billingDetails = configuration.defaultBillingDetails, billingDetailsCollectionConfiguration = configuration.billingDetailsCollectionConfiguration, cbcEligibility = CardBrandChoiceEligibility.Ineligible @@ -204,6 +203,7 @@ internal object CustomerSheetTestHelper { stripeAccountId = null, ), configuration: CustomerSheet.Configuration = CustomerSheet.Configuration( + merchantDisplayName = "Example", googlePayEnabled = isGooglePayAvailable ), formViewModelSubcomponentBuilderProvider: Provider =