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

Add prefix to form field value in PhoneNumberController #9571

Merged
merged 1 commit into from
Nov 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class LinkSignupHandlerForInstantDebits @Inject constructor(

val signup = consumerRepository.signUp(
email = state.validEmail!!,
phoneNumber = phoneController.getE164PhoneNumber(state.validPhone!!),
phoneNumber = state.validPhone!!,
country = phoneController.getCountryCode(),
)

Expand Down Expand Up @@ -95,7 +95,7 @@ internal class LinkSignupHandlerForNetworking @Inject constructor(
saveAccountToLink.new(
country = phoneController.getCountryCode(),
email = state.validEmail!!,
phoneNumber = phoneController.getE164PhoneNumber(state.validPhone!!),
phoneNumber = state.validPhone!!,
Copy link
Collaborator Author

@samer-stripe samer-stripe Nov 8, 2024

Choose a reason for hiding this comment

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

Not that formFieldValue transmits this, we don't need to convert it manually. This is covered by Maestro tests.

selectedAccounts = selectedAccounts,
shouldPollAccountNumbers = manifest.isDataFlow,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,11 @@ internal class InlineSignupViewModel @AssistedInject constructor(

return if (email != null && phoneNumber != null && signUpMode != null) {
val isNameValid = !requiresNameCollection || !name.isNullOrBlank()

val phone = phoneController.getE164PhoneNumber(phoneNumber)
val country = phoneController.getCountryCode()

UserInput.SignUp(
email = email,
phone = phone,
phone = phoneNumber,
country = country,
name = name,
consentAction = signUpMode.toConsentAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,17 @@ internal class PhoneNumberControllerTest {
assertThat(awaitItem()).isTrue()
}
}

@Test
fun `when phone number is entered, form field value should contain prefix`() = runTest {
val phoneNumberController = PhoneNumberController.createPhoneNumberController(
initiallySelectedCountryCode = "CA",
)

phoneNumberController.onValueChange("(122) 252-5252")

phoneNumberController.formFieldValue.test {
assertThat(awaitItem().value).isEqualTo("+11222525252")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal fun billingDetailsParams(): RequestMatcher {
internal fun fullBillingDetailsParams(): RequestMatcher {
return RequestMatchers.composite(
bodyPart(urlEncode("billing_details[name]"), urlEncode(CustomerSheetPage.NAME)),
bodyPart(urlEncode("billing_details[phone]"), CustomerSheetPage.PHONE_NUMBER),
bodyPart(urlEncode("billing_details[phone]"), urlEncode("+1${CustomerSheetPage.PHONE_NUMBER}")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Were we sending this to the backend incorrectly!??!?

Copy link
Collaborator Author

@samer-stripe samer-stripe Nov 8, 2024

Choose a reason for hiding this comment

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

Unfortunately yeah :(. This has been a fairly long standing issue (since 2022 at least)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this broken in PaymentSheet as well?

Copy link
Collaborator Author

@samer-stripe samer-stripe Nov 8, 2024

Choose a reason for hiding this comment

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

Yeah since we weren't manually converting the text input. InlineLinkSignup did it properly but not any phone number field outside of it (through billing config, required by LPM)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. Nice fix!

bodyPart(urlEncode("billing_details[email]"), urlEncode(CustomerSheetPage.EMAIL)),
bodyPart(urlEncode("billing_details[address][line1]"), urlEncode(CustomerSheetPage.ADDRESS_LINE_ONE)),
bodyPart(urlEncode("billing_details[address][line2]"), urlEncode(CustomerSheetPage.ADDRESS_LINE_TWO)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
name = name,
// The createPaymentDetails endpoint does not accept uppercase characters.
email = email?.lowercase(),
phone = phone?.let { phoneController.getE164PhoneNumber(it) },
phone = phone,
address = address?.let {
ElementsSessionContext.BillingDetails.Address(
line1 = it.line1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class USBankAccountFormViewModelTest {
val input = PaymentSelection.New.USBankAccount.Input(
name = "Some One",
email = "[email protected]",
phone = "1112223456",
phone = "+11112223456",
address = Address(
line1 = "123 Not Main Street",
line2 = "Apt 123",
Expand Down Expand Up @@ -308,7 +308,7 @@ class USBankAccountFormViewModelTest {
val input = PaymentSelection.New.USBankAccount.Input(
name = "Some One",
email = "[email protected]",
phone = "1112223456",
phone = "+11112223456",
address = Address(
line1 = "123 Not Main Street",
line2 = "Apt 123",
Expand Down Expand Up @@ -363,7 +363,7 @@ class USBankAccountFormViewModelTest {
billingDetails = PaymentSheet.BillingDetails(
name = CUSTOMER_NAME,
email = CUSTOMER_EMAIL,
phone = CUSTOMER_PHONE_COUNTRY_CODE + CUSTOMER_PHONE,
phone = CUSTOMER_PHONE,
address = CUSTOMER_ADDRESS,
),
billingDetailsCollectionConfiguration = PaymentSheet.BillingDetailsCollectionConfiguration(
Expand Down Expand Up @@ -505,7 +505,7 @@ class USBankAccountFormViewModelTest {
billingDetails = PaymentSheet.BillingDetails(
name = CUSTOMER_NAME,
email = CUSTOMER_EMAIL,
phone = CUSTOMER_PHONE_COUNTRY_CODE + CUSTOMER_PHONE,
phone = CUSTOMER_PHONE,
address = CUSTOMER_ADDRESS,
),
billingDetailsCollectionConfiguration = PaymentSheet.BillingDetailsCollectionConfiguration(
Expand Down Expand Up @@ -1626,8 +1626,7 @@ class USBankAccountFormViewModelTest {
const val CUSTOMER_EMAIL = "[email protected]"
const val STRIPE_ACCOUNT_ID = "stripe_account_id"
const val CUSTOMER_COUNTRY = "US"
const val CUSTOMER_PHONE_COUNTRY_CODE = "+1"
const val CUSTOMER_PHONE = "3105551234"
const val CUSTOMER_PHONE = "+13105551234"
val CUSTOMER_ADDRESS = PaymentSheet.Address(
line1 = "123 Main Street",
line2 = "Apt 456",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class PhoneNumberController private constructor(
override val isComplete = combineAsStateFlow(fieldValue, phoneNumberMinimumLength) { value, minLength ->
value.length >= (minLength ?: 0) || acceptAnyInput
}
override val formFieldValue = combineAsStateFlow(fieldValue, isComplete) { fieldValue, isComplete ->
FormFieldEntry(fieldValue, isComplete)
override val formFieldValue = combineAsStateFlow(rawFieldValue, isComplete) { rawFieldValue, isComplete ->
FormFieldEntry(rawFieldValue, isComplete)
}

override val error: StateFlow<FieldError?> = combineAsStateFlow(
Expand Down
Loading