prolificinteractive / Caishen

A Payment Card UI & Validator for iOS
MIT License
766 stars 119 forks source link

Validate Card on pre-fill #116

Closed BeauNouvelle closed 6 years ago

BeauNouvelle commented 7 years ago

After pre-filling fields with CardIO, didEnterCardInformation is not called. Some actions are taken after a successful validation, such as enabling a "Submit" button.

How would I force textfield to validate and call the didEnterCardInformation delegate method?

BeauNouvelle commented 7 years ago

Here's what I'm using at the moment right after pre-filling:

let result = cardType.validate(number: card.bankCardNumber)
                .union(cardType.validate(cvc: card.cardVerificationCode))
                .union(cardType.validate(expiry: card.expiryDate))
submitCardButton.isEnabled = result == .Valid

I guess technically it's a single line, but would love something a little shorter.

DannyVancura commented 6 years ago

The current example project does this, enabling a "Buy" button in the upper right hand corner of the screen. cardTextField(_ cardTextField: CardTextField, didEnterCardInformation information: Card, withValidationResult validationResult: CardValidationResult) is called appropriately here to update this button state as you describe. Please note, that this uses prefill(_, month: Int, year: Int, cvc: String) rather than setting text directly, in case that is what you are doing.

Thanks, Daniel

BeauNouvelle commented 6 years ago

No problem thank you.