Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 3.8 KB

README.md

File metadata and controls

76 lines (54 loc) · 3.8 KB

LSCreditCardForm

Version License Platform

Engaging credit card form that is simple to use.

Demo

demo-vid

Usage

To use LSCreditCardForm, simply add LSCreditCardFormView into your view controller and layout apropriately. Contents of LSCreditCardFormView are dynamicaly resized and layout is updated on each view size change. Use LSCreditCardFormDelegate to get values user entered into the form. Delegate protocol contains only one method didCompleteForm(creditCard: LSCreditCard) that is called whenever user hits Done button. Library does not validate entered data except making sure that user did not enter invalid characters.

LSCreditCardFormView currently detects following credit card issuers: VISA Mastercard AmericanExpress DinersClub Discover enRoute JCB Maestro

Customization

Various aspects of form can be customized using LSCreditCardFormConfig and it's subfields. Customization points include fonts, text colors, background colors and ability to provide custom credit card images. IMPORTANT: all customizations have to be made before LSCreditCardFormView gets instantiated

Textfield focus automatically changes when user enters maximum allowed number of characters. This works well in most cases, but causes problems with VISA cards. Maximum number of digits for VISA credit cards is 19, but vast majority of cards consist of only 16 digits. This would make entering VISA cards annoying so config has CreditCard.softLimitVisaTo16Digits that can be set to true to automatically skip to next textfield when user enters 16th digit. In rare cases when user wants to enter 19 digits, he can manually return to number text field.

If you wish to limit which credit cards get detected, override CreditCard.supportedTypes property by providing array of types you want to detect. User will still be able to enter any credit card number, disabling detection for certain types simply means that the credit card image will not update and will remain on "unknown" credit card.

Custom types

You can supply detection of and images for additional credit card types. Use delegate method func getCustomCardType(for number: String) -> LSCreditCardType? to check if CC number belongs to your custom type. Return nil if it doesn't, to have library do the default type detection. You also should provide images for your new type using LSCreditCardFormConfig.CreditCard.imgBackForCustomType and LSCreditCardFormConfig.CreditCard.imgFrontForCustomType callbacks. See example project for more details. Currently, only custom images are supported, you can't provide custom number length and formatting, default 4-4-4-4 is used for all custom types.

Keyboard

If you wish to have keyboard open as soon as the view appears with new view controller, call becomeFirstResponder on LSCreditCardFormView.

Installation

LSCreditCardForm is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LSCreditCardForm'

Using LSCreditCardView outside of the LSCreditCardForm

If you want to display credit card view in your app, you can. First create instance of LSCreditCardView and add it into your view hierarchy. Create instance of LSCreditCard and feed it CC number, card holder name, expiration date string and type and call updateValues(creditCard:) on your LSCreditCardView instance.

License

LSCreditCardForm is available under the MIT license. See the LICENSE file for more info.