Skip to content

Commit

Permalink
Focus on CardInputWidget field with first error (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafrir-stripe authored Jan 8, 2020
1 parent f56f2bc commit 1236962
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,13 @@ class CardInputWidget @JvmOverloads constructor(
*/
override val paymentMethodCard: PaymentMethodCreateParams.Card?
get() {
val cardNumber = cardNumberEditText.cardNumber
val cardDate = expiryDateEditText.validDateFields
val cvcValue = cvcValue

return if (cardNumber != null && cardDate != null && cvcValue != null) {
return card?.let {
PaymentMethodCreateParams.Card(
number = cardNumber,
cvc = cvcValue,
expiryMonth = cardDate.first,
expiryYear = cardDate.second
number = it.number,
cvc = it.cvc,
expiryMonth = it.expMonth,
expiryYear = it.expYear
)
} else {
null
}
}

Expand Down Expand Up @@ -167,15 +161,26 @@ class CardInputWidget @JvmOverloads constructor(
get() {
val cardNumber = cardNumberEditText.cardNumber
val cardDate = expiryDateEditText.validDateFields
return if (cardNumber != null && cardDate != null) {
cvcValue?.let {
Card.Builder(cardNumber, cardDate.first, cardDate.second, it)
val cvcValue = this.cvcValue

when {
cardNumber == null -> {
cardNumberEditText.requestFocus()
}
cardDate == null -> {
expiryDateEditText.requestFocus()
}
cvcValue == null -> {
cvcNumberEditText.requestFocus()
}
else -> {
return Card.Builder(cardNumber, cardDate.first, cardDate.second, cvcValue)
.addressZip(postalCodeValue)
.loggingTokens(listOf(LOGGING_TOKEN))
}
} else {
null
}

return null
}

private val frameWidth: Int
Expand Down

0 comments on commit 1236962

Please sign in to comment.