The easiest way to integrate DyScan is by using CocoaPods, which is covered in this guide.
If you would rather include DyScan directly as a framework, see the instructions here.
If you use Carthage as your dependency manager, see the instructions here.
If you use Swift Package Manager, see the instructions here.
Follow the instructions below corresponding with your DyScan version to access the necessary repositories.
After getting the access token for Dyneti's repo access, open up your Podfile and above the target add this line:
Then, inside the target with the other dependencies, add the appropriate line below for your specific version of Swift. If you are unsure what Swift version you are using, use Universal variant.
pod 'DyScan'
pod 'DyScan/5.1'
pod 'DyScan/5.0'
pod 'DyScan/4.2'
Include use_frameworks! in your Podfile if you have not done so already (see here for a sample Podfile). Then in a terminal in the directory of your iOS project, run
$podinstall
If 2FA is set up on your GitHub account, this step may fail. To rectify this, you will need to generate a personal access token in GitHub. This can be done by logging into GitHub and following the directions by navigating to Settings > Developer settings > Personal access tokens.
If your app does not already ask for camera permissions, add the key “NSCameraUsageDescription” (Privacy - Camera Usage Description) to your app's Info.plist file. You should set the value to be the string a user sees when they are prompted for the camera permission (e.g. To scan credit cards).
If you are getting an error like dyld: Library not loaded: @rpath/DyScan.framework/DyScan CocoaPods probably has not configured the dependency properly. In Pods/Target Support Files/Pods-{Project}/Pods-{Project}-frameworks.sh add the line install_framework "${PODS_ROOT}/DyScan/Swift5_1/DyScan.framework" in both the debug and release configurations (you should see many other similar lines). In "Embed Pods Frameworks" in your project's build phases, add
${PODS_ROOT}/DyScan/Swift5_1/DyScan.framework as an input path.
Initializing DyScan (only for version 1.1.1 and up)
In your AppDelegate add import DyScan and the following line to configure DyScan.
As a view controller: Quick and easy. Create a view controller that is presented modally. The DyScan view controller handles all aspects of the UX. We currently support two view controllers. One is intended for when DyScan is optionally accessed from a checkout form. The other is intended for when DyScan is the default method of entering payment information, and provides an option to enter numbers manually instead.
As a view: More flexible. Create a DyScanView to do card scanning only and manage everything else yourself. This enables a broader range of presentations, such as in-place transitions, but requires that you handle the rest of the UI yourself.
Regardless of which methodology you use, the failure callback will provide a reason for why scanning was not successful. You do not have to use this value (for example you could always go to manual entry on any failure), but this gives you the opportunity to react differently based on the reason, for example by requesting the user to enable the permissions. The possible values are:
import DyScan in the file that contains the view controller that will instantiate DyScan.
In your app, create an extension for your view controller that conforms to DyScanViewControllerDelegate. This will require you to implement two functions, onFailure, and onSuccess. onFailure is called whenever a scan event is unsuccessful (for any reason, including the user choosing to cancel).
Optionally, you can implement the function onProgressUpdate to access information about the card being scanned while the scan is ongoing (available for version 1.2.9 of DyScan and up). The DyScanProgressUpdate class has two attributes (both of string type): lastFourDigits and network, which correspond to the last four digits and network of the credit card (e.g., Visa or Mastercard) being scanned, respectively. You may choose to surface this information to your users to give them more feedback as they are waiting for their card to scan.
extensionExampleViewController:DyScanViewControllerDelegate{funconFailure(_paymentViewController: DyScanViewController!, reason: DyScanExitReason) { paymentViewController.dismiss(animated:true, completion:nil)// Implement functionality for failure cases }funconSuccess(_cardInfo: DyScanCreditCardInfo!, inpaymentViewController: DyScanViewController!) { paymentViewController.dismiss(animated:true, completion:nil)// Implement functionality after card is read (information is stored in cardInfo) }funconProgressUpdate(_progressUpdate: DyScanProgressUpdate, inpaymentViewController: DyScanViewController!){let network = progressUpdate.networklet lastFourDigits = progressUpdate.lastFourDigits// Implement functionality to use this info mid-scan }}
If you are using Stripe, see this guide for how to implement these functions.
DyScanCreditCardInfo has the following fields:
To instantiate DyScan, create an instance of DyScanViewController, and set the paymentDelegate attribute of it to your view controller (using self). Then, present the view controller.
let viewController =DyScanViewController()viewController.paymentDelegate = selfviewController.apiKey ="{YOUR API KEY}"// for version lower than 1.1.1let navigationController =UINavigationController(rootViewController: viewController)navigationController.modalPresentationStyle = .fullScreenpresent(navigationController, animated:true, completion:nil)
import DyScan in the file that contains the view controller that will instantiate DyScan.
In your app, create an extension for your view controller that conforms to DyScanDefaultViewControllerDelegate. This will require you to implement three functions, onFailure, onSuccess , and userChoseManual. onFailure is called whenever a scan event is unsuccessful (for any reason, even if the user chose to cancel).
Optionally, you can implement the function onProgressUpdate to access information about the card being scanned while the scan is ongoing (available for version 1.2.9 of DyScan and up). The DyScanProgressUpdate class has two attributes (both of string type): lastFourDigits and network, which correspond to the last four digits and network of the credit card (e.g., Visa or Mastercard) being scanned, respectively. You may choose to surface this information to your users to give them more feedback as they are waiting for their card to scan.
extensionExampleViewController:DyScanViewControllerDelegate{funconFailure(_paymentViewController: DyScanViewController!, reason: DyScanExitReason) { paymentViewController.dismiss(animated:true, completion:nil)// Implement functionality after user cancels }funconSuccess(_cardInfo: DyScanCreditCardInfo!, inpaymentViewController: DyScanViewController!) { paymentViewController.dismiss(animated:true, completion:nil)// Implement functionality after card is read (information is stored in cardInfo) }funcuserChoseManual(_paymentViewController: DyScanDefaultViewController!){ paymentViewController.dismiss(animated:true, completion:nil)// Implement functionality for transitioning manual entry }funconProgressUpdate(_progressUpdate: DyScanProgressUpdate, inpaymentViewController: DyScanViewController!){let network = progressUpdate.networklet lastFourDigits = progressUpdate.lastFourDigits// Implement functionality to use this info mid-scan }}
If you are using Stripe, see this guide for what functions to implement here.
DyScanCreditCardInfo has the following fields:
To instantiate DyScan, create an instance of DyScanDefaultViewController, and set the paymentDelegate attribute of it to your view controller (using self). Then, present the view controller.
let viewController =DyScanDefaultViewController()viewController.paymentDelegate = selfviewController.apiKey ="{YOUR API KEY}"// for version lower than 1.1.0let navigationController =UINavigationController(rootViewController: viewController)navigationController.modalPresentationStyle = .fullScreenpresent(navigationController, animated:true, completion:nil)
If you would like to disable the manual entry option, you can do so by setting the key viewController.allowManualEntry=false.
import DyScan in the file that contains the view controller that will instantiate DyScan.
In your app, create an extension for your view that conforms to DyScanViewDelegate. This will require you to implement two functions, onFailure, and onSuccess.
Optionally, you can implement the function onProgressUpdate to access information about the card being scanned while the scan is ongoing (available for version 1.2.9 of DyScan and up). The DyScanProgressUpdate class has two attributes (both of string type): lastFourDigits and network, which correspond to the last four digits and network of the credit card (e.g., Visa or Mastercard) being scanned, respectively. You may choose to surface this information to your users to give them more feedback as they are waiting for their card to scan.
extensionExampleViewController:DyScanViewDelegate{funconFailure(_dyScanIOView: DyScanView!, reason: DyScanExitReason) {//Implement functionality when we could not scan }funconSuccess(_dyScanIOView: DyScanView!, cardInfo: DyScanCreditCardInfo?) {//Implement functionality when scanning completes (information is stored in cardInfo) }funconProgressUpdate(_dyScanIOView: DyScanView!, progressUpdate: DyScanProgressUpdate) {let network = progressUpdate.networklet lastFourDigits = progressUpdate.lastFourDigits// Implement functionality to use this info mid-scan }}
If you are using Stripe, see this guide for what functions to implement here.
DyScanCreditCardInfo has the following fields:
To instantiate DyScan, create an instance of DyScanView, and set the delegate attribute of it to your view controller (using self). You will need to call the prepare() function to fully initialize the view before adding it as a subview. For example, DyScanView could be added like this:
dyScanView =DyScanView(frame: CGRect(x:0, y:0, width: self.view.frame.width, height: self.view.frame.height))dyScanView?.apiKey ="{YOUR API KEY}"// for version lower than 1.1.1dyScanView?.delegate = selfdyScanView?.prepare()self.view.addSubview(dyScanView!)
If you would like to allow for the user to switch to a vertical card scanning experience, use the DyScanView.rotate function.
Customizing the Appearance
The DyScan UI is customizable through the following options
The following fields can only be used in the view controller:
Additionally, there are some public fields you can use to easily add buttons with additional functionality to your scan screen. Note that these are available only if you are using DyScan as a view. The fields are described below: