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

[CONSUMERBANK-528] Handle invalid phone numbers in Link signup more gracefully #4269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -179,6 +179,7 @@ final class LinkLoginViewController: UIViewController {
}
} else {
formView?.showAndEditPhoneNumberFieldIfNeeded()
setContinueWithLinkButtonDisabledState()
}
case .failure(let error):
self.delegate?.linkLoginViewController(self, didReceiveTerminalError: error)
Expand Down Expand Up @@ -210,7 +211,21 @@ final class LinkLoginViewController: UIViewController {
case .success(let response):
self.delegate?.linkLoginViewController(self, signedUpAttachedAndSynchronized: response)
case .failure(let error):
self.delegate?.linkLoginViewController(self, didReceiveTerminalError: error)
func completeWithTerminalError() {
self.delegate?.linkLoginViewController(self, didReceiveTerminalError: error)
}

guard let stripeError = error as? StripeError, case .apiError(let stripeAPIError) = stripeError else {
return completeWithTerminalError()
}

// Hack to determine if the error is related to the phone number.
// If so, show a generic error message under the phone textfield.
if let errorMessage = stripeAPIError.message, errorMessage.contains("phone") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't sure if I should search for the localized string "phone" here, or hardcode the english word. Are remote error messages localized?

formView.phoneTextField.setErrorText(PhoneTextField.LocalizedStrings.invalidPhoneNumber)
} else {
completeWithTerminalError()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ extension LinkSignupFormView: PhoneTextFieldDelegate {
_ phoneTextField: PhoneTextField,
didChangePhoneNumber phoneNumber: PhoneNumber?
) {
phoneTextField.clearErrorText()
delegate?.linkSignupFormViewDidUpdateFields(self)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@ protocol PhoneTextFieldDelegate: AnyObject {

final class PhoneTextField: UIView {

enum LocalizedStrings {
static let textfieldPlaceholder = STPLocalizedString(
"Phone number",
"The title of a user-input-field that appears when a user is signing up to Link (a payment service). It instructs user to type a phone number."
)

static let invalidPhoneNumber = STPLocalizedString(
"Your mobile phone number is invalid.",
"An error message that instructs the user to keep typing their phone number in a user-input field."
)
}

fileprivate lazy var textField: RoundedTextField = {
let textField = RoundedTextField(
placeholder: STPLocalizedString("Phone number", "The title of a user-input-field that appears when a user is signing up to Link (a payment service). It instructs user to type a phone number."),
placeholder: LocalizedStrings.textfieldPlaceholder,
showDoneToolbar: true,
theme: theme
)
Expand Down Expand Up @@ -158,13 +170,21 @@ final class PhoneTextField: UIView {
if text.isEmpty {
// no error message if empty
} else {
textField.errorText = STPLocalizedString("Your mobile phone number is incomplete.", "An error message that instructs the user to keep typing their phone number in a user-input field.")
textField.errorText = LocalizedStrings.invalidPhoneNumber
}
}
}

delegate?.phoneTextField(self, didChangePhoneNumber: phoneNumber)
}

func setErrorText(_ errorMessage: String) {
textField.errorText = errorMessage
}

func clearErrorText() {
textField.errorText = nil
}
}

// MARK: - RoundedTextFieldDelegate
Expand Down
Loading