@jimrising/easymerchantsdk-react-native 2.5.2 → 2.5.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.
@@ -1,258 +1,10 @@
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
- //// public var onCompletion: ((EasyPay.SDKResult) -> Void)?
17
- //// private var didHandleBankConnection = false
18
- //// private var allLinkedAccounts: [[String: Any]] = []
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
- //// if #available(iOS 14.0, *) {
40
- //// let webpagePreferences = WKWebpagePreferences()
41
- //// webpagePreferences.allowsContentJavaScript = true
42
- //// config.defaultWebpagePreferences = webpagePreferences
43
- //// } else {
44
- //// let preferences = WKPreferences()
45
- //// preferences.javaScriptEnabled = true
46
- //// config.preferences = preferences
47
- //// }
48
- ////
49
- //// config.websiteDataStore = WKWebsiteDataStore.default()
50
- //// config.userContentController.add(self, name: "grailpayHandler")
51
- //// config.allowsInlineMediaPlayback = true
52
- //// config.mediaTypesRequiringUserActionForPlayback = []
53
- ////
54
- //// webView = WKWebView(frame: view.bounds, configuration: config)
55
- //// webView.navigationDelegate = self
56
- //// webView.uiDelegate = self
57
- //// webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
58
- //// view.addSubview(webView)
59
- ////
60
- //// loadingIndicator = UIActivityIndicatorView(style: .large)
61
- //// loadingIndicator.center = view.center
62
- //// loadingIndicator.hidesWhenStopped = true
63
- //// view.addSubview(loadingIndicator)
64
- //// }
65
- ////
66
- //// private func loadGrailPaySDK() {
67
- //// loadingIndicator.startAnimating()
68
- ////
69
- ////// let sdkURL = request.isSandbox
70
- ////// ? "https://bank-link-widget-sandbox.grailpay.com/sdk.js"
71
- ////// : "https://bank-link-widget.grailpay.com/sdk.js"
72
- ////
73
- //// let sdkURL = EnvironmentConfig.grailPaySDKURL
74
- ////
75
- //// let html = """
76
- //// <!DOCTYPE html>
77
- //// <html>
78
- //// <head>
79
- //// <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">
80
- //// <script>
81
- //// window.sdkInitialized = false;
82
- ////
83
- //// function initializeSDK() {
84
- //// if (window.sdkInitialized) return;
85
- ////
86
- //// if (typeof window.grailpay === 'undefined') {
87
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'SDK not loaded' });
88
- //// return;
89
- //// }
90
- ////
91
- //// window.grailpay.init({
92
- //// token: '\(UserStoreSingleton.shared.bankWidgetKey ?? "")',
93
- //// vendorId: '\(UserStoreSingleton.shared.vendorID ?? "")',
94
- //// role: '\(request.role)',
95
- //// timeout: \(request.timeout),
96
- //// theme: {
97
- //// branding_name: '\(request.brandingName)',
98
- //// screens: {
99
- //// finder: {
100
- //// subtitle: '\(request.finderSubtitle)',
101
- //// searchPlaceholder: '\(request.searchPlaceholder)'
102
- //// }
103
- //// }
104
- //// },
105
- //// onError: function(error) {
106
- //// console.log("JS onError:", error);
107
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
108
- //// },
109
- //// onBankConnected: function(data) {
110
- //// console.log("✅ Bank connected:", data);
111
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'bankConnected', data: data });
112
- //// },
113
- //// onLinkedDefaultAccount: function(data) {
114
- //// console.log("✅ Default Account selected:", data);
115
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'defaultAccountSelected', data: data });
116
- //// },
117
- //// onLinkExit: function(data) {
118
- //// console.log("⚠️ User exited:", data);
119
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'linkExit', data: data });
120
- //// }
121
- //// }).then(function() {
122
- //// window.sdkInitialized = true;
123
- //// window.grailpay.open();
124
- //// }).catch(function(error) {
125
- //// console.log("❌ SDK init failed:", error);
126
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
127
- //// });
128
- //// }
129
- ////
130
- //// function loadSDK() {
131
- //// const script = document.createElement('script');
132
- //// script.src = '\(sdkURL)';
133
- //// script.onload = function() {
134
- //// setTimeout(initializeSDK, 1000);
135
- //// };
136
- //// script.onerror = function(error) {
137
- //// console.log("❌ Failed to load SDK script");
138
- //// window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'Failed to load SDK script' });
139
- //// };
140
- //// document.head.appendChild(script);
141
- //// }
142
- ////
143
- //// document.addEventListener('DOMContentLoaded', loadSDK);
144
- //// </script>
145
- //// </head>
146
- //// <body style=\"margin:0;padding:0;\"></body>
147
- //// </html>
148
- //// """
149
- ////
150
- ////// let baseURL = URL(string: request.isSandbox
151
- ////// ? "https://bank-link-widget-sandbox.grailpay.com"
152
- ////// : "https://bank-link-widget.grailpay.com")
153
- ////
154
- //// let baseURL = URL(string: EnvironmentConfig.grailPayBaseURL)
155
- ////
156
- //// webView.loadHTMLString(html, baseURL: baseURL)
157
- //// }
158
- ////
159
- //// private func handleError(_ error: Error) {
160
- //// DispatchQueue.main.async {
161
- //// self.loadingIndicator.stopAnimating()
162
- //// self.onCompletion?(EasyPay.SDKResult(error: error as NSError))
163
- //// self.dismiss(animated: true)
164
- //// }
165
- //// }
166
- ////}
167
1
  ////
168
- ////// MARK: - WKNavigationDelegate
169
- ////extension GrailPayVC: WKNavigationDelegate {
170
- //// public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
171
- //// loadingIndicator.stopAnimating()
172
- //// }
173
- ////
174
- //// public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
175
- //// handleError(error)
176
- //// }
177
- ////}
2
+ //// GrailPayVC.swift
3
+ //// EasyPay
178
4
  ////
179
- ////// MARK: - WKScriptMessageHandler
180
- ////extension GrailPayVC: WKScriptMessageHandler {
181
- //// public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
182
- //// print("JS Message received: \(message.body)")
183
- ////
184
- //// guard let body = message.body as? [String: Any],
185
- //// let type = body["type"] as? String else {
186
- //// print("Invalid message structure")
187
- //// return
188
- //// }
189
- ////
190
- //// switch type {
191
- //// case "bankConnected":
192
- //// if let data = body["data"] as? [[String: Any]] {
193
- //// print("✅ All linked accounts:", data)
194
- //// self.allLinkedAccounts = data
195
- //// }
196
- ////
197
- //// case "defaultAccountSelected":
198
- //// guard let selectedAccount = body["data"] as? [String: Any] else {
199
- //// print("No account data selected")
200
- //// return
201
- //// }
202
- ////
203
- //// print("✅ Selected default account: \(selectedAccount)")
204
- ////
205
- //// if !didHandleBankConnection {
206
- //// didHandleBankConnection = true
207
- //// DispatchQueue.main.async {
208
- //// self.onCompletion?(EasyPay.SDKResult(type: .success, chargeData: ["data": [selectedAccount]]))
209
- //// self.dismiss(animated: true)
210
- //// }
211
- //// }
212
- ////
213
- //// case "linkExit":
214
- //// if didHandleBankConnection {
215
- //// print("linkExit ignored (already handled)")
216
- //// return
217
- //// }
218
- //// print("User exited linking flow")
219
- //// DispatchQueue.main.async {
220
- //// self.onCompletion?(EasyPay.SDKResult(type: .cancelled))
221
- //// self.dismiss(animated: true)
222
- //// }
223
- ////
224
- //// case "error":
225
- //// let errorMessage = body["data"] as? String ?? "Unknown error"
226
- //// print("GrailPay Error:", errorMessage)
227
- //// let error = NSError(domain: "GrailPayError", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage])
228
- //// handleError(error)
229
- ////
230
- //// default:
231
- //// print("Unknown JS message type:", type)
232
- //// }
233
- //// }
234
- ////}
5
+ //// Created by Mony's Mac on 02/05/25.
235
6
  ////
236
- ////// MARK: - WKUIDelegate
237
- ////extension GrailPayVC: WKUIDelegate {
238
- //// public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
239
- //// for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
240
- //// if navigationAction.targetFrame == nil {
241
- //// webView.load(navigationAction.request)
242
- //// }
243
- //// return nil
244
- //// }
245
- ////}
246
- //
247
- //
248
- //
249
- //
250
- //
251
- //
252
- //
253
- //
254
- //
255
- //
7
+
256
8
  //import UIKit
257
9
  //import WebKit
258
10
  //
@@ -261,7 +13,7 @@
261
13
  // private var webView: WKWebView!
262
14
  // private var loadingIndicator: UIActivityIndicatorView!
263
15
  // private var request: GrailPayRequest
264
- // public var onCompletion: ((SDKResult) -> Void)?
16
+ // public var onCompletion: ((EasyPay.SDKResult) -> Void)?
265
17
  // private var didHandleBankConnection = false
266
18
  // private var allLinkedAccounts: [[String: Any]] = []
267
19
  //
@@ -314,14 +66,17 @@
314
66
  // private func loadGrailPaySDK() {
315
67
  // loadingIndicator.startAnimating()
316
68
  //
317
- // let sdkURL = EnvironmentConfig.grailPaySDKURL
318
- // let baseURL = URL(string: EnvironmentConfig.grailPayBaseURL)
69
+ //// let sdkURL = request.isSandbox
70
+ //// ? "https://bank-link-widget-sandbox.grailpay.com/sdk.js"
71
+ //// : "https://bank-link-widget.grailpay.com/sdk.js"
319
72
  //
73
+ // let sdkURL = EnvironmentConfig.grailPaySDKURL
74
+ //
320
75
  // let html = """
321
76
  // <!DOCTYPE html>
322
77
  // <html>
323
78
  // <head>
324
- // <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
79
+ // <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">
325
80
  // <script>
326
81
  // window.sdkInitialized = false;
327
82
  //
@@ -388,21 +143,23 @@
388
143
  // document.addEventListener('DOMContentLoaded', loadSDK);
389
144
  // </script>
390
145
  // </head>
391
- // <body style="margin:0;padding:0;"></body>
146
+ // <body style=\"margin:0;padding:0;\"></body>
392
147
  // </html>
393
148
  // """
394
149
  //
150
+ //// let baseURL = URL(string: request.isSandbox
151
+ //// ? "https://bank-link-widget-sandbox.grailpay.com"
152
+ //// : "https://bank-link-widget.grailpay.com")
153
+ //
154
+ // let baseURL = URL(string: EnvironmentConfig.grailPayBaseURL)
155
+ //
395
156
  // webView.loadHTMLString(html, baseURL: baseURL)
396
157
  // }
397
158
  //
398
159
  // private func handleError(_ error: Error) {
399
160
  // DispatchQueue.main.async {
400
161
  // self.loadingIndicator.stopAnimating()
401
- // let errorData: [String: Any] = [
402
- // "status": false,
403
- // "message": error.localizedDescription
404
- // ]
405
- // self.onCompletion?(SDKResult(type: .error, data: errorData as NSDictionary))
162
+ // self.onCompletion?(EasyPay.SDKResult(error: error as NSError))
406
163
  // self.dismiss(animated: true)
407
164
  // }
408
165
  // }
@@ -443,7 +200,7 @@
443
200
  // if !didHandleBankConnection {
444
201
  // didHandleBankConnection = true
445
202
  // DispatchQueue.main.async {
446
- // self.onCompletion?(SDKResult(type: .success, data: ["data": [selectedAccount]] as NSDictionary))
203
+ // self.onCompletion?(EasyPay.SDKResult(type: .success, chargeData: ["data": [selectedAccount]]))
447
204
  // self.dismiss(animated: true)
448
205
  // }
449
206
  // }
@@ -453,11 +210,7 @@
453
210
  // return
454
211
  // }
455
212
  // DispatchQueue.main.async {
456
- // let cancelData: [String: Any] = [
457
- // "status": false,
458
- // "message": "User cancelled the payment"
459
- // ]
460
- // self.onCompletion?(SDKResult(type: .cancelled, data: cancelData as NSDictionary))
213
+ // self.onCompletion?(EasyPay.SDKResult(type: .cancelled))
461
214
  // self.dismiss(animated: true)
462
215
  // }
463
216
  //
@@ -481,3 +234,242 @@
481
234
  // return nil
482
235
  // }
483
236
  //}
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ import UIKit
248
+ import WebKit
249
+
250
+ public class GrailPayVC: UIViewController {
251
+
252
+ private var webView: WKWebView!
253
+ private var loadingIndicator: UIActivityIndicatorView!
254
+ private var request: GrailPayRequest
255
+ public var onCompletion: ((SDKResult) -> Void)?
256
+ private var didHandleBankConnection = false
257
+ private var allLinkedAccounts: [[String: Any]] = []
258
+
259
+ public init(request: GrailPayRequest) {
260
+ self.request = request
261
+ super.init(nibName: nil, bundle: nil)
262
+ }
263
+
264
+ required init?(coder: NSCoder) {
265
+ fatalError("init(coder:) has not been implemented")
266
+ }
267
+
268
+ override public func viewDidLoad() {
269
+ super.viewDidLoad()
270
+ setupUI()
271
+ loadGrailPaySDK()
272
+ }
273
+
274
+ private func setupUI() {
275
+ view.backgroundColor = .white
276
+
277
+ let config = WKWebViewConfiguration()
278
+ if #available(iOS 14.0, *) {
279
+ let webpagePreferences = WKWebpagePreferences()
280
+ webpagePreferences.allowsContentJavaScript = true
281
+ config.defaultWebpagePreferences = webpagePreferences
282
+ } else {
283
+ let preferences = WKPreferences()
284
+ preferences.javaScriptEnabled = true
285
+ config.preferences = preferences
286
+ }
287
+
288
+ config.websiteDataStore = WKWebsiteDataStore.default()
289
+ config.userContentController.add(self, name: "grailpayHandler")
290
+ config.allowsInlineMediaPlayback = true
291
+ config.mediaTypesRequiringUserActionForPlayback = []
292
+
293
+ webView = WKWebView(frame: view.bounds, configuration: config)
294
+ webView.navigationDelegate = self
295
+ webView.uiDelegate = self
296
+ webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
297
+ view.addSubview(webView)
298
+
299
+ loadingIndicator = UIActivityIndicatorView(style: .large)
300
+ loadingIndicator.center = view.center
301
+ loadingIndicator.hidesWhenStopped = true
302
+ view.addSubview(loadingIndicator)
303
+ }
304
+
305
+ private func loadGrailPaySDK() {
306
+ loadingIndicator.startAnimating()
307
+
308
+ let sdkURL = EnvironmentConfig.grailPaySDKURL
309
+ let baseURL = URL(string: EnvironmentConfig.grailPayBaseURL)
310
+
311
+ let html = """
312
+ <!DOCTYPE html>
313
+ <html>
314
+ <head>
315
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
316
+ <script>
317
+ window.sdkInitialized = false;
318
+
319
+ function initializeSDK() {
320
+ if (window.sdkInitialized) return;
321
+
322
+ if (typeof window.grailpay === 'undefined') {
323
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'SDK not loaded' });
324
+ return;
325
+ }
326
+
327
+ window.grailpay.init({
328
+ token: '\(UserStoreSingleton.shared.bankWidgetKey ?? "")',
329
+ vendorId: '\(UserStoreSingleton.shared.vendorID ?? "")',
330
+ role: '\(request.role)',
331
+ timeout: \(request.timeout),
332
+ theme: {
333
+ branding_name: '\(request.brandingName)',
334
+ screens: {
335
+ finder: {
336
+ subtitle: '\(request.finderSubtitle)',
337
+ searchPlaceholder: '\(request.searchPlaceholder)'
338
+ }
339
+ }
340
+ },
341
+ onError: function(error) {
342
+ console.log("JS onError:", error);
343
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
344
+ },
345
+ onBankConnected: function(data) {
346
+ console.log("✅ Bank connected:", data);
347
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'bankConnected', data: data });
348
+ },
349
+ onLinkedDefaultAccount: function(data) {
350
+ console.log("✅ Default Account selected:", data);
351
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'defaultAccountSelected', data: data });
352
+ },
353
+ onLinkExit: function(data) {
354
+ console.log("⚠️ User exited:", data);
355
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'linkExit', data: data });
356
+ }
357
+ }).then(function() {
358
+ window.sdkInitialized = true;
359
+ window.grailpay.open();
360
+ }).catch(function(error) {
361
+ console.log("❌ SDK init failed:", error);
362
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: error });
363
+ });
364
+ }
365
+
366
+ function loadSDK() {
367
+ const script = document.createElement('script');
368
+ script.src = '\(sdkURL)';
369
+ script.onload = function() {
370
+ setTimeout(initializeSDK, 1000);
371
+ };
372
+ script.onerror = function(error) {
373
+ console.log("❌ Failed to load SDK script");
374
+ window.webkit.messageHandlers.grailpayHandler.postMessage({ type: 'error', data: 'Failed to load SDK script' });
375
+ };
376
+ document.head.appendChild(script);
377
+ }
378
+
379
+ document.addEventListener('DOMContentLoaded', loadSDK);
380
+ </script>
381
+ </head>
382
+ <body style="margin:0;padding:0;"></body>
383
+ </html>
384
+ """
385
+
386
+ webView.loadHTMLString(html, baseURL: baseURL)
387
+ }
388
+
389
+ private func handleError(_ error: Error) {
390
+ DispatchQueue.main.async {
391
+ self.loadingIndicator.stopAnimating()
392
+ let errorData: [String: Any] = [
393
+ "status": false,
394
+ "message": error.localizedDescription
395
+ ]
396
+ self.onCompletion?(SDKResult(type: .error, data: errorData as NSDictionary))
397
+ self.dismiss(animated: true)
398
+ }
399
+ }
400
+ }
401
+
402
+ // MARK: - WKNavigationDelegate
403
+ extension GrailPayVC: WKNavigationDelegate {
404
+ public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
405
+ loadingIndicator.stopAnimating()
406
+ }
407
+
408
+ public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
409
+ handleError(error)
410
+ }
411
+ }
412
+
413
+ // MARK: - WKScriptMessageHandler
414
+ extension GrailPayVC: WKScriptMessageHandler {
415
+ public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
416
+
417
+ guard let body = message.body as? [String: Any],
418
+ let type = body["type"] as? String else {
419
+ return
420
+ }
421
+
422
+ switch type {
423
+ case "bankConnected":
424
+ if let data = body["data"] as? [[String: Any]] {
425
+ self.allLinkedAccounts = data
426
+ }
427
+
428
+ case "defaultAccountSelected":
429
+ guard let selectedAccount = body["data"] as? [String: Any] else {
430
+ return
431
+ }
432
+
433
+
434
+ if !didHandleBankConnection {
435
+ didHandleBankConnection = true
436
+ DispatchQueue.main.async {
437
+ self.onCompletion?(SDKResult(type: .success, data: ["data": [selectedAccount]] as NSDictionary))
438
+ self.dismiss(animated: true)
439
+ }
440
+ }
441
+
442
+ case "linkExit":
443
+ if didHandleBankConnection {
444
+ return
445
+ }
446
+ DispatchQueue.main.async {
447
+ let cancelData: [String: Any] = [
448
+ "status": false,
449
+ "message": "User cancelled the payment"
450
+ ]
451
+ self.onCompletion?(SDKResult(type: .cancelled, data: cancelData as NSDictionary))
452
+ self.dismiss(animated: true)
453
+ }
454
+
455
+ case "error":
456
+ let errorMessage = body["data"] as? String ?? "Unknown error"
457
+ let error = NSError(domain: "GrailPayError", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage])
458
+ handleError(error)
459
+
460
+ default:
461
+ break
462
+ }
463
+ }
464
+ }
465
+
466
+ // MARK: - WKUIDelegate
467
+ extension GrailPayVC: WKUIDelegate {
468
+ public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
469
+ for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
470
+ if navigationAction.targetFrame == nil {
471
+ webView.load(navigationAction.request)
472
+ }
473
+ return nil
474
+ }
475
+ }