Skip to content

Commit

Permalink
2.0.0 (#6)
Browse files Browse the repository at this point in the history
Fixed tests

Co-authored-by: AG <[email protected]>
  • Loading branch information
AJ9 and AG authored Feb 26, 2024
1 parent 62507d7 commit 7245b8f
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 424 deletions.
6 changes: 4 additions & 2 deletions Gr4vy UIKit Sample App/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class CheckoutViewController: UIViewController {
borderWidths: Gr4vyBorderWidths(container: "thin", input: "thin"),
radii: Gr4vyRadii(container: "subtle", input: "subtle"),
shadows: Gr4vyShadows(focusRing: "0 0 0 2px #ffffff, 0 0 0 4px #4844ff")),
connectionOptions: Gr4vyConnectionOptions(data: [
requireSecurityCode: true,
connectionOptions:[
"forter-anti-fraud": [
"is_guest_buyer": false]]),
"is_guest_buyer": .bool(true)]],

debugMode: true
) else {
print("Unable to load Gr4vy")
Expand Down
2 changes: 1 addition & 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', '1.8.0'
pod 'gr4vy-ios', '2.0.0'
end
```

Expand Down
12 changes: 4 additions & 8 deletions gr4vy-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
59160F7A2AF6EDDD00143DA2 /* Gr4vyConnectionOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptions.swift */; };
59160F7A2AF6EDDD00143DA2 /* Gr4vyConnectionOptionsValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptionsValue.swift */; };
592C4BBC28BF9AEE00063AC7 /* Gr4vy_SwiftUI_Sample_App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 592C4BBB28BF9AEE00063AC7 /* Gr4vy_SwiftUI_Sample_App.swift */; };
592C4BC028BF9AEF00063AC7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 592C4BBF28BF9AEF00063AC7 /* Assets.xcassets */; };
592C4BC328BF9AEF00063AC7 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 592C4BC228BF9AEF00063AC7 /* Preview Assets.xcassets */; };
Expand All @@ -34,7 +34,6 @@
59C5D46229F162C0008FFEBC /* Gr4vyStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C5D46129F162C0008FFEBC /* Gr4vyStore.swift */; };
59D09964274654C70086348B /* Gr4vyLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59D09963274654C70086348B /* Gr4vyLogger.swift */; };
59F72C012A17BE2B00DD2833 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59F72C002A17BE2B00DD2833 /* UIImage+Extensions.swift */; };
59FA35752B7D21550086DFD7 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FA35742B7D21550086DFD7 /* String+Extensions.swift */; };
59FE69502722BB7A006C1C08 /* Gr4vy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FE694F2722BB7A006C1C08 /* Gr4vy.swift */; };
59FE69582722BBB2006C1C08 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FE69572722BBB2006C1C08 /* AppDelegate.swift */; };
59FE695A2722BBB2006C1C08 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FE69592722BBB2006C1C08 /* SceneDelegate.swift */; };
Expand Down Expand Up @@ -98,7 +97,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gr4vyConnectionOptions.swift; sourceTree = "<group>"; };
59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptionsValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gr4vyConnectionOptionsValue.swift; sourceTree = "<group>"; };
592C4BB928BF9AEE00063AC7 /* Gr4vy SwiftUI Sample App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Gr4vy SwiftUI Sample App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
592C4BBB28BF9AEE00063AC7 /* Gr4vy_SwiftUI_Sample_App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gr4vy_SwiftUI_Sample_App.swift; sourceTree = "<group>"; };
592C4BBF28BF9AEF00063AC7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -127,7 +126,6 @@
59C5D46129F162C0008FFEBC /* Gr4vyStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gr4vyStore.swift; sourceTree = "<group>"; };
59D09963274654C70086348B /* Gr4vyLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gr4vyLogger.swift; sourceTree = "<group>"; };
59F72C002A17BE2B00DD2833 /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = "<group>"; };
59FA35742B7D21550086DFD7 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
59FE694F2722BB7A006C1C08 /* Gr4vy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Gr4vy.swift; sourceTree = "<group>"; };
59FE69552722BBB2006C1C08 /* Gr4vy UIKit Sample App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Gr4vy UIKit Sample App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
59FE69572722BBB2006C1C08 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,7 +253,7 @@
59C5D45D29E34D32008FFEBC /* Gr4vyStatementDescriptor.swift */,
59C5D45F29E34D56008FFEBC /* Gr4vySetup.swift */,
59C5D46129F162C0008FFEBC /* Gr4vyStore.swift */,
59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptions.swift */,
59160F792AF6EDDD00143DA2 /* Gr4vyConnectionOptionsValue.swift */,
);
path = Models;
sourceTree = "<group>";
Expand All @@ -265,7 +263,6 @@
children = (
59C5D45729E34CAC008FFEBC /* Data+Extensions.swift */,
59F72C002A17BE2B00DD2833 /* UIImage+Extensions.swift */,
59FA35742B7D21550086DFD7 /* String+Extensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -484,9 +481,8 @@
files = (
59C5D45C29E34D19008FFEBC /* Gr4vyPaymentSource.swift in Sources */,
59C5D45A29E34D04008FFEBC /* Gr4vyCartItem.swift in Sources */,
59160F7A2AF6EDDD00143DA2 /* Gr4vyConnectionOptions.swift in Sources */,
59160F7A2AF6EDDD00143DA2 /* Gr4vyConnectionOptionsValue.swift in Sources */,
59FE69502722BB7A006C1C08 /* Gr4vy.swift in Sources */,
59FA35752B7D21550086DFD7 /* String+Extensions.swift in Sources */,
59F72C012A17BE2B00DD2833 /* UIImage+Extensions.swift in Sources */,
5978B28A271C7F1300F5CC00 /* gr4vy_iOS.docc in Sources */,
59C5D46029E34D56008FFEBC /* Gr4vySetup.swift in Sources */,
Expand Down
21 changes: 0 additions & 21 deletions gr4vy-iOS/Extensions/String+Extensions.swift

This file was deleted.

4 changes: 2 additions & 2 deletions gr4vy-iOS/Gr4vy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum Gr4vyEvent: Equatable {
case generalError(String)
}

public enum Gr4vyEnvironment {
public enum Gr4vyEnvironment: String, Codable {
case sandbox
case production
}
Expand Down Expand Up @@ -56,7 +56,7 @@ public class Gr4vy {
requireSecurityCode: Bool? = nil,
shippingDetailsId: String? = nil,
merchantAccountId: String? = nil,
connectionOptions: Gr4vyConnectionOptions? = nil,
connectionOptions: [String: [String: Gr4vyConnectionOptionsValue]]? = nil,
debugMode: Bool = false,
onEvent: Gr4vyCompletionHandler? = nil) {

Expand Down
134 changes: 16 additions & 118 deletions gr4vy-iOS/Gr4vyUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,132 +19,30 @@ struct Gr4vyUtility {
return URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData)
}


static func generateUpdateOptions(from setup: Gr4vySetup) -> String {
var optionalData: String = ""

if let externalIdentifier = setup.externalIdentifier {
optionalData = optionalData + ", externalIdentifier: '\(externalIdentifier)'"
}

if let store = setup.store {
optionalData = optionalData + ", store: \(store.getStringRepresentation())"
}

if let display = setup.display {
optionalData = optionalData + ", display: '\(display)'"
}

if let intent = setup.intent {
optionalData = optionalData + ", intent: '\(intent)'"
}

if let metadata = setup.metadata {
var metadataString = ", metadata: {"
for (index, key) in Array(metadata.keys).sorted().enumerated() {
guard key != "" else {
continue
}
let ending = index + 1 == metadata.count ? "" : ", "
let value = metadata[key]!
metadataString = metadataString + "\(key): '\(value)'" + ending
}
metadataString = metadataString + "}"
optionalData = optionalData + metadataString
}

if let paymentSource = setup.paymentSource {
optionalData = optionalData + ", paymentSource: '\(paymentSource.rawValue)'"
}

if let cartItems = setup.cartItems {
var cartItemsString = ", cartItems: ["
for (index, item) in cartItems.enumerated() {
let ending = index + 1 == cartItems.count ? "" : ", "
cartItemsString = cartItemsString + "{name: '\(item.name.escapingJavaScriptCharacters())', quantity: \(item.quantity), unitAmount: \(item.unitAmount), discountAmount: \(item.discountAmount), taxAmount: \(item.taxAmount)"

if item.externalIdentifier != nil {
cartItemsString += ", externalIdentifier: \(item.externalIdentifier?.escapingJavaScriptCharacters() ?? "")"
}
if item.sku != nil {
cartItemsString += ", sku: '\(item.sku?.escapingJavaScriptCharacters() ?? "")'"
}
if item.productUrl != nil {
cartItemsString += ", productUrl: '\(item.productUrl ?? "")'"
}
if item.imageUrl != nil {
cartItemsString += ", imageUrl: '\(item.imageUrl ?? "")'"
}
if item.categories != nil && item.categories!.count > 0 {
var cat = ""
var count = 0
for i in item.categories! {
let ending = count + 1 == item.categories?.count ?? 0 ? "" : ", "
cat += "'\(i.escapingJavaScriptCharacters())'" + ending
count += 1
}
cartItemsString += ", categories: [\(cat)]"
}
if item.productType != nil {
cartItemsString += ", productType: '\(item.productType?.escapingJavaScriptCharacters() ?? "")'"
}
cartItemsString += "}" + ending
}
cartItemsString = cartItemsString + "]"
optionalData = optionalData + cartItemsString
}

if let buyerId = setup.buyerId {
optionalData = optionalData + ", buyerId: '\(buyerId)'"
}
var mutableSetup = setup
mutableSetup.apiHost = "api.\(setup.instance).gr4vy.app"
mutableSetup.apiUrl = "https://api.\(setup.instance).gr4vy.app"

if let applePayMerchantId = setup.applePayMerchantId, !applePayMerchantId.isEmpty {
if deviceSupportsApplePay() {
optionalData = optionalData + ", supportedApplePayVersion: 5"
mutableSetup.supportedApplePayVersion = 5
}
} else {
optionalData = optionalData + ", supportedApplePayVersion: 0"
}

if let theme = setup.theme {
optionalData = optionalData + ", theme: \(theme.toString())"
}

if let buyerExternalIdentifier = setup.buyerExternalIdentifier {
optionalData = optionalData + ", buyerExternalIdentifier: '\(buyerExternalIdentifier)'"
}

if let locale = setup.locale {
optionalData = optionalData + ", locale: '\(locale)'"
}

if let statementDescriptor = setup.statementDescriptor {
optionalData = optionalData + ", statementDescriptor: \(statementDescriptor.toString())"
}

if let requireSecurityCode = setup.requireSecurityCode {
optionalData = optionalData + ", requireSecurityCode: '\(requireSecurityCode.description)'"
}

if let shippingDetailsId = setup.shippingDetailsId {
optionalData = optionalData + ", shippingDetailsId: '\(shippingDetailsId)'"
}

if let merchantAccountId = setup.merchantAccountId {
optionalData = optionalData + ", merchantAccountId: '\(merchantAccountId)'"
}

if let connectionOptions = setup.connectionOptions, let connectionOptionsString = connectionOptions.convertedString {
optionalData = optionalData + ", connectionOptions: \(connectionOptionsString)"
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
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
} catch {
return ""
}

let content =
"window.postMessage({ channel: 123, type: 'updateOptions', data: { apiHost: 'api.\(setup.instance).gr4vy.app', apiUrl: 'https://api.\(setup.instance).gr4vy.app', token: '\(setup.token)', amount: \(setup.amount), country: '\(setup.country)', currency: '\(setup.currency)'"
+
optionalData
+
"},})"

return content
}

static func generateAppleCompleteSession() -> String {
Expand Down
2 changes: 1 addition & 1 deletion gr4vy-iOS/Models/Gr4vyCartItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

public struct Gr4vyCartItem {
public struct Gr4vyCartItem: Codable {
let name: String
let quantity: Int
let unitAmount: Int
Expand Down
35 changes: 0 additions & 35 deletions gr4vy-iOS/Models/Gr4vyConnectionOptions.swift

This file was deleted.

47 changes: 47 additions & 0 deletions gr4vy-iOS/Models/Gr4vyConnectionOptionsValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Gr4vyConnectionOptionsValue.swift
// gr4vy-ios
//
//

import Foundation

public enum Gr4vyConnectionOptionsValue: Codable {
case string(String)
case int(Int)
case bool(Bool)
case double(Double)

private enum CodingError: Error {
case unknownValue
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let boolValue = try? container.decode(Bool.self) {
self = .bool(boolValue)
} else if let intValue = try? container.decode(Int.self) {
self = .int(intValue)
} else if let doubleValue = try? container.decode(Double.self) {
self = .double(doubleValue)
} else if let stringValue = try? container.decode(String.self) {
self = .string(stringValue)
} else {
throw CodingError.unknownValue
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let value):
try container.encode(value)
case .int(let value):
try container.encode(value)
case .bool(let value):
try container.encode(value)
case .double(let value):
try container.encode(value)
}
}
}
2 changes: 1 addition & 1 deletion gr4vy-iOS/Models/Gr4vyPaymentSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

public enum Gr4vyPaymentSource: String {
public enum Gr4vyPaymentSource: String, Codable {
case installment
case recurring
}
Loading

0 comments on commit 7245b8f

Please sign in to comment.