internal fun saveCreditCard(state: CreditCardEditorState) { binding.root.hideKeyboard() if (validateForm()) { val cardNumber = binding.cardNumberInput.text.toString().toCreditCardNumber() if (state.isEditing) { val fields = UpdatableCreditCardFields( billingName = binding.nameOnCardInput.text.toString(), cardNumber = CreditCardNumber.Plaintext(cardNumber), cardNumberLast4 = cardNumber.last4Digits(), expiryMonth = (binding.expiryMonthDropDown.selectedItemPosition + 1).toLong(), expiryYear = binding.expiryYearDropDown.selectedItem.toString().toLong(), cardType = cardNumber.creditCardIIN()?.creditCardIssuerNetwork?.name ?: "", ) interactor.onUpdateCreditCard(state.guid, fields) } else { val fields = NewCreditCardFields( billingName = binding.nameOnCardInput.text.toString(), plaintextCardNumber = CreditCardNumber.Plaintext(cardNumber), cardNumberLast4 = cardNumber.last4Digits(), expiryMonth = (binding.expiryMonthDropDown.selectedItemPosition + 1).toLong(), expiryYear = binding.expiryYearDropDown.selectedItem.toString().toLong(), cardType = cardNumber.creditCardIIN()?.creditCardIssuerNetwork?.name ?: "", ) interactor.onSaveCreditCard(fields) } } }
Saves a new credit card or updates an existing one with data from the user input.