/

Card Scanner

You can add a card scanning solution to your application by adding CardIO module. VGS Collect provides secure Card.io integration for collecting and setting scanned card data into VGSTextFields.

Integration

To use Card.io with VGSCollectSDK you should add CardIO module alongside with core VGSCollectSDK module into your App Podfile:

pod 'VGSCollectSDK'
pod 'VGSCollectSDK/CardIO'
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Also you need to add NSCameraUsageDescription key with camera usage description into your App Info.plist.

VGSCardIOScanController

An object you use to manage CardIO scan ViewController.

Declaration

class VGSCardIOScanController
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Creating a VGSCardIOScanController

init(_ delegate: VGSCardIOScanControllerDelegate? = nil)
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

VGSCardIOScanController Attributes and Methods

/// Handle CardIO states
var delegate: VGSCardIOScanControllerDelegate?

/// Set preferred camera position(default, back, front)
var preferredCameraPosition: AVCaptureDevice.Position?

/// Present CardIO scan ViewController
func presentCardScanner(on viewController: UIViewController, animated: Bool, completion: (() -> Void)?)

/// Dismiss CardIO scan ViewController
func dismissCardScanner(animated: Bool, completion: (() -> Void)?)
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

VGSCardIOScanControllerDelegate

Declaration

protocol VGSCardIOScanControllerDelegate
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Managing Controller States

/// On user confirm scanned data by selecting Done button on CardIO screen
@objc optional func userDidFinishScan()

/// On user selecting Cancel button on CardIO screen
@objc optional func userDidCancelScan()
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Providing VGSTextFields for setting Scanned Data

/// Asks VGSTextField where scanned data with type need to be set.
/// Called after user select Done button, just before userDidFinishScan() delegate.
@objc func textFieldForScannedData(type: CradIODataType) -> VGSTextField?
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

If scanned data is valid, it will be set in your VGSTextFields automatically after user confirmation.

CradIODataType

CradIODataType is an Enum of supported scan data types by CardIO module

CradIODataTypeType, Value
.cardNumberString, 16 digits number
.expirationDateString, "mm/yy" digits
.expirationMonthString, "mm" digits
.expirationYearString, "yy" digits
.cvcString, 3-4 digits

Usage

Create UI Form with VGSTextfields, if not done yet.
Inside your ViewController create and configure VGSCardIOScanController instance:

class ViewController: UIViewController {

    // Create VGSCardIOScanController instance
    var scanController = VGSCardIOScanController()

    // Scan card button
    var scanButton = UIButton()

    /// Initialize VGSCollect instance
    var vgsCollect = VGSCollect(id: "vauiltId", environment: .sandbox)

    /// VGS UI Elements
    var cardNumberField = VGSCardTextField()
    var cardHolderNameField = VGSTextField()
    var expCardDateField = VGSTextField()
    var cvcField = VGSTextField()


    override func viewDidLoad() {
       super.viewDidLoad()

       /// Set preferred device camera(optinal)
       scanController.preferredCameraPosition = .front

       /// Set and implement VGSCardIOScanDelegate to handle user interaction with Card.io
       scanController.delegate = self

       /// Add action to handle scan button touch
       scanButton.addTarget(self, action: #selector(scanData(_:)), for: .touchUpInside)

       /// Setup Fields Layout and Configuration
       ...
    }

     // Present scan ViewController
     @objc func scanData(_ sender: UIButton) {
         scanController.presentCardScanner(on: self, animated: true, completion: nil)
     }
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Implement VGSCardIOScanControllerDelegate methods.
To setup scanned data into specific VGSTextFields implement textFieldForScannedData:. If scanned data is valid it will be set in your VGSTextFields automatically after user confirmation. Check CradIODataType to get available scanned data types.

extension ViewController: VGSCardIOScanControllerDelegate {

  //When user press Done button on CardIO screen
  func userDidFinishScan() {
      scanController.dismissCardScanner(animated: true, completion: {
          // add actions on scan controller dismiss completion
      })
  }

  //When user press Cancel button on CardIO screen
  func userDidCancelScan() {
      scanController.dismissCardScanner(animated: true, completion: nil)
  }

  //Asks VGSTextField where scanned data with type need to be set.
  func textFieldForScannedData(type: CradIODataType) -> VGSTextField? {
      switch type {
      case .expirationDate:
          return expCardDateField
      case .cvc:
          return cvcField
      case .cardNumber:
          return cardNumberField
      default:
          return nil
      }
  }
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format