Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.3.0 - Added connectionOptionsString #13

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading