Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CustomerSheet.Configuration non nullable. #7627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class CustomerSheetPlaygroundViewModel(
private val _configurationState = MutableStateFlow(CustomerSheetPlaygroundConfigurationState())
val configurationState: StateFlow<CustomerSheetPlaygroundConfigurationState> = _configurationState

private val initialConfiguration = CustomerSheet.Configuration.builder()
private val initialConfiguration = CustomerSheet.Configuration.builder(
merchantDisplayName = "Payment Sheet Example"
)
.defaultBillingDetails(
PaymentSheet.BillingDetails(
name = "CustomerSheet Testing"
Expand Down
7 changes: 3 additions & 4 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,42 +159,40 @@ 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<CardBrand> = 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
private var defaultBillingDetails: PaymentSheet.BillingDetails = PaymentSheet.BillingDetails()
private var billingDetailsCollectionConfiguration:
PaymentSheet.BillingDetailsCollectionConfiguration =
PaymentSheet.BillingDetailsCollectionConfiguration()
private var merchantDisplayName: String? = null
private var preferredNetworks: List<CardBrand> = emptyList()

fun appearance(appearance: PaymentSheet.Appearance) = apply {
Expand All @@ -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(
Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.stripe.android.utils.rememberActivityOrNull
@ExperimentalCustomerSheetApi
@Composable
fun rememberCustomerSheet(
configuration: CustomerSheet.Configuration = CustomerSheet.Configuration(),
configuration: CustomerSheet.Configuration,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure what to think about this. Should we relax this to a nullable config and create a default configuration internally, with the application label as the merchant name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally possible. This is what we do for PaymentSheet.

If everything else in this sounds good to you, I think we should definitely do that and ship it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s do it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline. Slightly more inclined to leave it as not optional since the non compose way to instantiate CustomerSheet already requires a config.

customerAdapter: CustomerAdapter,
callback: CustomerSheetResultCallback,
): CustomerSheet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,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()

Expand Down Expand Up @@ -366,8 +363,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,
Expand All @@ -385,7 +381,7 @@ internal class CustomerSheetViewModel @Inject constructor(
},
mandateText = it.draftPaymentSelection?.mandateText(
context = application,
merchantName = merchantName,
merchantName = configuration.merchantDisplayName,
isSaveForFutureUseSelected = false,
isSetupFlow = true,
),
Expand Down Expand Up @@ -537,7 +533,7 @@ internal class CustomerSheetViewModel @Inject constructor(
),
mandateText = paymentSelection.mandateText(
context = application,
merchantName = merchantName,
merchantName = configuration.merchantDisplayName,
isSaveForFutureUseSelected = false,
isSetupFlow = true,
)?.takeIf { primaryButtonVisible },
Expand Down Expand Up @@ -626,7 +622,7 @@ internal class CustomerSheetViewModel @Inject constructor(
val formArguments = FormArgumentsFactory.create(
paymentMethod = card,
configuration = configuration,
merchantName = merchantName,
merchantName = configuration.merchantDisplayName,
cbcEligibility = cbcEligibility,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ class CustomerAdapterTest {
application = application
).createCustomerSessionComponent(
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = true
),
customerAdapter = adapter,
Expand Down Expand Up @@ -686,6 +687,7 @@ class CustomerAdapterTest {
application = application
).createCustomerSessionComponent(
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = false
),
customerAdapter = adapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -50,6 +50,7 @@ class CustomerSessionViewModelTest {

val component2 = viewModel.createCustomerSessionComponent(
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = true
),
customerAdapter = CustomerAdapter.create(
Expand Down Expand Up @@ -77,6 +78,7 @@ class CustomerSessionViewModelTest {
val callback = mock<CustomerSheetResultCallback>()
val component1 = viewModel.createCustomerSessionComponent(
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = false,
),
customerAdapter = customerAdapter,
Expand All @@ -86,6 +88,7 @@ class CustomerSessionViewModelTest {

val component2 = viewModel.createCustomerSessionComponent(
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = true,
),
customerAdapter = customerAdapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ class CustomerSheetViewModelTest {
selectPaymentMethodViewState,
),
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = true,
),
isGooglePayAvailable = false,
Expand All @@ -1219,6 +1220,7 @@ class CustomerSheetViewModelTest {
CustomerSheetViewState.Loading(false),
),
configuration = CustomerSheet.Configuration(
merchantDisplayName = "Example",
googlePayEnabled = true,
),
customerSheetLoader = FakeCustomerSheetLoader(
Expand Down
Loading
Loading