Skip to content

Commit 1e8fdab

Browse files
authored
fix: support connection options value dictionary (#15)
* Support dictionary value in connectionOptions * Bump version to 2.4.1 * Add tests
1 parent 9c297ce commit 1e8fdab

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable {
1111
case int(Int)
1212
case bool(Bool)
1313
case double(Double)
14+
case dictionary([String: String])
1415

1516
private enum CodingError: Error {
1617
case unknownValue
@@ -26,6 +27,8 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable {
2627
self = .double(doubleValue)
2728
} else if let stringValue = try? container.decode(String.self) {
2829
self = .string(stringValue)
30+
} else if let dictionaryValue = try? container.decode([String: String].self) {
31+
self = .dictionary(dictionaryValue)
2932
} else {
3033
throw CodingError.unknownValue
3134
}
@@ -42,6 +45,8 @@ public enum Gr4vyConnectionOptionsValue: Codable, Equatable {
4245
try container.encode(value)
4346
case .double(let value):
4447
try container.encode(value)
48+
case .dictionary(let value):
49+
try container.encode(value)
4550
}
4651
}
4752
}

gr4vy-iOSTests/gr4vy_iOSTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,8 @@ class gr4vy_iOSTests: XCTestCase {
894894
["key1": ["subKey1": .string("value1")], "key2": ["subKey1": .bool(true)]],
895895
["key1": ["subKey1": .int(1)], "key2": ["subKey1": .bool(true)]],
896896
["key1": ["subKey1": .string("value1"), "subKey2": .int(1)], "key2": ["subKey1": .int(1), "subKey2": .bool(true)]],
897-
["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]]
897+
["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]],
898+
["key1": ["subKey1": .dictionary(["key1": "value1"])]],
898899
]
899900

900901
for permutation in permutations {
@@ -939,6 +940,13 @@ class gr4vy_iOSTests: XCTestCase {
939940

940941
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)
941942

943+
setup.connectionOptions = [
944+
"cybersource-anti-fraud": ["merchant_defined_data": .dictionary(["key": "value"])]
945+
]
946+
sut = Gr4vyUtility.generateUpdateOptions(from: setup)
947+
948+
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)
949+
942950
setup.connectionOptions = [:]
943951
sut = Gr4vyUtility.generateUpdateOptions(from: setup)
944952
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 {
958966
["key1": ["subKey1": .string("value1")], "key2": ["subKey1": .bool(true)]],
959967
["key1": ["subKey1": .int(1)], "key2": ["subKey1": .bool(true)]],
960968
["key1": ["subKey1": .string("value1"), "subKey2": .int(1)], "key2": ["subKey1": .int(1), "subKey2": .bool(true)]],
961-
["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]]
969+
["key1": ["subKey1": .string("value1"), "subKey2": .bool(true)], "key2": ["subKey1": .int(1), "subKey2": .string("value2")]],
970+
["key1": ["subKey1": .dictionary(["key1": "value1"])]],
962971
]
963972

964973
for permutation in permutations {

gr4vy-ios.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'gr4vy-ios'
3-
s.version = '2.4.0'
3+
s.version = '2.4.1'
44
s.license = 'MIT'
55
s.summary = 'Quickly embed Gr4vy in your iOS app to store card details, authorize payments, and capture a transaction.'
66
s.homepage = 'https://github.com/gr4vy/gr4vy-ios'

0 commit comments

Comments
 (0)