Skip to content

Commit

Permalink
2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
adyen-git-manager authored and Diego Marcon committed Oct 5, 2018
1 parent 2735400 commit cc48081
Show file tree
Hide file tree
Showing 62 changed files with 1,294 additions and 1,241 deletions.
2 changes: 1 addition & 1 deletion Adyen.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/Adyen/adyen-ios.git', :tag => "#{s.version}" }
s.platform = :ios
s.ios.deployment_target = '9.3'
s.swift_version = '4.1'
s.swift_version = '4.2'
s.frameworks = 'Foundation'
s.default_subspecs = 'Core', 'Card', 'SEPA'

Expand Down
169 changes: 92 additions & 77 deletions Adyen.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Adyen.xcodeproj/xcshareddata/xcschemes/Adyen.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Adyen.xcodeproj/xcshareddata/xcschemes/AdyenCard.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Adyen.xcodeproj/xcshareddata/xcschemes/AdyenSEPA.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
79 changes: 74 additions & 5 deletions Adyen/Core/Models/PaymentDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public struct PaymentDetail: Decodable {
/// A boolean value indicating whether filling this payment detail is optional.
public let isOptional: Bool

/// Configuration specific to this payment detail.
public let configuration: Configuration

/// Creates a new instance by decoding from the given decoder.
///
/// This initializer throws an error if reading from the decoder fails, or if the data read is corrupted or otherwise invalid.
Expand All @@ -33,6 +36,7 @@ public struct PaymentDetail: Decodable {
self.key = try container.decode(String.self, forKey: .key)
self.value = try container.decodeIfPresent(String.self, forKey: .value)
self.isOptional = try container.decodeIfPresent(Bool.self, forKey: .isOptional) ?? false
self.configuration = try container.decodeIfPresent(Configuration.self, forKey: .configuration) ?? Configuration()

do {
self.inputType = try InputType(from: decoder)
Expand All @@ -48,19 +52,21 @@ public struct PaymentDetail: Decodable {
/// - value: The current value of the payment detail.
/// - inputType: The type of input requested.
/// - isOptional: A boolean value indicating whether filling this payment detail is optional.
/// - selectItems: An array of possible values to choose from. Present when inputType is select.
internal init(key: String, value: String? = nil, inputType: InputType = .text, isOptional: Bool = false) {
/// - configuration: Configuration for this payment detail.
internal init(key: String, value: String? = nil, inputType: InputType = .text, isOptional: Bool = false, configuration: Configuration = Configuration()) {
self.key = key
self.value = value
self.inputType = inputType
self.isOptional = isOptional
self.configuration = configuration
}

// MARK: - Coding Keys

private enum CodingKeys: String, CodingKey {
case key
case value
case configuration
case isOptional = "optional"
}

Expand Down Expand Up @@ -90,7 +96,19 @@ public extension PaymentDetail {
case applePayToken

/// Address input type.
case address
case address([PaymentDetail])

/// Email address input type.
case emailAddress

/// Phone number input type.
case phone

/// Date input type.
case date

/// Details input type.
case fieldSet([PaymentDetail])

/// :nodoc:
public init(from decoder: Decoder) throws {
Expand All @@ -101,7 +119,7 @@ public extension PaymentDetail {
self = .text
case "boolean":
self = .boolean
case "select":
case "select", "radio":
let selectItems = try container.decode([SelectItem].self, forKey: .selectItems)

self = .select(selectItems)
Expand All @@ -112,7 +130,19 @@ public extension PaymentDetail {
case "applePayToken":
self = .applePayToken
case "address":
self = .address
let details = try container.decode([PaymentDetail].self, forKey: .details)

self = .address(details)
case "emailAddress":
self = .emailAddress
case "tel":
self = .phone
case "date":
self = .date
case "fieldSet":
let details = try container.decode([PaymentDetail].self, forKey: .details)

self = .fieldSet(details)
default:
let context = DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Unknown value (\(type)) for input type.")

Expand All @@ -125,6 +155,7 @@ public extension PaymentDetail {
private enum CodingKeys: String, CodingKey {
case inputType = "type"
case selectItems = "items"
case details
}

// MARK: - Equatable
Expand Down Expand Up @@ -177,3 +208,41 @@ public extension PaymentDetail {
}

}

// MARK: - PaymentDetail.Configuration

public extension PaymentDetail {
/// A structure representing configuration for payment details with type `fieldset`.
public struct Configuration: Decodable, Equatable {

/// Enum specifying the visibility of a field.
public enum FieldVisibility: String {
case editable, hidden, readOnly
}

/// A string representing the visibility of given payment detail.
public let fieldVisibility: FieldVisibility

/// :nodoc:
public init() {
fieldVisibility = .editable
}

/// :nodoc:
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let rawFieldVisibility = try container.decodeIfPresent(String.self, forKey: .fieldVisibility)

if let rawFieldVisibility = rawFieldVisibility, let visibility = FieldVisibility(rawValue: rawFieldVisibility) {
self.fieldVisibility = visibility
} else {
self.fieldVisibility = .editable
}
}

private enum CodingKeys: String, CodingKey {
case fieldVisibility
}
}

}
3 changes: 1 addition & 2 deletions Adyen/Core/Models/StoredPaymentDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import Foundation

/// Conforming instances provide access to payment details from previously used payment methods.
public protocol StoredPaymentDetails: Decodable {
}
public protocol StoredPaymentDetails: Decodable {}

/// Contains payment details from a previously used card.
public struct StoredCardPaymentDetails: StoredPaymentDetails {
Expand Down
3 changes: 1 addition & 2 deletions Adyen/Core/Networking/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ internal protocol Request: Encodable {
}

/// The response to a request sent using an APIClient.
internal protocol Response: Decodable {
}
internal protocol Response: Decodable {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
import Foundation

/// The response to a stored payment method deletion request.
internal struct StoredPaymentMethodDeletionResponse: Response {
}
internal struct StoredPaymentMethodDeletionResponse: Response {}
2 changes: 1 addition & 1 deletion Adyen/Core/Payment Controller/PaymentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public final class PaymentController {
let returnURLQueryDetail = PaymentDetail(key: "returnUrlQueryString", value: returnURL.query)

var request = request
request.paymentMethod.details.append(returnURLQueryDetail)
request.paymentDetails.append(returnURLQueryDetail)
initiatePayment(with: request)
}

Expand Down
12 changes: 9 additions & 3 deletions Adyen/Core/Plugins/PaymentDetailKeyValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ public extension Array where Element == PaymentDetail {
/// Returns a dictionary of the filled payment details.
internal var serialized: [String: Any] {
let elements = compactMap { paymentDetail -> (String, Any)? in
guard let value = paymentDetail.value else { return nil }

return (paymentDetail.key, value)
switch paymentDetail.inputType {

case let .fieldSet(details), let .address(details):
return (paymentDetail.key, details.serialized)

default:
guard let value = paymentDetail.value else { return nil }
return (paymentDetail.key, value)
}
}

return Dictionary(uniqueKeysWithValues: elements)
Expand Down
9 changes: 4 additions & 5 deletions Adyen/Core/Plugins/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ open class Plugin: NSObject {
self.appearance = appearance
}

open let paymentMethod: PaymentMethod
open let paymentSession: PaymentSession
open let appearance: Appearance
public let paymentMethod: PaymentMethod
public let paymentSession: PaymentSession
public let appearance: Appearance
open var additionalPaymentDetails: AdditionalPaymentDetails?

open var showsDisclosureIndicator: Bool {
Expand All @@ -32,8 +32,7 @@ open class Plugin: NSObject {
return true
}

open func present(using navigationController: UINavigationController, completion: @escaping Completion<[PaymentDetail]>) {
}
open func present(using navigationController: UINavigationController, completion: @escaping Completion<[PaymentDetail]>) {}

open func finish(with result: Result<PaymentResult>, completion: @escaping () -> Void) {
completion()
Expand Down
45 changes: 45 additions & 0 deletions Adyen/Core/Utilities/Validator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright (c) 2018 Adyen B.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

public protocol Validator {
func isValid(_ string: String) -> Bool
func isMaxLength(_ string: String) -> Bool
func format(_ string: String) -> String
func sanitize(_ string: String) -> String
}

public extension Validator {
func isValid(_ string: String) -> Bool {
return true
}

func isMaxLength(_ string: String) -> Bool {
return false
}

func format(_ string: String) -> String {
return string
}

func sanitize(_ string: String) -> String {
return string
}
}

public protocol NumericValidator: Validator {}

public extension NumericValidator {
func sanitize(_ string: String) -> String {
let allowedCharacters = CharacterSet.decimalDigits
let filteredUnicodeScalars = string.unicodeScalars.filter(allowedCharacters.contains(_:))

let sanitizedString = filteredUnicodeScalars.reduce("") { (string, unicodeScalar) -> String in
return string + String(unicodeScalar)
}

return sanitizedString
}
}
Loading

0 comments on commit cc48081

Please sign in to comment.