diff --git a/gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift b/gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift index 0b8681f..08e1f88 100644 --- a/gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift +++ b/gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift @@ -11,6 +11,7 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable { case int(Int) case bool(Bool) case double(Double) + case dictionary([String: String]) private enum CodingError: Error { case unknownValue @@ -26,6 +27,8 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable { self = .double(doubleValue) } else if let stringValue = try? container.decode(String.self) { self = .string(stringValue) + } else if let dictionaryValue = try? container.decode([String: String].self) { + self = .dictionary(dictionaryValue) } else { throw CodingError.unknownValue } @@ -42,6 +45,8 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable { try container.encode(value) case .double(let value): try container.encode(value) + case .dictionary(let value): + try container.encode(value) } } } diff --git a/gr4vy-iOSTests/gr4vy_iOSTests.swift b/gr4vy-iOSTests/gr4vy_iOSTests.swift index bc4d0ad..59b5ee9 100644 --- a/gr4vy-iOSTests/gr4vy_iOSTests.swift +++ b/gr4vy-iOSTests/gr4vy_iOSTests.swift @@ -894,7 +894,8 @@ class gr4vy_iOSTests: XCTestCase { ["key1": ["subKey1": .string("value1")], "key2": ["subKey1": .bool(true)]], ["key1": ["subKey1": .int(1)], "key2": ["subKey1": .bool(true)]], ["key1": ["subKey1": .string("value1"), "subKey2": .int(1)], "key2": ["subKey1": .int(1), "subKey2": .bool(true)]], - ["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]] + ["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]], + ["key1": ["subKey1": .dictionary(["key1": "value1"])]], ] for permutation in permutations { @@ -939,6 +940,13 @@ class gr4vy_iOSTests: XCTestCase { XCTAssertEqual("window.postMessage({ \"channel\": 123, \"type\": \"updateOptions\", \"data\": {\"amount\":100,\"apiHost\":\"api.ID123.gr4vy.app\",\"apiUrl\":\"https:\\/\\/api.ID123.gr4vy.app\",\"buyerId\":\"BUYER123\",\"connectionOptions\":{\"cybersource-anti-fraud\":{\"merchant_defined_data\":\"value\"}},\"country\":\"GB\",\"currency\":\"GBP\",\"supportedApplePayVersion\":0,\"token\":\"TOKEN123\"}})", sut) + setup.connectionOptions = [ + "cybersource-anti-fraud": ["merchant_defined_data": .dictionary(["key": "value"])] + ] + sut = Gr4vyUtility.generateUpdateOptions(from: setup) + + XCTAssertEqual("window.postMessage({ \"channel\": 123, \"type\": \"updateOptions\", \"data\": {\"amount\":100,\"apiHost\":\"api.ID123.gr4vy.app\",\"apiUrl\":\"https:\\/\\/api.ID123.gr4vy.app\",\"buyerId\":\"BUYER123\",\"connectionOptions\":{\"cybersource-anti-fraud\":{\"merchant_defined_data\":{\"key\":\"value\"}}},\"country\":\"GB\",\"currency\":\"GBP\",\"supportedApplePayVersion\":0,\"token\":\"TOKEN123\"}})", sut) + setup.connectionOptions = [:] sut = Gr4vyUtility.generateUpdateOptions(from: setup) XCTAssertEqual("window.postMessage({ \"channel\": 123, \"type\": \"updateOptions\", \"data\": {\"amount\":100,\"apiHost\":\"api.ID123.gr4vy.app\",\"apiUrl\":\"https:\\/\\/api.ID123.gr4vy.app\",\"buyerId\":\"BUYER123\",\"connectionOptions\":{},\"country\":\"GB\",\"currency\":\"GBP\",\"supportedApplePayVersion\":0,\"token\":\"TOKEN123\"}})", sut) @@ -958,7 +966,8 @@ class gr4vy_iOSTests: XCTestCase { ["key1": ["subKey1": .string("value1")], "key2": ["subKey1": .bool(true)]], ["key1": ["subKey1": .int(1)], "key2": ["subKey1": .bool(true)]], ["key1": ["subKey1": .string("value1"), "subKey2": .int(1)], "key2": ["subKey1": .int(1), "subKey2": .bool(true)]], - ["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]] + ["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]], + ["key1": ["subKey1": .dictionary(["key1": "value1"])]], ] for permutation in permutations { diff --git a/gr4vy-ios.podspec b/gr4vy-ios.podspec index cf94aa3..8149da4 100644 --- a/gr4vy-ios.podspec +++ b/gr4vy-ios.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'gr4vy-ios' - s.version = '2.4.0' + s.version = '2.4.1' s.license = 'MIT' s.summary = 'Quickly embed Gr4vy in your iOS app to store card details, authorize payments, and capture a transaction.' s.homepage = 'https://github.com/gr4vy/gr4vy-ios'