Skip to content

Commit

Permalink
Make CustomerSheet.Configuration non nullable. (#7627)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe authored Nov 17, 2023
1 parent 79cc4a3 commit 4cd5ca9
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 49 deletions.
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,
customerAdapter: CustomerAdapter,
callback: CustomerSheetResultCallback,
): CustomerSheet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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,
Expand All @@ -384,7 +380,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 @@ -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 },
Expand Down Expand Up @@ -625,7 +621,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

0 comments on commit 4cd5ca9

Please sign in to comment.