Skip to content

Commit

Permalink
Public release 1.14.0 (#349) (#350)
Browse files Browse the repository at this point in the history
* Revert "Add VGSDateTextField."

This reverts commit 92c1e50.

* Bump SDK version
  • Loading branch information
DonaldRG committed Jun 19, 2023
1 parent 5206e5b commit fcbbd6e
Show file tree
Hide file tree
Showing 49 changed files with 3,842 additions and 532 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ workflows:
build-and-test:
jobs:
- build-and-test-sdk
- build-and-ui-test-demo-app-ios-16-iphone14
- build-and-ui-test-demo-app-ios-16-iphone14
6 changes: 3 additions & 3 deletions Sources/VGSCollectSDK/Core/Collector/VGSCollect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class VGSCollect {
return storage.textFields
}

// MARK: - Initialzation
// MARK: - Initialization

/// Initialzation.
/// Initialization.
///
/// - Parameters:
/// - id: `String` object, your organization vault id.
Expand All @@ -72,7 +72,7 @@ public class VGSCollect {
}
}

/// Initialzation.
/// Initialization.
///
/// - Parameters:
/// - id: `String` object, your organization vault id.
Expand Down
16 changes: 14 additions & 2 deletions Sources/VGSCollectSDK/Core/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public enum FieldType: Int, CaseIterable {
/// Field type that requires Expiration Date input formatting and validation.
case expDate

/// Field type that requires Date input formatting and validation.
case date

/// Field type that requires Credit Card CVC input formatting and validation.
case cvc

Expand Down Expand Up @@ -64,14 +67,16 @@ internal extension FieldType {
return DateFormatPattern.shortYear.rawValue
case .ssn:
return "###-##-####"
case .date:
return VGSDateFormat.default.formatPattern
default:
return ""
}
}

var defaultDivider: String {
switch self {
case .expDate:
case .expDate, .date:
return "/"
case .ssn:
return "-"
Expand All @@ -86,6 +91,8 @@ internal extension FieldType {
return "^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"
case .expDate:
return "^(0[1-9]|1[0-2])\\/?([0-9]{4}|[0-9]{2})$"
case .date:
return "^([0-9]{4}|[0-9]{2})\\/?([0-9]{2})\\/?([0-9]{4}|[0-9]{2})$"
case .cardHolderName:
return "^([a-zA-Z0-9\\ \\,\\.\\-\\']{2,})$"
case .ssn:
Expand All @@ -100,7 +107,7 @@ internal extension FieldType {

var keyboardType: UIKeyboardType {
switch self {
case .cardNumber, .cvc, .expDate, .ssn:
case .cardNumber, .cvc, .expDate, .date, .ssn:
return .asciiCapableNumberPad
default:
return .alphabet
Expand All @@ -115,6 +122,9 @@ internal extension FieldType {
case .expDate:
rules.add(rule: VGSValidationRulePattern(pattern: self.defaultRegex, error: VGSValidationErrorType.pattern.rawValue))
rules.add(rule: VGSValidationRuleCardExpirationDate(error: VGSValidationErrorType.expDate.rawValue))
case .date:
rules.add(rule: VGSValidationRulePattern(pattern: self.defaultRegex, error: VGSValidationErrorType.pattern.rawValue))
rules.add(rule: VGSValidationRuleDateRange(error: VGSValidationErrorType.date.rawValue))
case .cardNumber:
rules.add(rule: VGSValidationRulePaymentCard(error: VGSValidationErrorType.cardNumber.rawValue))
case .cvc:
Expand All @@ -137,6 +147,8 @@ internal extension FieldType {
return "card-security-code"
case .expDate:
return "card-expiration-date"
case .date:
return "date"
case .ssn:
return "ssn"
case .none:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// VGSDateTokenizationConfiguration.swift
// VGSCollectSDK
//

import Foundation

/// `VGSDateTokenizationParameters` - parameters required for tokenization API
public struct VGSDateTokenizationParameters: VGSTokenizationParametersProtocol {

/// Vault storage type.
public var storage: String = VGSVaultStorageType.PERSISTENT.rawValue

/// Data alies format.
public var format: String = VGSVaultAliasFormat.UUID.rawValue
}

/// Class responsible for configuration `VGSDateTextField` or `VGSTextField` with `fieldType = .date`.
/// Extends `VGSConfiguration`. Required to work with tokenization API.
public final class VGSDateTokenizationConfiguration: VGSConfiguration, VGSDateConfigurationProtocol, VGSTextFieldTokenizationConfigurationProtocol, VGSFormatSerializableProtocol {

// MARK: - Properties
/// Start date used to fill out the date picker
private var datePickerStartDate: VGSDate = VGSDateConfiguration.minValidPickerStartDate

/// End date used to fill out the date picker
private var datePickerEndDate: VGSDate = VGSDateConfiguration.maxValidPickerEndDate

/// Get the list of years from `datePickerStartDate` to `datePickerEndDate`.
/// In case any of the dates are not set, it will use the default
/// values `minValidStartDate` and `maxValidEndDate` respectively
internal var years: [Int] {
Array(datePickerStartDate.year...datePickerEndDate.year)
}

// MARK: - Constructor
/// Initialization
/// Date configuration initializer, if no `datePickerStartDate` is provided,
/// a default date will be used adding 100 years to the current date.
/// Similar approach will be used if `datePickerEndDate` is not provided,
/// it will be calculated removing 100 years from current date.
///
/// - Parameters:
/// - vgs: `VGSCollect` instance.
/// - fieldName: associated `fieldName`.
/// - datePickerStartDate: optional `VGSDate` instance.
/// - datePickerEndDate: optional `VGSDate` instance.
public init(collector vgs: VGSCollect,
fieldName: String,
datePickerStartDate: VGSDate? = nil,
datePickerEndDate: VGSDate? = nil) {
/// Setup custom picker start date
if let startDate = datePickerStartDate {
self.datePickerStartDate = startDate
}
/// Setup custom picker end date
if let endDate = datePickerEndDate {
self.datePickerEndDate = endDate
}
/// Super initializer
super.init(collector: vgs, fieldName: fieldName)
}

// MARK: - Overridden methods and properties
public override var type: FieldType {
get { return .date }
set {}
}

// MARK: - VGSDateConfigurationProtocol implementation
public var inputSource: VGSTextFieldInputSource = .datePicker
public var inputDateFormat: VGSDateFormat?
public var outputDateFormat: VGSDateFormat?

// MARK: - VGSFormatSerializableProtocol implementation
public var serializers: [VGSFormatSerializerProtocol] = []
func serialize(_ content: String) -> [String: Any] {
return DateFormatConvertor.serialize(content, serializers: serializers, outputFormat: outputDateFormat)
}
internal var shouldSerialize: Bool {
return !serializers.isEmpty
}

// MARK: - VGSDateTokenizationParameters implementation
public var tokenizationParameters = VGSDateTokenizationParameters()
internal var tokenizationConfiguration: VGSTokenizationParametersProtocol {
return tokenizationParameters
}
}

// MARK: - `TextFormatConvertable` implementation
extension VGSDateTokenizationConfiguration: VGSTextFormatConvertable {

/// :nodoc:
var inputFormat: InputConvertableFormat? {
return inputDateFormat
}

/// :nodoc:
var outputFormat: OutputConvertableFormat? {
return outputDateFormat
}

/// :nodoc:
var convertor: TextFormatConvertor {
return DateFormatConvertor()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class VGSExpDateTokenizationConfiguration: VGSConfiguration, VGSExp
// MARK: - `VGSExpDateConfiguration` implementation
/// Serialize Expiration Date
internal func serialize(_ content: String) -> [String: Any] {
return ExpDateFormatConvertor.serialize(content, serializers: serializers, outputFormat: outputFormat)
return ExpDateFormatConvertor.serialize(content, serializers: serializers, outputFormat: outputDateFormat)
}

/// Returns if Content should be Serialized
Expand All @@ -58,18 +58,18 @@ public final class VGSExpDateTokenizationConfiguration: VGSConfiguration, VGSExp
}
}

/// Implement `FormatConvertable` protocol.
extension VGSExpDateTokenizationConfiguration: FormatConvertable {

internal var outputFormat: VGSCardExpDateFormat? {
return outputDateFormat
}

internal var inputFormat: VGSCardExpDateFormat? {
return inputDateFormat
}
/// Implement `TextFormatConvertable` protocol.
extension VGSExpDateTokenizationConfiguration: VGSTextFormatConvertable {
var inputFormat: InputConvertableFormat? {
return inputDateFormat
}
var outputFormat: OutputConvertableFormat? {
return outputDateFormat
}

internal var convertor: TextFormatConvertor {
return ExpDateFormatConvertor()
}
internal var convertor: TextFormatConvertor {
return ExpDateFormatConvertor()
}
}
84 changes: 84 additions & 0 deletions Sources/VGSCollectSDK/Core/VGSDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// VGSDate.swift
// VGSCollectSDK
//

import Foundation

/// `Struct` that represents a date including `year`, `month` and `day`. It doesn't include `hours`, `minutes` or `seconds`.
public struct VGSDate {

// MARK: - Properties
public var day: Int
public var month: Int
public var year: Int

/// Get the day formatted value, for example if the day is `1` it is returned as `01`
public var dayFormatted: String {
return String(format: "%02d", day)
}

/// Get the month formatted value, for example if the month is `3` it is returned as `03`
public var monthFormatted: String {
return String(format: "%02d", month)
}

// MARK: - Initialization
/// Create a new instance of a `VGSDate` object, if the date is not valid, it returns `nil`
/// - Parameters:
/// - day: `Int`. Represents the day in the date.
/// - month: `Int`. Represents the month in the date.
/// - year: `Int`. Represents the year in the date.
/// - Returns: `VGSDate`, date reference or nil if the date is invalid.
public init?(day: Int, month: Int, year: Int) {
// Make sure it is a valid date
guard DateComponents(
calendar: Calendar(identifier: .gregorian),
year: year,
month: month,
day: day
).isValidDate else {
let message = "Invalid day, month or year to create date at VGSDate initializer"
let event = VGSLogEvent(level: .warning, text: message, severityLevel: .error)
VGSCollectLogger.shared.forwardLogEvent(event)
return nil
}
// Save date data
self.day = day
self.month = month
self.year = year
}
}

// MARK: - Equatable and Comparable implementation
extension VGSDate: Comparable {

/// :nodoc:
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.year == rhs.year &&
lhs.month == rhs.month &&
lhs.day == rhs.day
}

/// :nodoc:
public static func < (lhs: VGSDate, rhs: VGSDate) -> Bool {
// Check year
if lhs.year < rhs.year {
return true
}
// If the year is equal, check month
else if lhs.year == rhs.year {
// Check month
if lhs.month < rhs.month {
return true
}
// If the month is equal, check day
else if lhs.month == rhs.month {
// Check day
return lhs.day < rhs.day
}
}
// The date at left is not less than date at right
return false
}
}
Loading

0 comments on commit fcbbd6e

Please sign in to comment.