@jimrising/easymerchantsdk-react-native 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/caches/deviceStreaming.xml +11 -0
- package/.idea/workspace.xml +19 -15
- package/README.md +46 -35
- package/ios/Classes/EasyMerchantSdk.m +7 -65
- package/ios/Classes/EasyMerchantSdk.swift +70 -150
- package/ios/Classes/EasyPayViewController.swift +4 -0
- package/ios/Classes/dsd +74 -0
- package/ios/EnvironmentConfig.swift +4 -0
- package/ios/Example/ViewController.swift +72 -36
- package/ios/Helper/GrailPayHelper.swift +19 -0
- package/ios/Models/Request.swift +138 -142
- package/ios/Pods/UserDefaults/UserStoreSingleton.swift +21 -5
- package/ios/Pods/ViewControllers/GrailPayVC.swift +220 -0
- package/ios/Pods/ViewControllers/PaymentInformation/PaymentInfoVC.swift +632 -436
- package/ios/easymerchantsdk.podspec +3 -1
- package/ios/easymerchantsdk.storyboard +4092 -45
- package/package.json +1 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
//
|
|
2
|
+
//
|
|
1
3
|
//import UIKit
|
|
4
|
+
//import EasyPay
|
|
2
5
|
//
|
|
3
6
|
//class ViewController: UIViewController {
|
|
4
7
|
//
|
|
@@ -8,36 +11,48 @@
|
|
|
8
11
|
// override func viewDidLoad() {
|
|
9
12
|
// super.viewDidLoad()
|
|
10
13
|
//
|
|
11
|
-
//
|
|
12
|
-
// EnvironmentConfig.setEnvironment(.staging)
|
|
14
|
+
// // Select environment
|
|
15
|
+
// EasyPay.EnvironmentConfig.setEnvironment(.staging)
|
|
16
|
+
//
|
|
17
|
+
// // Blink Card License Setup
|
|
18
|
+
// let licenseErrorMessage = BlinkCardHelper.setupLicense()
|
|
19
|
+
// if !licenseErrorMessage.isEmpty {
|
|
20
|
+
// showLicenseErrorAlert(message: licenseErrorMessage)
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// private func showLicenseErrorAlert(message: String) {
|
|
25
|
+
// let alert = UIAlertController(title: "License Error", message: message, preferredStyle: .alert)
|
|
26
|
+
// alert.addAction(UIAlertAction(title: "OK", style: .default))
|
|
27
|
+
// self.present(alert, animated: true, completion: nil)
|
|
13
28
|
// }
|
|
14
29
|
//
|
|
15
30
|
// @IBAction private func payAction() {
|
|
16
|
-
//// let apiKey = "
|
|
17
|
-
//// let apiSecret = "
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// EnvironmentConfig.configure(apiKey: apiKey, apiSecret: apiSecret)
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
// let themeConfiguration
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
31
|
+
//// let apiKey = "f149cf5afc3a67c79e0aa87e7"
|
|
32
|
+
//// let apiSecret = "22b9dd1e588146077ca77da82"
|
|
33
|
+
//
|
|
34
|
+
// let apiKey = "14fbf8a186091763e59c289c1"
|
|
35
|
+
// let apiSecret = "f90863e7a853539f8ace8d6de"
|
|
36
|
+
//
|
|
37
|
+
// EasyPay.EnvironmentConfig.configure(apiKey: apiKey, apiSecret: apiSecret)
|
|
38
|
+
//
|
|
39
|
+
// // Theme Configuration
|
|
40
|
+
// let themeConfiguration = ThemeConfiguration(
|
|
41
|
+
// bodyBackgroundColor: "#EBF8FF",
|
|
42
|
+
// containerBackgroundColor: "#FFFFFF",
|
|
43
|
+
// primaryFontColor: "#1E3A8A",
|
|
44
|
+
// secondaryFontColor: "#696969",
|
|
45
|
+
// primaryButtonBackgroundColor: "#1D4ED8",
|
|
46
|
+
// primaryButtonHoverColor: "#2563EB",
|
|
47
|
+
// primaryButtonFontColor: "#FFFFFF",
|
|
48
|
+
// secondaryButtonBackgroundColor: "#FFFFFF",
|
|
49
|
+
// secondaryButtonHoverColor: "#BFDBFE",
|
|
50
|
+
// secondaryButtonFontColor: "#1E40AF",
|
|
51
|
+
// borderRadius: "8",
|
|
52
|
+
// fontSize: "14"
|
|
53
|
+
// )
|
|
39
54
|
//
|
|
40
|
-
// let additionalInfoRequest = [
|
|
55
|
+
// let additionalInfoRequest: [String: Any] = [
|
|
41
56
|
// "name": "Test User",
|
|
42
57
|
// "email": "test@gmail.com",
|
|
43
58
|
// "phone_number": "9465351125",
|
|
@@ -59,18 +74,32 @@
|
|
|
59
74
|
// return
|
|
60
75
|
// }
|
|
61
76
|
//
|
|
62
|
-
// let
|
|
77
|
+
// let authenticatedACH = true
|
|
78
|
+
//
|
|
79
|
+
// let grailPayParams = GrailPayRequest(
|
|
80
|
+
// accessToken: "251|uTijpDGfrS88UR2V1cZNMQ8S4hUJA0sVzsnsoUZF",
|
|
81
|
+
// vendorId: "251",
|
|
82
|
+
// role: "business",
|
|
83
|
+
// timeout: 10,
|
|
84
|
+
// isSandbox: true,
|
|
85
|
+
// brandingName: "Lyfecycle Payments",
|
|
86
|
+
// finderSubtitle: "Search for your bank",
|
|
87
|
+
// searchPlaceholder: "Enter bank name"
|
|
88
|
+
// )
|
|
89
|
+
//
|
|
90
|
+
// let request = EasyPay.Request(
|
|
63
91
|
// amount: 99,
|
|
64
92
|
// billingInfoData: jsonData,
|
|
65
93
|
// paymentMethods: [.Card, .Bank, .Crypto],
|
|
66
94
|
// themeConfiguration: themeConfiguration,
|
|
67
95
|
// tokenOnly: false,
|
|
68
96
|
// saveCard: false,
|
|
69
|
-
// saveAccount: false
|
|
70
|
-
//
|
|
97
|
+
// saveAccount: false,
|
|
98
|
+
// submitButtonText: "Submit",
|
|
99
|
+
// authenticatedACH: authenticatedACH,
|
|
100
|
+
// grailPayParams: authenticatedACH ? grailPayParams : nil
|
|
71
101
|
// )
|
|
72
102
|
//
|
|
73
|
-
// // If tokenOnly is true, wait for the clientToken and show it in lblResponseShow
|
|
74
103
|
// if request.tokenOnly == true {
|
|
75
104
|
// NotificationCenter.default.addObserver(forName: NSNotification.Name("ClientTokenReceived"), object: nil, queue: .main) { notification in
|
|
76
105
|
// if let clientToken = notification.object as? String {
|
|
@@ -82,21 +111,16 @@
|
|
|
82
111
|
// let controller = EasyPayViewController(request: request, delegate: self)
|
|
83
112
|
// self.present(controller, animated: true)
|
|
84
113
|
// }
|
|
85
|
-
//
|
|
86
114
|
// }
|
|
87
|
-
//
|
|
88
115
|
//}
|
|
89
116
|
//
|
|
90
117
|
//extension ViewController: EasyPayViewControllerDelegate {
|
|
91
118
|
//
|
|
92
|
-
// func easyPayController(_ controller: EasyPayViewController, didFinishWith result: Result) {
|
|
119
|
+
// func easyPayController(_ controller: EasyPayViewController, didFinishWith result: EasyPay.Result) {
|
|
93
120
|
// switch result.type {
|
|
94
121
|
// case .cancelled:
|
|
95
122
|
// print("Cancelled")
|
|
96
123
|
// case .success:
|
|
97
|
-
// // if let chargeData = result.chargeData {
|
|
98
|
-
// // handleSuccess(with: chargeData)
|
|
99
|
-
// // }
|
|
100
124
|
// if let chargeData = result.chargeData {
|
|
101
125
|
// if let clientToken = chargeData["clientToken"] as? String {
|
|
102
126
|
// // If tokenOnly was true, display the token
|
|
@@ -121,4 +145,16 @@
|
|
|
121
145
|
// lblResponseShow.isHidden = false
|
|
122
146
|
// lblResponseShow.text = "Received Charge Data: \(chargeData)"
|
|
123
147
|
// }
|
|
148
|
+
//
|
|
124
149
|
//}
|
|
150
|
+
//
|
|
151
|
+
//
|
|
152
|
+
//
|
|
153
|
+
//
|
|
154
|
+
//
|
|
155
|
+
//
|
|
156
|
+
//
|
|
157
|
+
//
|
|
158
|
+
//
|
|
159
|
+
//
|
|
160
|
+
//
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GrailPayHelper.swift
|
|
3
|
+
// EasyPay
|
|
4
|
+
//
|
|
5
|
+
// Created by Mony's Mac on 02/05/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
public class GrailPayHelper {
|
|
9
|
+
public static func presentGrailPay(
|
|
10
|
+
from viewController: UIViewController,
|
|
11
|
+
request: GrailPayRequest,
|
|
12
|
+
completion: @escaping (Result) -> Void
|
|
13
|
+
) {
|
|
14
|
+
let grailPayVC = GrailPayVC(request: request)
|
|
15
|
+
grailPayVC.onCompletion = completion
|
|
16
|
+
grailPayVC.modalPresentationStyle = .fullScreen
|
|
17
|
+
viewController.present(grailPayVC, animated: true)
|
|
18
|
+
}
|
|
19
|
+
}
|
package/ios/Models/Request.swift
CHANGED
|
@@ -7,66 +7,107 @@
|
|
|
7
7
|
|
|
8
8
|
import UIKit
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// if let paymentMethods = paymentMethods {
|
|
24
|
-
// self.selectedPaymentMethods = paymentMethods
|
|
25
|
-
// UserStoreSingleton.shared.paymentMethods = paymentMethods.map { $0.rawValue } // Save in User Defaults
|
|
26
|
-
// } else {
|
|
27
|
-
// let savedMethods = UserStoreSingleton.shared.paymentMethods ?? []
|
|
28
|
-
// self.selectedPaymentMethods = savedMethods.compactMap { PaymentMethod(rawValue: $0) }
|
|
29
|
-
// }
|
|
30
|
-
//
|
|
31
|
-
// super.init()
|
|
32
|
-
//
|
|
33
|
-
// // Call the payment intent API
|
|
34
|
-
// self.paymentIntentApi { success in
|
|
35
|
-
// if success {
|
|
36
|
-
// print("Payment Intent API call succeeded")
|
|
37
|
-
// // Save the amount in UserStoreSingleton
|
|
38
|
-
// UserStoreSingleton.shared.price = String(self.amount)
|
|
39
|
-
// print("Saved amount: \(UserStoreSingleton.shared.price ?? "No amount")")
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
//
|
|
43
|
-
// }
|
|
10
|
+
public struct ThemeConfiguration: Codable {
|
|
11
|
+
public let bodyBackgroundColor: String?
|
|
12
|
+
public let containerBackgroundColor: String?
|
|
13
|
+
public let primaryFontColor: String?
|
|
14
|
+
public let secondaryFontColor: String?
|
|
15
|
+
public let primaryButtonBackgroundColor: String?
|
|
16
|
+
public let primaryButtonHoverColor: String?
|
|
17
|
+
public let primaryButtonFontColor: String?
|
|
18
|
+
public let secondaryButtonBackgroundColor: String?
|
|
19
|
+
public let secondaryButtonHoverColor: String?
|
|
20
|
+
public let secondaryButtonFontColor: String?
|
|
21
|
+
public let borderRadius: String?
|
|
22
|
+
public let fontSize: String?
|
|
44
23
|
|
|
24
|
+
public init(
|
|
25
|
+
bodyBackgroundColor: String? = nil,
|
|
26
|
+
containerBackgroundColor: String? = nil,
|
|
27
|
+
primaryFontColor: String? = nil,
|
|
28
|
+
secondaryFontColor: String? = nil,
|
|
29
|
+
primaryButtonBackgroundColor: String? = nil,
|
|
30
|
+
primaryButtonHoverColor: String? = nil,
|
|
31
|
+
primaryButtonFontColor: String? = nil,
|
|
32
|
+
secondaryButtonBackgroundColor: String? = nil,
|
|
33
|
+
secondaryButtonHoverColor: String? = nil,
|
|
34
|
+
secondaryButtonFontColor: String? = nil,
|
|
35
|
+
borderRadius: String? = nil,
|
|
36
|
+
fontSize: String? = nil
|
|
37
|
+
) {
|
|
38
|
+
self.bodyBackgroundColor = bodyBackgroundColor
|
|
39
|
+
self.containerBackgroundColor = containerBackgroundColor
|
|
40
|
+
self.primaryFontColor = primaryFontColor
|
|
41
|
+
self.secondaryFontColor = secondaryFontColor
|
|
42
|
+
self.primaryButtonBackgroundColor = primaryButtonBackgroundColor
|
|
43
|
+
self.primaryButtonHoverColor = primaryButtonHoverColor
|
|
44
|
+
self.primaryButtonFontColor = primaryButtonFontColor
|
|
45
|
+
self.secondaryButtonBackgroundColor = secondaryButtonBackgroundColor
|
|
46
|
+
self.secondaryButtonHoverColor = secondaryButtonHoverColor
|
|
47
|
+
self.secondaryButtonFontColor = secondaryButtonFontColor
|
|
48
|
+
self.borderRadius = borderRadius
|
|
49
|
+
self.fontSize = fontSize
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public struct GrailPayRequest: Codable {
|
|
54
|
+
public let accessToken: String
|
|
55
|
+
public let vendorId: String
|
|
56
|
+
public let role: String
|
|
57
|
+
public let timeout: Int
|
|
58
|
+
public let isSandbox: Bool
|
|
59
|
+
public let brandingName: String
|
|
60
|
+
public let finderSubtitle: String
|
|
61
|
+
public let searchPlaceholder: String
|
|
62
|
+
|
|
63
|
+
public init(
|
|
64
|
+
accessToken: String,
|
|
65
|
+
vendorId: String,
|
|
66
|
+
role: String,
|
|
67
|
+
timeout: Int,
|
|
68
|
+
isSandbox: Bool,
|
|
69
|
+
brandingName: String,
|
|
70
|
+
finderSubtitle: String,
|
|
71
|
+
searchPlaceholder: String
|
|
72
|
+
) {
|
|
73
|
+
self.accessToken = accessToken
|
|
74
|
+
self.vendorId = vendorId
|
|
75
|
+
self.role = role
|
|
76
|
+
self.timeout = timeout
|
|
77
|
+
self.isSandbox = isSandbox
|
|
78
|
+
self.brandingName = brandingName // Fixed: Use the actual parameter
|
|
79
|
+
self.finderSubtitle = finderSubtitle // Fixed: Use the actual parameter
|
|
80
|
+
self.searchPlaceholder = searchPlaceholder // Fixed: Use the actual parameter
|
|
81
|
+
}
|
|
82
|
+
}
|
|
45
83
|
|
|
46
84
|
@objc
|
|
47
85
|
public final class Request: NSObject {
|
|
48
86
|
public let amount: Double
|
|
49
87
|
public let billingInfoData: Data?
|
|
50
|
-
let themeConfiguration:
|
|
88
|
+
let themeConfiguration: ThemeConfiguration?
|
|
51
89
|
let selectedPaymentMethods: [PaymentMethod]
|
|
52
|
-
|
|
90
|
+
|
|
53
91
|
// New parameters
|
|
54
92
|
public let tokenOnly: Bool?
|
|
55
93
|
public let saveCard: Bool?
|
|
56
94
|
public let saveAccount: Bool?
|
|
57
95
|
public let submitButtonText: String?
|
|
58
|
-
|
|
96
|
+
public let authenticatedACH: Bool?
|
|
97
|
+
public let grailPayParams: GrailPayRequest?
|
|
98
|
+
|
|
59
99
|
public init(
|
|
60
100
|
amount: Double,
|
|
61
101
|
billingInfoData: Data,
|
|
62
102
|
paymentMethods: [PaymentMethod]? = nil,
|
|
63
|
-
themeConfiguration:
|
|
103
|
+
themeConfiguration: ThemeConfiguration? = nil,
|
|
64
104
|
tokenOnly: Bool = false,
|
|
65
105
|
saveCard: Bool = false,
|
|
66
106
|
saveAccount: Bool = false,
|
|
67
|
-
submitButtonText: String? = nil
|
|
107
|
+
submitButtonText: String? = nil,
|
|
108
|
+
authenticatedACH: Bool = false,
|
|
109
|
+
grailPayParams: GrailPayRequest? = nil
|
|
68
110
|
) {
|
|
69
|
-
|
|
70
111
|
self.amount = amount
|
|
71
112
|
self.billingInfoData = billingInfoData
|
|
72
113
|
self.themeConfiguration = themeConfiguration
|
|
@@ -74,7 +115,9 @@ public final class Request: NSObject {
|
|
|
74
115
|
self.saveCard = saveCard
|
|
75
116
|
self.saveAccount = saveAccount
|
|
76
117
|
self.submitButtonText = submitButtonText
|
|
77
|
-
|
|
118
|
+
self.authenticatedACH = authenticatedACH
|
|
119
|
+
self.grailPayParams = authenticatedACH ? grailPayParams : nil
|
|
120
|
+
|
|
78
121
|
if let paymentMethods = paymentMethods {
|
|
79
122
|
self.selectedPaymentMethods = paymentMethods
|
|
80
123
|
UserStoreSingleton.shared.paymentMethods = paymentMethods.map { $0.rawValue }
|
|
@@ -82,25 +125,24 @@ public final class Request: NSObject {
|
|
|
82
125
|
let savedMethods = UserStoreSingleton.shared.paymentMethods ?? []
|
|
83
126
|
self.selectedPaymentMethods = savedMethods.compactMap { PaymentMethod(rawValue: $0) }
|
|
84
127
|
}
|
|
85
|
-
|
|
86
128
|
// ✅ Save theme configuration in UserStoreSingleton only if themeConfiguration is not nil or empty
|
|
87
|
-
if let themeConfig = themeConfiguration
|
|
88
|
-
UserStoreSingleton.shared.body_bg_col = themeConfig
|
|
89
|
-
UserStoreSingleton.shared.container_bg_col = themeConfig
|
|
90
|
-
UserStoreSingleton.shared.primary_font_col = themeConfig
|
|
91
|
-
UserStoreSingleton.shared.secondary_font_col = themeConfig
|
|
92
|
-
UserStoreSingleton.shared.primary_btn_bg_col = themeConfig
|
|
93
|
-
UserStoreSingleton.shared.primary_btn_hover_col = themeConfig
|
|
94
|
-
UserStoreSingleton.shared.primary_btn_font_col = themeConfig
|
|
95
|
-
UserStoreSingleton.shared.secondary_btn_bg_col = themeConfig
|
|
96
|
-
UserStoreSingleton.shared.secondary_btn_hover_col = themeConfig
|
|
97
|
-
UserStoreSingleton.shared.secondary_btn_font_col = themeConfig
|
|
98
|
-
UserStoreSingleton.shared.border_radious = themeConfig
|
|
99
|
-
UserStoreSingleton.shared.fontSize = themeConfig
|
|
129
|
+
if let themeConfig = themeConfiguration {
|
|
130
|
+
UserStoreSingleton.shared.body_bg_col = themeConfig.bodyBackgroundColor
|
|
131
|
+
UserStoreSingleton.shared.container_bg_col = themeConfig.containerBackgroundColor
|
|
132
|
+
UserStoreSingleton.shared.primary_font_col = themeConfig.primaryFontColor
|
|
133
|
+
UserStoreSingleton.shared.secondary_font_col = themeConfig.secondaryFontColor
|
|
134
|
+
UserStoreSingleton.shared.primary_btn_bg_col = themeConfig.primaryButtonBackgroundColor
|
|
135
|
+
UserStoreSingleton.shared.primary_btn_hover_col = themeConfig.primaryButtonHoverColor
|
|
136
|
+
UserStoreSingleton.shared.primary_btn_font_col = themeConfig.primaryButtonFontColor
|
|
137
|
+
UserStoreSingleton.shared.secondary_btn_bg_col = themeConfig.secondaryButtonBackgroundColor
|
|
138
|
+
UserStoreSingleton.shared.secondary_btn_hover_col = themeConfig.secondaryButtonHoverColor
|
|
139
|
+
UserStoreSingleton.shared.secondary_btn_font_col = themeConfig.secondaryButtonFontColor
|
|
140
|
+
UserStoreSingleton.shared.border_radious = themeConfig.borderRadius
|
|
141
|
+
UserStoreSingleton.shared.fontSize = themeConfig.fontSize
|
|
100
142
|
}
|
|
101
|
-
|
|
143
|
+
|
|
102
144
|
super.init()
|
|
103
|
-
|
|
145
|
+
|
|
104
146
|
// If tokenOnly is true, fetch only the clientToken and do not open the SDK
|
|
105
147
|
if tokenOnly {
|
|
106
148
|
self.paymentIntentApi { success in
|
|
@@ -110,7 +152,8 @@ public final class Request: NSObject {
|
|
|
110
152
|
}
|
|
111
153
|
}
|
|
112
154
|
}
|
|
113
|
-
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
114
157
|
// Proceed with normal payment flow
|
|
115
158
|
self.paymentIntentApi { success in
|
|
116
159
|
if success {
|
|
@@ -120,29 +163,29 @@ public final class Request: NSObject {
|
|
|
120
163
|
}
|
|
121
164
|
}
|
|
122
165
|
}
|
|
123
|
-
|
|
166
|
+
|
|
124
167
|
}
|
|
125
|
-
|
|
168
|
+
|
|
126
169
|
//MARK: - Payment Intent Api
|
|
127
170
|
func paymentIntentApi(completion: @escaping (Bool) -> Void) {
|
|
128
171
|
// Start loader when API call starts
|
|
129
|
-
|
|
172
|
+
|
|
130
173
|
guard let serviceURL = URL(string: EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.paymentIntent.path()) else {
|
|
131
174
|
print("Invalid URL")
|
|
132
175
|
completion(false)
|
|
133
176
|
return
|
|
134
177
|
}
|
|
135
|
-
|
|
178
|
+
|
|
136
179
|
var request = URLRequest(url: serviceURL)
|
|
137
180
|
request.httpMethod = "POST"
|
|
138
181
|
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
139
182
|
request.addValue(EnvironmentConfig.apiKey ?? "", forHTTPHeaderField: "X-Api-Key")
|
|
140
183
|
request.addValue(EnvironmentConfig.apiSecret ?? "", forHTTPHeaderField: "X-Api-Secret")
|
|
141
|
-
|
|
184
|
+
|
|
142
185
|
let params: [String: Any] = [
|
|
143
186
|
"amount": amount,
|
|
144
187
|
]
|
|
145
|
-
|
|
188
|
+
|
|
146
189
|
do {
|
|
147
190
|
request.httpBody = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
148
191
|
} catch {
|
|
@@ -150,34 +193,34 @@ public final class Request: NSObject {
|
|
|
150
193
|
completion(false)
|
|
151
194
|
return
|
|
152
195
|
}
|
|
153
|
-
|
|
196
|
+
|
|
154
197
|
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
|
155
198
|
DispatchQueue.main.async {
|
|
156
199
|
// Stop loader when response is received
|
|
157
200
|
}
|
|
158
|
-
|
|
201
|
+
|
|
159
202
|
guard let httpResponse = response as? HTTPURLResponse, error == nil else {
|
|
160
203
|
print("Error: \(error?.localizedDescription ?? "Unknown error")")
|
|
161
204
|
completion(false)
|
|
162
205
|
return
|
|
163
206
|
}
|
|
164
|
-
|
|
207
|
+
|
|
165
208
|
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
166
209
|
if let data = data {
|
|
167
210
|
do {
|
|
168
211
|
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
169
212
|
print("Response Data: \(responseObject)")
|
|
170
|
-
|
|
213
|
+
|
|
171
214
|
// Save tokens
|
|
172
215
|
if let clientToken = responseObject["client_token"] as? String {
|
|
173
216
|
UserStoreSingleton.shared.clientToken = clientToken
|
|
174
217
|
print("Client Token successfully saved: \(UserStoreSingleton.shared.clientToken ?? "None")")
|
|
175
218
|
}
|
|
176
|
-
|
|
219
|
+
|
|
177
220
|
if let paymentIntent = responseObject["payment_intent"] as? String {
|
|
178
221
|
UserStoreSingleton.shared.paymentIntent = paymentIntent
|
|
179
222
|
}
|
|
180
|
-
|
|
223
|
+
|
|
181
224
|
self.hostedCheckoutsApi { success in
|
|
182
225
|
completion(success)
|
|
183
226
|
}
|
|
@@ -200,29 +243,29 @@ public final class Request: NSObject {
|
|
|
200
243
|
}
|
|
201
244
|
task.resume()
|
|
202
245
|
}
|
|
203
|
-
|
|
246
|
+
|
|
204
247
|
// MARK: - Hosted Checkout API
|
|
205
248
|
func hostedCheckoutsApi(completion: @escaping (Bool) -> Void) {
|
|
206
|
-
|
|
249
|
+
|
|
207
250
|
// Build the URL using EnvironmentConfig
|
|
208
251
|
guard let baseURL = URL(string: EnvironmentConfig.baseURL) else {
|
|
209
252
|
print("Invalid base URL")
|
|
210
253
|
completion(false)
|
|
211
254
|
return
|
|
212
255
|
}
|
|
213
|
-
|
|
256
|
+
|
|
214
257
|
let endpointPath = EnvironmentConfig.Endpoints.hostedCheckouts.path()
|
|
215
258
|
let serviceURL = baseURL.appendingPathComponent(endpointPath)
|
|
216
|
-
|
|
259
|
+
|
|
217
260
|
var request = URLRequest(url: serviceURL)
|
|
218
261
|
request.httpMethod = "POST"
|
|
219
262
|
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
220
263
|
request.addValue(UserStoreSingleton.shared.clientToken ?? "", forHTTPHeaderField: "clientToken")
|
|
221
|
-
|
|
264
|
+
|
|
222
265
|
let params: [String: Any] = [
|
|
223
266
|
"amount": amount,
|
|
224
267
|
]
|
|
225
|
-
|
|
268
|
+
|
|
226
269
|
do {
|
|
227
270
|
request.httpBody = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
228
271
|
} catch {
|
|
@@ -230,33 +273,33 @@ public final class Request: NSObject {
|
|
|
230
273
|
completion(false)
|
|
231
274
|
return
|
|
232
275
|
}
|
|
233
|
-
|
|
276
|
+
|
|
234
277
|
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
|
235
|
-
|
|
278
|
+
|
|
236
279
|
guard let httpResponse = response as? HTTPURLResponse, error == nil else {
|
|
237
280
|
print("Error: \(error?.localizedDescription ?? "Unknown error")")
|
|
238
281
|
completion(false)
|
|
239
282
|
return
|
|
240
283
|
}
|
|
241
|
-
|
|
284
|
+
|
|
242
285
|
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
243
286
|
if let data = data {
|
|
244
287
|
do {
|
|
245
288
|
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
|
|
246
289
|
let dataObject = responseObject["data"] as? [String: Any] {
|
|
247
290
|
print(dataObject)
|
|
248
|
-
|
|
291
|
+
|
|
249
292
|
// Save merchant details
|
|
250
293
|
if let merchantEmail = dataObject["merchant_email"] as? String {
|
|
251
294
|
UserStoreSingleton.shared.merchantEmail = merchantEmail
|
|
252
295
|
print("Saved merchantEmail: \(merchantEmail)")
|
|
253
296
|
}
|
|
254
|
-
|
|
297
|
+
|
|
255
298
|
if let merchantName = dataObject["merchant_name"] as? String {
|
|
256
299
|
UserStoreSingleton.shared.merchantName = merchantName
|
|
257
300
|
print("Saved merchantName: \(merchantName)")
|
|
258
301
|
}
|
|
259
|
-
|
|
302
|
+
|
|
260
303
|
// Save payment methods (crypto payment account)
|
|
261
304
|
if let paymentMethods = dataObject["payment_methods"] as? [String: Any],
|
|
262
305
|
let cryptoSection = paymentMethods["crypto"] as? [String: Any],
|
|
@@ -264,80 +307,32 @@ public final class Request: NSObject {
|
|
|
264
307
|
UserStoreSingleton.shared.paymentAccount = paymentAccount
|
|
265
308
|
print("Saved paymentAccount (Crypto): \(paymentAccount)")
|
|
266
309
|
}
|
|
267
|
-
|
|
310
|
+
|
|
268
311
|
// Save payment methods
|
|
269
312
|
if let paymentMethods = dataObject["payment_methods"] as? [String: Any] {
|
|
270
313
|
var paymentMethodNames: [String] = []
|
|
271
|
-
|
|
314
|
+
|
|
272
315
|
if paymentMethods["card"] is [String: Any] {
|
|
273
316
|
paymentMethodNames.append("Card")
|
|
274
317
|
}
|
|
275
|
-
|
|
318
|
+
|
|
276
319
|
if paymentMethods["ach"] is [String: Any] {
|
|
277
320
|
paymentMethodNames.append("Bank")
|
|
278
321
|
}
|
|
279
|
-
|
|
322
|
+
|
|
280
323
|
if paymentMethods["crypto"] is [String: Any] {
|
|
281
324
|
paymentMethodNames.append("Crypto")
|
|
282
325
|
}
|
|
283
|
-
|
|
326
|
+
|
|
284
327
|
if paymentMethods["wallet"] is [String: Any] {
|
|
285
328
|
paymentMethodNames.append("Wallet")
|
|
286
329
|
}
|
|
287
|
-
|
|
330
|
+
|
|
288
331
|
UserStoreSingleton.shared.paymentMethods = paymentMethodNames
|
|
289
332
|
print("Saved payment methods: \(paymentMethodNames)")
|
|
290
333
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// if let appearanceSettings = dataObject["apperance_settings"] as? [String: Any] {
|
|
294
|
-
// if let bodyBgCol = appearanceSettings["body_bg_col"] as? String {
|
|
295
|
-
// UserStoreSingleton.shared.body_bg_col = bodyBgCol
|
|
296
|
-
// print("Saved bodyBgCol: \(bodyBgCol)")
|
|
297
|
-
// }
|
|
298
|
-
// if let borderRadious = appearanceSettings["border_radious"] as? String {
|
|
299
|
-
// UserStoreSingleton.shared.border_radious = borderRadious
|
|
300
|
-
// print("Saved borderRadious: \(borderRadious)")
|
|
301
|
-
// }
|
|
302
|
-
// if let containerBgCol = appearanceSettings["container_bg_col"] as? String {
|
|
303
|
-
// UserStoreSingleton.shared.container_bg_col = containerBgCol
|
|
304
|
-
// print("Saved containerBgCol: \(containerBgCol)")
|
|
305
|
-
// }
|
|
306
|
-
// if let primaryBtnBgCol = appearanceSettings["primary_btn_bg_col"] as? String {
|
|
307
|
-
// UserStoreSingleton.shared.primary_btn_bg_col = primaryBtnBgCol
|
|
308
|
-
// print("Saved primaryBtnBgCol: \(primaryBtnBgCol)")
|
|
309
|
-
// }
|
|
310
|
-
// if let primaryBtnFontCol = appearanceSettings["primary_btn_font_col"] as? String {
|
|
311
|
-
// UserStoreSingleton.shared.primary_btn_font_col = primaryBtnFontCol
|
|
312
|
-
// print("Saved primaryBtnFontCol: \(primaryBtnFontCol)")
|
|
313
|
-
// }
|
|
314
|
-
// if let primaryBtnHoverCol = appearanceSettings["primary_btn_hover_col"] as? String {
|
|
315
|
-
// UserStoreSingleton.shared.primary_btn_hover_col = primaryBtnHoverCol
|
|
316
|
-
// print("Saved primaryBtnHoverCol: \(primaryBtnHoverCol)")
|
|
317
|
-
// }
|
|
318
|
-
// if let primaryFontCol = appearanceSettings["primary_font_col"] as? String {
|
|
319
|
-
// UserStoreSingleton.shared.primary_font_col = primaryFontCol
|
|
320
|
-
// print("Saved primaryFontCol: \(primaryFontCol)")
|
|
321
|
-
// }
|
|
322
|
-
// if let secondaryBtnBgCol = appearanceSettings["secondary_btn_bg_col"] as? String {
|
|
323
|
-
// UserStoreSingleton.shared.secondary_btn_bg_col = secondaryBtnBgCol
|
|
324
|
-
// print("Saved secondaryBtnBgCol: \(secondaryBtnBgCol)")
|
|
325
|
-
// }
|
|
326
|
-
// if let secondaryBtnFontCol = appearanceSettings["secondary_btn_font_col"] as? String {
|
|
327
|
-
// UserStoreSingleton.shared.secondary_font_col = secondaryBtnFontCol
|
|
328
|
-
// print("Saved secondaryBtnFontCol: \(secondaryBtnFontCol)")
|
|
329
|
-
// }
|
|
330
|
-
// if let secondaryBtnHoverCol = appearanceSettings["secondary_btn_hover_col"] as? String {
|
|
331
|
-
// UserStoreSingleton.shared.secondary_btn_hover_col = secondaryBtnHoverCol
|
|
332
|
-
// print("Saved secondaryBtnHoverCol: \(secondaryBtnHoverCol)")
|
|
333
|
-
// }
|
|
334
|
-
// if let secondaryFontCol = appearanceSettings["secondary_font_col"] as? String {
|
|
335
|
-
// UserStoreSingleton.shared.secondary_font_col = secondaryFontCol
|
|
336
|
-
// print("Saved secondaryFontCol: \(secondaryFontCol)")
|
|
337
|
-
// }
|
|
338
|
-
// }
|
|
339
|
-
|
|
340
|
-
if (self.themeConfiguration == nil || self.themeConfiguration!.isEmpty), let appearanceSettings = dataObject["apperance_settings"] as? [String: Any] {
|
|
334
|
+
|
|
335
|
+
if self.themeConfiguration == nil, let appearanceSettings = dataObject["apperance_settings"] as? [String: Any] {
|
|
341
336
|
UserStoreSingleton.shared.body_bg_col = appearanceSettings["body_bg_col"] as? String
|
|
342
337
|
UserStoreSingleton.shared.border_radious = appearanceSettings["border_radious"] as? String
|
|
343
338
|
UserStoreSingleton.shared.container_bg_col = appearanceSettings["container_bg_col"] as? String
|
|
@@ -349,13 +344,13 @@ public final class Request: NSObject {
|
|
|
349
344
|
UserStoreSingleton.shared.secondary_btn_font_col = appearanceSettings["secondary_font_col"] as? String
|
|
350
345
|
UserStoreSingleton.shared.secondary_btn_hover_col = appearanceSettings["secondary_btn_hover_col"] as? String
|
|
351
346
|
UserStoreSingleton.shared.secondary_font_col = appearanceSettings["secondary_font_col"] as? String
|
|
352
|
-
|
|
347
|
+
|
|
353
348
|
// Clearing the font size value
|
|
354
349
|
UserStoreSingleton.shared.fontSize = nil
|
|
355
350
|
}
|
|
356
|
-
|
|
351
|
+
|
|
357
352
|
completion(true)
|
|
358
|
-
|
|
353
|
+
|
|
359
354
|
} else {
|
|
360
355
|
print("Invalid JSON format or 'data' key is missing")
|
|
361
356
|
completion(false)
|
|
@@ -375,5 +370,6 @@ public final class Request: NSObject {
|
|
|
375
370
|
}
|
|
376
371
|
task.resume()
|
|
377
372
|
}
|
|
378
|
-
|
|
373
|
+
|
|
379
374
|
}
|
|
375
|
+
|