@jimrising/easymerchantsdk-react-native 2.2.1 → 2.2.3
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/README.md +1 -1
- package/ios/Pods/UserDefaults/UserStoreSingleton.swift +304 -0
- package/ios/Pods/ViewControllers/AdditionalInfoVC.swift +2636 -0
- package/ios/Pods/ViewControllers/BaseVC.swift +141 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/BillingInfoVC.swift +3347 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/CityListTVC.swift +46 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/CountryListTVC.swift +47 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/StateListTVC.swift +46 -0
- package/ios/Pods/ViewControllers/CountryListVC.swift +435 -0
- package/ios/Pods/ViewControllers/CustomOverlay.swift +199 -0
- package/ios/Pods/ViewControllers/EmailVerificationVC.swift +307 -0
- package/ios/Pods/ViewControllers/GrailPayVC.swift +244 -0
- package/ios/Pods/ViewControllers/OTPVerificationVC.swift +2066 -0
- package/ios/Pods/ViewControllers/PaymentDoneVC.swift +272 -0
- package/ios/Pods/ViewControllers/PaymentErrorVC.swift +85 -0
- package/ios/Pods/ViewControllers/PaymentInformation/AccountTypeTVC.swift +41 -0
- package/ios/Pods/ViewControllers/PaymentInformation/PaymentInfoVC.swift +11025 -0
- package/ios/Pods/ViewControllers/PaymentInformation/PaymentInformationCVC.swift +35 -0
- package/ios/Pods/ViewControllers/PaymentInformation/RecurringTVC.swift +40 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedAccountsTVC/SavedAccountTVC.swift +81 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedAccountsTVC/SavedAccountTVC.xib +163 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedCardsTVC/SavedCardsTVC.swift +81 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedCardsTVC/SavedCardsTVC.xib +188 -0
- package/ios/Pods/ViewControllers/PaymentStatusWebViewVC.swift +167 -0
- package/ios/Pods/ViewControllers/TermAndConditionsVC.swift +63 -0
- package/ios/Pods/ViewControllers/ThreeDSecurePaymentDoneVC.swift +629 -0
- package/ios/easymerchantsdk.podspec +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
////
|
|
2
|
+
//// GrailPayVC.swift
|
|
3
|
+
//// EasyPay
|
|
4
|
+
////
|
|
5
|
+
//// Created by Mony's Mac on 02/05/25.
|
|
6
|
+
////
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
import WebKit
|
|
10
|
+
|
|
11
|
+
public class GrailPayVC: UIViewController {
|
|
12
|
+
|
|
13
|
+
private var webView: WKWebView!
|
|
14
|
+
private var loadingIndicator: UIActivityIndicatorView!
|
|
15
|
+
private var request: GrailPayRequest
|
|
16
|
+
|
|
17
|
+
public var onCompletion: ((SDKResult) -> Void)?
|
|
18
|
+
private var didHandleBankConnection = false
|
|
19
|
+
|
|
20
|
+
public init(request: GrailPayRequest) {
|
|
21
|
+
self.request = request
|
|
22
|
+
super.init(nibName: nil, bundle: nil)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
required init?(coder: NSCoder) {
|
|
26
|
+
fatalError("init(coder:) has not been implemented")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override public func viewDidLoad() {
|
|
30
|
+
super.viewDidLoad()
|
|
31
|
+
setupUI()
|
|
32
|
+
loadGrailPaySDK()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private func setupUI() {
|
|
36
|
+
view.backgroundColor = .white
|
|
37
|
+
|
|
38
|
+
let config = WKWebViewConfiguration()
|
|
39
|
+
|
|
40
|
+
// Modern iOS 14+ JavaScript enablement
|
|
41
|
+
if #available(iOS 14.0, *) {
|
|
42
|
+
let webpagePreferences = WKWebpagePreferences()
|
|
43
|
+
webpagePreferences.allowsContentJavaScript = true
|
|
44
|
+
config.defaultWebpagePreferences = webpagePreferences
|
|
45
|
+
} else {
|
|
46
|
+
// Fallback for iOS < 14
|
|
47
|
+
let preferences = WKPreferences()
|
|
48
|
+
preferences.javaScriptEnabled = true
|
|
49
|
+
config.preferences = preferences
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
config.websiteDataStore = WKWebsiteDataStore.default()
|
|
53
|
+
config.userContentController.add(self, name: "grailpayHandler")
|
|
54
|
+
config.allowsInlineMediaPlayback = true
|
|
55
|
+
config.mediaTypesRequiringUserActionForPlayback = []
|
|
56
|
+
|
|
57
|
+
webView = WKWebView(frame: view.bounds, configuration: config)
|
|
58
|
+
webView.navigationDelegate = self
|
|
59
|
+
webView.uiDelegate = self
|
|
60
|
+
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
61
|
+
view.addSubview(webView)
|
|
62
|
+
|
|
63
|
+
loadingIndicator = UIActivityIndicatorView(style: .large)
|
|
64
|
+
loadingIndicator.center = view.center
|
|
65
|
+
loadingIndicator.hidesWhenStopped = true
|
|
66
|
+
view.addSubview(loadingIndicator)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private func loadGrailPaySDK() {
|
|
70
|
+
loadingIndicator.startAnimating()
|
|
71
|
+
|
|
72
|
+
let sdkURL = request.isSandbox
|
|
73
|
+
? "https://bank-link-widget-sandbox.grailpay.com/sdk.js"
|
|
74
|
+
: "https://bank-link-widget.grailpay.com/sdk.js"
|
|
75
|
+
|
|
76
|
+
let html = """
|
|
77
|
+
<!DOCTYPE html>
|
|
78
|
+
<html>
|
|
79
|
+
<head>
|
|
80
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
81
|
+
<script>
|
|
82
|
+
window.sdkInitialized = false;
|
|
83
|
+
|
|
84
|
+
function initializeSDK() {
|
|
85
|
+
if (window.sdkInitialized) return;
|
|
86
|
+
|
|
87
|
+
if (typeof window.grailpay === 'undefined') {
|
|
88
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'SDK not loaded' });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
window.grailpay.init({
|
|
93
|
+
token: '\(UserStoreSingleton.shared.bankWidgetKey ?? "")',
|
|
94
|
+
vendorId: '\(UserStoreSingleton.shared.vendorID ?? "")',
|
|
95
|
+
role: '\(request.role)',
|
|
96
|
+
timeout: \(request.timeout),
|
|
97
|
+
theme: {
|
|
98
|
+
branding_name: '\(request.brandingName)',
|
|
99
|
+
screens: {
|
|
100
|
+
finder: {
|
|
101
|
+
subtitle: '\(request.finderSubtitle)',
|
|
102
|
+
searchPlaceholder: '\(request.searchPlaceholder)'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
onError: function(error) {
|
|
107
|
+
console.log("JS onError:", error);
|
|
108
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
|
|
109
|
+
},
|
|
110
|
+
onBankConnected: function(data) {
|
|
111
|
+
console.log("✅ Bank connected:", data);
|
|
112
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'bankConnected', data: data });
|
|
113
|
+
},
|
|
114
|
+
onLinkedDefaultAccount: function(data) {
|
|
115
|
+
console.log("Default Account", data);
|
|
116
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'defaultAccountSelected', data: data });
|
|
117
|
+
},
|
|
118
|
+
onLinkExit: function(data) {
|
|
119
|
+
console.log("⚠️ User exited:", data);
|
|
120
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'linkExit', data: data });
|
|
121
|
+
}
|
|
122
|
+
}).then(function() {
|
|
123
|
+
window.sdkInitialized = true;
|
|
124
|
+
window.grailpay.open();
|
|
125
|
+
}).catch(function(error) {
|
|
126
|
+
console.log("❌ SDK init failed:", error);
|
|
127
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function loadSDK() {
|
|
132
|
+
const script = document.createElement('script');
|
|
133
|
+
script.src = '\(sdkURL)';
|
|
134
|
+
script.onload = function() {
|
|
135
|
+
setTimeout(initializeSDK, 1000);
|
|
136
|
+
};
|
|
137
|
+
script.onerror = function(error) {
|
|
138
|
+
console.log("❌ Failed to load SDK script");
|
|
139
|
+
window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'Failed to load SDK script' });
|
|
140
|
+
};
|
|
141
|
+
document.head.appendChild(script);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
document.addEventListener('DOMContentLoaded', loadSDK);
|
|
145
|
+
</script>
|
|
146
|
+
</head>
|
|
147
|
+
<body style="margin:0;padding:0;"></body>
|
|
148
|
+
</html>
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
let baseURL = URL(string: request.isSandbox
|
|
152
|
+
? "https://bank-link-widget-sandbox.grailpay.com"
|
|
153
|
+
: "https://bank-link-widget.grailpay.com")
|
|
154
|
+
|
|
155
|
+
webView.loadHTMLString(html, baseURL: baseURL)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private func handleError(_ error: Error) {
|
|
159
|
+
DispatchQueue.main.async {
|
|
160
|
+
self.loadingIndicator.stopAnimating()
|
|
161
|
+
self.onCompletion?(SDKResult(error: error as NSError))
|
|
162
|
+
self.dismiss(animated: true)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// MARK: - WKNavigationDelegate
|
|
168
|
+
extension GrailPayVC: WKNavigationDelegate {
|
|
169
|
+
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
170
|
+
loadingIndicator.stopAnimating()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
|
174
|
+
handleError(error)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// MARK: - WKScriptMessageHandler
|
|
179
|
+
extension GrailPayVC: WKScriptMessageHandler {
|
|
180
|
+
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
181
|
+
print("JS Message received: \(message.body)")
|
|
182
|
+
|
|
183
|
+
guard let body = message.body as? [String: Any],
|
|
184
|
+
let type = body["type"] as? String else {
|
|
185
|
+
print("Invalid message structure")
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
switch type {
|
|
190
|
+
case "bankConnected":
|
|
191
|
+
if let data = body["data"] {
|
|
192
|
+
print("All linked account data from GrailPay:", data)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
case "defaultAccountSelected":
|
|
196
|
+
guard let dataG = body["data"] as? [String: Any] else {
|
|
197
|
+
print("No account data selected")
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
print("Received defaultAccountSelected: \(dataG)")
|
|
202
|
+
|
|
203
|
+
if !didHandleBankConnection {
|
|
204
|
+
didHandleBankConnection = true
|
|
205
|
+
let dataArray: [[String: Any]] = [dataG]
|
|
206
|
+
DispatchQueue.main.async {
|
|
207
|
+
self.onCompletion?(SDKResult(type: .success, chargeData: ["data": dataArray]))
|
|
208
|
+
self.dismiss(animated: true)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
case "linkExit":
|
|
213
|
+
if didHandleBankConnection {
|
|
214
|
+
print("linkExit ignored (already handled)")
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
print("User exited linking flow")
|
|
218
|
+
DispatchQueue.main.async {
|
|
219
|
+
self.onCompletion?(SDKResult(type: .cancelled))
|
|
220
|
+
self.dismiss(animated: true)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
case "error":
|
|
224
|
+
let errorMessage = body["data"] as? String ?? "Unknown error"
|
|
225
|
+
print("GrailPay Error:", errorMessage)
|
|
226
|
+
let error = NSError(domain: "GrailPayError", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage])
|
|
227
|
+
handleError(error)
|
|
228
|
+
|
|
229
|
+
default:
|
|
230
|
+
print("Unknown JS message type:", type)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// MARK: - WKUIDelegate
|
|
236
|
+
extension GrailPayVC: WKUIDelegate {
|
|
237
|
+
public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
|
|
238
|
+
for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
|
|
239
|
+
if navigationAction.targetFrame == nil {
|
|
240
|
+
webView.load(navigationAction.request)
|
|
241
|
+
}
|
|
242
|
+
return nil
|
|
243
|
+
}
|
|
244
|
+
}
|