Skip to content

Commit

Permalink
Release v2.3.0 - Added connectionOptionsString (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: AG <[email protected]>
  • Loading branch information
AJ9 and AG authored Jul 18, 2024
1 parent 35a4b8e commit e27aa88
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 78 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ gr4vy-ios doesn't contain any external dependencies.
use_frameworks!

target 'YOUR_TARGET_NAME' do
pod 'gr4vy-ios', '2.2.1'
pod 'gr4vy-ios', '2.3.0'
end
```

Expand Down Expand Up @@ -143,6 +143,7 @@ These are the parameteres available on the `launch` method:
| `shippingDetailsId`| `Optional` | An optional unique identifier of a set of shipping details stored for the buyer. |
| `merchantAccountId`| `Optional` | An optional merchant account ID. |
| `connectionOptions`| `Optional` | An optional set of options passed to a connection when processing a transaction (see https://docs.gr4vy.com/reference#operation/authorize-new-transaction) |
| `connectionOptionsString`| `Optional` | A JSON String of connectionOptions |
| `debugMode`| `Optional` | `true`, `false`. Defaults to `false`, this prints to the console. |
| `onEvent` | `Optional` | **Please see below for more details.** |

Expand Down
3 changes: 2 additions & 1 deletion gr4vy-iOS/Gr4vy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Gr4vy {
shippingDetailsId: String? = nil,
merchantAccountId: String? = nil,
connectionOptions: [String: [String: Gr4vyConnectionOptionsValue]]? = nil,
connectionOptionsString: String? = nil,
debugMode: Bool = false,
onEvent: Gr4vyCompletionHandler? = nil) {

Expand All @@ -84,7 +85,7 @@ public class Gr4vy {
requireSecurityCode: requireSecurityCode,
shippingDetailsId: shippingDetailsId,
merchantAccountId: merchantAccountId,
connectionOptions: connectionOptions)
connectionOptions: Gr4vyUtility.getConnectionOptions(from: connectionOptions, connectionOptionsString: connectionOptionsString))

self.debugMode = debugMode
self.onEvent = onEvent
Expand Down
25 changes: 24 additions & 1 deletion gr4vy-iOS/Gr4vyUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ struct Gr4vyUtility {
return URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData)
}

static func getConnectionOptions(from connectionOptions: [String: [String: Gr4vyConnectionOptionsValue]]?, connectionOptionsString: String?) -> [String: [String: Gr4vyConnectionOptionsValue]]? {
if let connectionOptions = connectionOptions {
return connectionOptions
}
guard let connectionOptionsString else {
return nil
}

typealias Gr4vyConnectionOptions = [String: [String: Gr4vyConnectionOptionsValue]]

guard let data = connectionOptionsString.data(using: .utf8) else {
return nil
}
let decoder = JSONDecoder()

do {
let decodedData = try decoder.decode(Gr4vyConnectionOptions.self, from: data)
return decodedData
} catch {
return nil
}
}


static func generateUpdateOptions(from setup: Gr4vySetup) -> String {
var mutableSetup = setup
Expand All @@ -36,7 +59,7 @@ struct Gr4vyUtility {
do {
let jsonData = try encoder.encode(mutableSetup)
let jsonString = String(data: jsonData, encoding: .utf8) ?? "{}"

let windowMessage = "window.postMessage({ \"channel\": 123, \"type\": \"updateOptions\", \"data\": \(jsonString)})"

return windowMessage
Expand Down
2 changes: 1 addition & 1 deletion gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

public enum Gr4vyConnectionOptionsValue: Codable {
public enum Gr4vyConnectionOptionsValue: Codable, Equatable {
case string(String)
case int(Int)
case bool(Bool)
Expand Down
Loading

0 comments on commit e27aa88

Please sign in to comment.