Skip to content

iOS Credit/Debit card scanner, built using Apple's Vision Framework.

License

Notifications You must be signed in to change notification settings

gymshark/ios-card-scan

Repository files navigation

SharkCardScan

SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.

SharkCardScan allows you to quickly implement a card scanner inside of your own app.

SharkCardScan is built and maintained with love by the Gymshark Engineering Team 💙📱

Usage

It's possible to get started quickly with the following snippet.

        let scannerVC = SharkCardScanViewController(viewModel: CardScanViewModel(noPermissionAction: { [weak self] in
            
            self?.showNoPermissionAlert()
            
        }, successHandler: { (response) in
            print("Expiry 💣: \(response.expiry ?? "")")
            print("Card Number 💳: \(response.number)")
            print("Holder name 🕺: \(response.holder ?? "")")
        }))
        

Here we handle the No Camera Permission error, from the ViewModeland our successHandler is called upon receipt of finding a card number, and the expiry and card holders name, albeit, we can call success if only a valid card number is found.

Styling

SharkCardScanViewController initialiser takes a default parameter for styling, which you can specify your own, if you wish to amend fonts/colours.

SharkCardScanViewController(viewModel: CardScanViewModel{...}, styling: MyOwnCardScannerStyling())

CardScanStyling is a protocol, your styling struct must conform too with the following properties you have to set;

public protocol CardScanStyling {
    var instructionLabelStyling: LabelStyling { get set }
    var cardNumberLabelStyling: LabelStyling { get set }
    var expiryLabelStyling: LabelStyling { get set }
    var holderLabelStyling: LabelStyling { get set }
    var backgroundColor: UIColor { get set }
}

NB: By using the default parameter, and using our DefaultStyling struct instance, the font will only have fixed sizes, for now, rather than being dynamic - one for us to fix later (or send us a PR?!)

Other Customisations

ACardScanViewModel has a instructionText property, if you wish to override the default instruction text that is shown on the viewer.

Installation

Swift Package Manager (SPM) To install SharkCardScan using Swift Package Manager you can follow the tutorial published by Apple using the URL for the SharkCardScan repo with the current version:

  1. In Xcode, select “File” → “Swift Packages” → “Add Package Dependency”
  2. Enter https://github.com/gymshark/ios-card-scan.git

About

iOS Credit/Debit card scanner, built using Apple's Vision Framework.

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages