-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Public Release 1.12.0
- Loading branch information
Showing
46 changed files
with
853 additions
and
1,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Sources/VGSBlinkCardCollector/CardDataMappers/VGSBlinkCardExpirationDate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
import Foundation | ||
#if !COCOAPODS | ||
import VGSCollectSDK | ||
#endif | ||
|
||
/// Holds scanned expiration date data. | ||
/// BlinkCard holds scanned data expiration date with two separate Ints. | ||
internal struct VGSBlinkCardExpirationDate { | ||
/// Scanned month. | ||
let month: Int | ||
/// Month converted to String: "01" | ||
let monthString: String | ||
/// Scanned year: YYYY | ||
let year: Int | ||
/// Scanned year short: YY | ||
let shortYear: Int | ||
|
||
init(_ month: Int, year: Int) { | ||
self.month = month | ||
// Normalize month to format "01" | ||
self.monthString = Self.formatMonthString(from: month) | ||
self.year = year | ||
self.shortYear = year - 2000 | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
/// Maps scanned exp month and year to valid format (MM/YY). | ||
/// - Returns: `String`, composed text or nil if scanned info is invalid. | ||
func mapDefaultExpirationDate() -> String { | ||
return "\(monthString)\(shortYear)" | ||
} | ||
|
||
/// Maps scanned exp month and year to long expiration date format (MM/YYYY). | ||
/// - Returns: `String`, composed text or nil if scanned info is invalid. | ||
func mapLongExpirationDate() -> String { | ||
return "\(monthString)\(year)" | ||
} | ||
|
||
/// Maps scanned exp month and year to valid format starting with year (YY/MM). | ||
/// - Returns: `String`, composed text or nil if scanned info is invalid. | ||
func mapExpirationDateWithShortYearFirst() -> String { | ||
return "\(shortYear)\(monthString)" | ||
} | ||
|
||
/// Maps scanned exp month and year to long expiration date format starting with year (YYYY/MM). | ||
/// - Returns: `String`, composed text or nil if scanned info is invalid. | ||
func mapLongExpirationDateWithLongYearFirst() -> String { | ||
return "\(year)\(monthString)" | ||
} | ||
|
||
/// Formats month int. | ||
/// - Parameter monthInt: `Int`, should be month. | ||
/// - Returns: `String` object, formatted month. | ||
private static func formatMonthString(from monthInt: Int) -> String { | ||
// Add `0` for month less than 10. | ||
let monthString = monthInt < 10 ? "0\(monthInt)" : "\(monthInt)" | ||
return monthString | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Sources/VGSBlinkCardCollector/VGSBlinkCardController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// VGSBlinkCardController.swift | ||
// VGSBlinkCardCollector | ||
// | ||
|
||
import Foundation | ||
#if !COCOAPODS | ||
import VGSCollectSDK | ||
#endif | ||
#if os(iOS) | ||
import UIKit | ||
#endif | ||
|
||
/// Controller responsible for managing `BlinkCard` scanner. | ||
@available(iOS 13.0, *) | ||
public class VGSBlinkCardController { | ||
|
||
// MARK: - Attributes | ||
|
||
/// Handle card scanner events. | ||
internal var scanHandler: VGSBlinkCardHandler? | ||
|
||
/// `VGSBlinkCardControllerDelegate` - handle user interaction with `BlinkCard` scanner. | ||
public var delegate: VGSBlinkCardControllerDelegate? { | ||
set { | ||
scanHandler?.delegate = newValue | ||
} | ||
get { | ||
return scanHandler?.delegate | ||
} | ||
} | ||
|
||
// MARK: - Initialization | ||
|
||
/// Initialization | ||
/// - Parameters: | ||
/// - licenseKey: key required for BlinkCard SDK usage. | ||
/// - delegate: `VGSBlinkCardControllerDelegate`. Default is `nil`. | ||
/// - errorCallback: Error callback with Int error code(represents `MBCLicenseError` enum), triggered only when error occured. | ||
public required init(licenseKey: String, delegate: VGSBlinkCardControllerDelegate? = nil, onError errorCallback: @escaping ((NSInteger) -> Void)) { | ||
self.scanHandler = VGSBlinkCardHandler(licenseKey: licenseKey, errorCallback: errorCallback) | ||
self.delegate = delegate | ||
|
||
} | ||
|
||
// MARK: - Methods | ||
|
||
/// Present `BlinkCard` scanner. | ||
/// - Parameters: | ||
/// - viewController: `UIViewController` that will present card scanner. | ||
/// - animated: pass `true` to animate the presentation; otherwise, pass `false`. | ||
/// - modalPresentationStyle: `UIModalPresentationStyle` object, modal presentation style. Default is `.overCurrentContext`. | ||
/// - completion: the block to execute after the presentation finishes. | ||
public func presentCardScanner(on viewController: UIViewController, animated: Bool, modalPresentationStyle: UIModalPresentationStyle = .overCurrentContext, completion: (() -> Void)?) { | ||
scanHandler?.presentScanVC(on: viewController, animated: animated, modalPresentationStyle: modalPresentationStyle, completion: completion) | ||
} | ||
|
||
/// Dismiss `BlinkCard` scanner. | ||
/// - Parameters: | ||
/// - animated: pass `true` to animate the dismiss of presented viewcontroller; otherwise, pass `false`. | ||
/// - completion: the block to execute after the dismiss finishes. | ||
public func dismissCardScanner(animated: Bool, completion: (() -> Void)?) { | ||
scanHandler?.dismissScanVC(animated: animated, completion: completion) | ||
} | ||
|
||
/// Set custom localization fileName. | ||
public static func setCustomLocalization(fileName: String) { | ||
VGSBlinkCardHandler.setCustomLocalization(fileName: fileName) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Sources/VGSBlinkCardCollector/VGSBlinkCardControllerDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// VGSBlinkCardControllerDelegate.swift | ||
// VGSBlinkCardCollector | ||
// | ||
|
||
import Foundation | ||
#if !COCOAPODS | ||
import VGSCollectSDK | ||
#endif | ||
#if os(iOS) | ||
import UIKit | ||
#endif | ||
|
||
/// Supported scan data fields by BlinkCard. | ||
@objc | ||
public enum VGSBlinkCardDataType: Int { | ||
|
||
/// Credit Card Number. Digits string. | ||
case cardNumber | ||
|
||
/// Card holder name displayed on card. | ||
case name | ||
|
||
/// Card cvc. | ||
case cvc | ||
|
||
/// Credit Card Expiration Date. String in format "mm/yy", e.g: "01/21". | ||
case expirationDate | ||
|
||
/// Credit Card Expiration Month. String in format "mm", e.g:"01". | ||
case expirationMonth | ||
|
||
/// Credit Card Expiration Year. String in format "yy", e.g: "21". | ||
case expirationYear | ||
|
||
/// Credit Card Expiration Year. String in format "yyyy", e.g:"2021". | ||
case expirationYearLong | ||
|
||
/// Credit Card Expiration Date. String in format "mm/yyyy", e.g:"01/2021". | ||
case expirationDateLong | ||
|
||
/// Credit Card Expiration Date. String in format "yy/mm", e.g:"21/01". | ||
case expirationDateShortYearThenMonth | ||
|
||
/// Credit Card Expiration Date. String in format "yyyy/mm", e.g:"2021/01". | ||
case expirationDateLongYearThenMonth | ||
} | ||
|
||
/// Delegates produced by `VGSBlinkCardController` instance. | ||
@objc | ||
public protocol VGSBlinkCardControllerDelegate { | ||
|
||
// MARK: - Handle user ineraction with `BlinkCard` | ||
|
||
/// On user confirm scanned data by selecting Done button on `BlinkCard` screen. | ||
@objc func userDidFinishScan() | ||
|
||
/// On user press Cancel buttonn on `BlinkCard` screen. | ||
@objc func userDidCancelScan() | ||
|
||
// MARK: - Manage scanned data | ||
|
||
/// Asks `VGSTextField` where scanned data with `VGSConfiguration.FieldType` need to be set. Called after user select Done button, just before userDidFinishScan() delegate. | ||
@objc func textFieldForScannedData(type: VGSBlinkCardDataType) -> VGSTextField? | ||
} |
Oops, something went wrong.