Skip to content

Commit

Permalink
Rename defaultValues to address (#5467)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe committed Aug 25, 2022
1 parent a61f618 commit 6ea0d92
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 55 deletions.
8 changes: 0 additions & 8 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,6 @@ public final class com/stripe/android/paymentsheet/addresselement/AddressLaunche
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentsheet/addresselement/AddressLauncher$DefaultAddressDetails$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/addresselement/AddressLauncher$DefaultAddressDetails;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/addresselement/AddressLauncher$DefaultAddressDetails;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentsheet/addresselement/AddressLauncherResult$Canceled$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/addresselement/AddressLauncherResult$Canceled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ data class AddressDetails(
}
}

internal fun AddressLauncher.DefaultAddressDetails.toAddressDetails(): AddressDetails =
AddressDetails(
name = this.name,
address = this.address,
phoneNumber = this.phoneNumber,
isCheckboxSelected = this.isCheckboxSelected
)

internal fun AddressDetails.toIdentifierMap(
billingDetails: PaymentSheet.BillingDetails? = null,
billingSameAsShipping: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal class AddressLauncher internal constructor(
/**
* The values to pre-populate shipping address fields with.
*/
val defaultValues: DefaultAddressDetails? = null,
val address: AddressDetails? = null,

/**
* A list of two-letter country codes representing countries the customers can select.
Expand Down Expand Up @@ -114,7 +114,7 @@ internal class AddressLauncher internal constructor(
*/
class Builder {
private var appearance: PaymentSheet.Appearance = PaymentSheet.Appearance()
private var defaultValues: DefaultAddressDetails? = null
private var address: AddressDetails? = null
private var allowedCountries: Set<String> = emptySet()
private var buttonTitle: String? = null
private var additionalFields: AdditionalFieldsConfiguration? = null
Expand All @@ -124,8 +124,8 @@ internal class AddressLauncher internal constructor(
fun appearance(appearance: PaymentSheet.Appearance) =
apply { this.appearance = appearance }

fun defaultValues(defaultValues: DefaultAddressDetails?) =
apply { this.defaultValues = defaultValues }
fun address(address: AddressDetails?) =
apply { this.address = address }

fun allowedCountries(allowedCountries: Set<String>) =
apply { this.allowedCountries = allowedCountries }
Expand All @@ -144,7 +144,7 @@ internal class AddressLauncher internal constructor(

fun build() = Configuration(
appearance,
defaultValues,
address,
allowedCountries,
buttonTitle,
additionalFields,
Expand Down Expand Up @@ -183,28 +183,4 @@ internal class AddressLauncher internal constructor(
REQUIRED
}
}

@Parcelize
data class DefaultAddressDetails(
/**
* The customer's full name
*/
val name: String? = null,

/**
* The customer's address
*/
val address: PaymentSheet.Address? = null,

/**
* The customer's phone number, without formatting e.g. "5551234567"
*/
val phoneNumber: String? = null,

/**
* Whether or not your custom checkbox is intially selected.
* Note: The checkbox is displayed below the other fields when AdditionalFieldsConfiguration.checkboxLabel is set.
*/
val isCheckboxSelected: Boolean? = null
) : Parcelable
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class InputAddressViewModel @Inject constructor(
private val eventReporter: AddressLauncherEventReporter,
formControllerProvider: Provider<FormControllerSubcomponent.Builder>
) : ViewModel() {
private val _collectedAddress = MutableStateFlow(args.config?.defaultValues?.toAddressDetails())
private val _collectedAddress = MutableStateFlow(args.config?.address)
val collectedAddress: StateFlow<AddressDetails?> = _collectedAddress

private val _formController = MutableStateFlow<FormController?>(null)
Expand Down Expand Up @@ -82,7 +82,7 @@ internal class InputAddressViewModel @Inject constructor(
}

// allows merchants to check the box by default and to restore the value later.
args.config?.defaultValues?.isCheckboxSelected?.let {
args.config?.address?.isCheckboxSelected?.let {
_checkboxChecked.value = it
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class InputAddressViewModelTest {
}
private val eventReporter = mock<AddressLauncherEventReporter>()

private fun createViewModel(defaultAddress: AddressLauncher.DefaultAddressDetails? = null): InputAddressViewModel {
defaultAddress?.let {
whenever(config.defaultValues).thenReturn(defaultAddress)
private fun createViewModel(address: AddressDetails? = null): InputAddressViewModel {
address?.let {
whenever(config.address).thenReturn(address)
}
whenever(args.config).thenReturn(config)
return InputAddressViewModel(
Expand Down Expand Up @@ -90,16 +90,16 @@ class InputAddressViewModelTest {

@Test
fun `default address from merchant is parsed`() = runTest(UnconfinedTestDispatcher()) {
val expectedAddress = AddressLauncher.DefaultAddressDetails(name = "skyler", address = PaymentSheet.Address(country = "US"))
val expectedAddress = AddressDetails(name = "skyler", address = PaymentSheet.Address(country = "US"))

val viewModel = createViewModel(expectedAddress)
assertThat(viewModel.collectedAddress.value).isEqualTo(expectedAddress.toAddressDetails())
assertThat(viewModel.collectedAddress.value).isEqualTo(expectedAddress)
}

@Test
fun `viewModel emits onComplete event`() = runTest(UnconfinedTestDispatcher()) {
val viewModel = createViewModel(
AddressLauncher.DefaultAddressDetails(
AddressDetails(
address = PaymentSheet.Address(
line1 = "99 Broadway St",
city = "Seattle",
Expand All @@ -126,7 +126,7 @@ class InputAddressViewModelTest {
@Test
fun `default checkbox should emit true to start if passed by merchant`() = runTest(UnconfinedTestDispatcher()) {
val viewModel = createViewModel(
AddressLauncher.DefaultAddressDetails(
AddressDetails(
isCheckboxSelected = true
)
)
Expand All @@ -136,7 +136,7 @@ class InputAddressViewModelTest {
@Test
fun `default checkbox should emit false to start if passed by merchant`() = runTest(UnconfinedTestDispatcher()) {
val viewModel = createViewModel(
AddressLauncher.DefaultAddressDetails(
AddressDetails(
isCheckboxSelected = false
)
)
Expand Down

0 comments on commit 6ea0d92

Please sign in to comment.