For #19492 - Provide the correct CreditCardNumber type to UpdatableCreditCardFields when updating a credit card (#19692)

We were crashing because we were specifying the wrong `CreditCardNumber` type when constructing the `UpdatableCreditCardFields`.
We only had the plaintext card number from the user input, but was placing it off as an encrypted card number, which resulted in the crash.
upstream-sync
Gabriel Luong 3 years ago committed by GitHub
parent 965a211fc3
commit 89a1b0016c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,6 +17,7 @@ import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.utils.creditCardIIN
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.toEditable
import org.mozilla.fenix.settings.creditcards.CreditCardEditorFragment
import org.mozilla.fenix.settings.creditcards.CreditCardEditorState
import org.mozilla.fenix.settings.creditcards.interactor.CreditCardEditorInteractor
import org.mozilla.fenix.settings.creditcards.last4Digits
@ -64,8 +65,10 @@ class CreditCardEditorView(
}
/**
* Saves a new credit card or updates an existing one with data from user input.
* @param state The state for the CreditCardEditorFragment containing all credit card data.
* Saves a new credit card or updates an existing one with data from the user input.
*
* @param state The state of the [CreditCardEditorFragment] containing the edited credit card
* information.
*/
internal fun saveCreditCard(state: CreditCardEditorState) {
containerView.hideKeyboard()
@ -76,7 +79,7 @@ class CreditCardEditorView(
if (state.isEditing) {
val fields = UpdatableCreditCardFields(
billingName = name_on_card_input.text.toString(),
cardNumber = CreditCardNumber.Encrypted(cardNumber),
cardNumber = CreditCardNumber.Plaintext(cardNumber),
cardNumberLast4 = cardNumber.last4Digits(),
expiryMonth = (expiry_month_drop_down.selectedItemPosition + 1).toLong(),
expiryYear = expiry_year_drop_down.selectedItem.toString().toLong(),
@ -99,6 +102,7 @@ class CreditCardEditorView(
/**
* Validates the credit card information entered by the user.
*
* @return true if the credit card is valid, false otherwise.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

@ -222,7 +222,7 @@ class CreditCardEditorViewTest {
guid = creditCard.guid,
creditCardFields = UpdatableCreditCardFields(
billingName = creditCard.billingName,
cardNumber = creditCard.encryptedCardNumber,
cardNumber = CreditCardNumber.Plaintext(cardNumber),
cardNumberLast4 = creditCard.cardNumberLast4,
expiryMonth = creditCard.expiryMonth,
expiryYear = creditCard.expiryYear,

Loading…
Cancel
Save