@jimrising/easymerchantsdk-react-native 1.4.3 → 1.4.4

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.
@@ -74,8 +74,11 @@ class OTPVerificationVC: BaseVC {
74
74
 
75
75
  var amount: Int?
76
76
 
77
+ var isSavedNewCard: Bool = false
78
+
77
79
  override func viewDidLoad() {
78
80
  super.viewDidLoad()
81
+ emailVerificationApi()
79
82
 
80
83
  uiFinishingTouchElements()
81
84
 
@@ -269,6 +272,89 @@ class OTPVerificationVC: BaseVC {
269
272
  }
270
273
  }
271
274
 
275
+ //MARK: - Send OTP Email Verification Api
276
+ func emailVerificationApi() {
277
+ showLoadingIndicator()
278
+
279
+ let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.emailVerification.path()
280
+
281
+ guard let serviceURL = URL(string: fullURL) else {
282
+ print("Invalid URL")
283
+ hideLoadingIndicator()
284
+ return
285
+ }
286
+
287
+ var request = URLRequest(url: serviceURL)
288
+ request.httpMethod = "POST"
289
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type")
290
+
291
+ let token = UserStoreSingleton.shared.clientToken
292
+ print("Setting clientToken header: \(token ?? "None")")
293
+ request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
294
+
295
+ // Add API headers
296
+ if let apiKey = EnvironmentConfig.apiKey,
297
+ let apiSecret = EnvironmentConfig.apiSecret {
298
+ request.addValue(apiKey, forHTTPHeaderField: "x-api-key")
299
+ request.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
300
+ }
301
+
302
+ let params: [String: Any] = [
303
+ "card_search_value": email ?? "",
304
+ "card_search_key": "email"
305
+ ]
306
+
307
+ do {
308
+ let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
309
+ request.httpBody = jsonData
310
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
311
+ print("JSON Payload: \(jsonString)")
312
+ }
313
+ } catch let error {
314
+ print("Error creating JSON data: \(error)")
315
+ hideLoadingIndicator()
316
+ return
317
+ }
318
+
319
+ let session = URLSession.shared
320
+ let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
321
+
322
+ DispatchQueue.main.async {
323
+ self.hideLoadingIndicator() // Stop loader when response is received
324
+ }
325
+
326
+ if let error = error {
327
+ print("Error: \(error.localizedDescription)")
328
+ return
329
+ }
330
+
331
+ guard let httpResponse = serviceResponse as? HTTPURLResponse else {
332
+ print("Invalid response")
333
+ return
334
+ }
335
+
336
+ if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
337
+ if let data = serviceData {
338
+ do {
339
+ if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
340
+ print("Response Data: \(responseObject)")
341
+
342
+ } else {
343
+ print("Invalid JSON format")
344
+ }
345
+ } catch let jsonError {
346
+ print("Error parsing JSON: \(jsonError)")
347
+ }
348
+ } else {
349
+ print("No data received")
350
+ }
351
+ } else {
352
+ print("HTTP Status Code: \(httpResponse.statusCode)")
353
+ }
354
+ }
355
+ task.resume()
356
+ }
357
+
272
358
  //MARK: - OTP Verification Api
273
359
  func otpVerificationApi() {
274
360
  showLoadingIndicator()
@@ -336,7 +422,7 @@ class OTPVerificationVC: BaseVC {
336
422
  do {
337
423
  if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
338
424
  print("Response Data: \(responseObject)")
339
- if self.selectedPaymentMethod == "Card" {
425
+ if self.selectedPaymentMethod == "Card"{
340
426
  if let dataSection = responseObject["data"] as? [String: Any],
341
427
  let innerData = dataSection["data"] as? [String: Any],
342
428
  let customerId = innerData["customer_id"] as? String {
@@ -404,100 +490,17 @@ class OTPVerificationVC: BaseVC {
404
490
  self.grailPayAccountChargeApi(customerId: nil)
405
491
  }
406
492
  }
407
- else if self.selectedPaymentMethod == "NewGrailPayAccount" {
408
- if let dataSection = responseObject["data"] as? [String: Any],
409
- let innerData = dataSection["data"] as? [String: Any],
410
- let customerId = innerData["customer_id"] as? String {
411
- print("Extracted customer_id: \(customerId)")
412
- self.grailPayAccountChargeApi(customerId: customerId)
413
- } else {
414
- print("customer_id not found. Sending empty customerId.")
415
- self.grailPayAccountChargeApi(customerId: nil)
416
- }
417
- }
418
- } else {
419
- print("Invalid JSON format")
420
- }
421
- } catch let jsonError {
422
- print("Error parsing JSON: \(jsonError)")
423
- }
424
- } else {
425
- print("No data received")
426
- }
427
- } else {
428
- print("HTTP Status Code: \(httpResponse.statusCode)")
429
- }
430
- }
431
- task.resume()
432
- }
433
-
434
- //MARK: - Send OTP Email Verification Api
435
- func emailVerificationApi() {
436
- showLoadingIndicator()
437
-
438
- let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.emailVerification.path()
439
-
440
- guard let serviceURL = URL(string: fullURL) else {
441
- print("Invalid URL")
442
- hideLoadingIndicator()
443
- return
444
- }
445
-
446
- var request = URLRequest(url: serviceURL)
447
- request.httpMethod = "POST"
448
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
449
-
450
- let token = UserStoreSingleton.shared.clientToken
451
- print("Setting clientToken header: \(token ?? "None")")
452
- request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
453
-
454
- // Add API headers
455
- if let apiKey = EnvironmentConfig.apiKey,
456
- let apiSecret = EnvironmentConfig.apiSecret {
457
- request.addValue(apiKey, forHTTPHeaderField: "x-api-key")
458
- request.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
459
- }
460
-
461
- let params: [String: Any] = [
462
- "card_search_value": email ?? "",
463
- "card_search_key": "email"
464
- ]
465
-
466
- do {
467
- let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
468
- request.httpBody = jsonData
469
- if let jsonString = String(data: jsonData, encoding: .utf8) {
470
- print("JSON Payload: \(jsonString)")
471
- }
472
- } catch let error {
473
- print("Error creating JSON data: \(error)")
474
- hideLoadingIndicator()
475
- return
476
- }
477
-
478
- let session = URLSession.shared
479
- let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
480
-
481
- DispatchQueue.main.async {
482
- self.hideLoadingIndicator() // Stop loader when response is received
483
- }
484
-
485
- if let error = error {
486
- print("Error: \(error.localizedDescription)")
487
- return
488
- }
489
-
490
- guard let httpResponse = serviceResponse as? HTTPURLResponse else {
491
- print("Invalid response")
492
- return
493
- }
494
-
495
- if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
496
- if let data = serviceData {
497
- do {
498
- if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
499
- print("Response Data: \(responseObject)")
500
-
493
+ // else if self.selectedPaymentMethod == "NewGrailPayAccount" {
494
+ // if let dataSection = responseObject["data"] as? [String: Any],
495
+ // let innerData = dataSection["data"] as? [String: Any],
496
+ // let customerId = innerData["customer_id"] as? String {
497
+ // print("Extracted customer_id: \(customerId)")
498
+ // self.grailPayAccountChargeApi(customerId: customerId)
499
+ // } else {
500
+ // print("customer_id not found. Sending empty customerId.")
501
+ // self.grailPayAccountChargeApi(customerId: nil)
502
+ // }
503
+ // }
501
504
  } else {
502
505
  print("Invalid JSON format")
503
506
  }
@@ -1456,7 +1459,7 @@ class OTPVerificationVC: BaseVC {
1456
1459
 
1457
1460
  var params: [String: Any] = [
1458
1461
  "name": nameOnCard ?? "",
1459
- "email": UserStoreSingleton.shared.merchantEmail ?? "",
1462
+ "email": userEmail ?? "",
1460
1463
  "card_number": cardNumber?.replacingOccurrences(of: " ", with: "") ?? "",
1461
1464
  "cardholder_name": nameOnCard ?? "",
1462
1465
  "exp_month": expiryDate?.components(separatedBy: "/").first ?? "",