@jimrising/easymerchantsdk-react-native 1.3.2 → 1.3.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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  import UIKit
9
9
 
10
- // @available(iOS 16.0, *)
10
+ @available(iOS 16.0, *)
11
11
  class AdditionalInfoVC: BaseVC {
12
12
 
13
13
  @IBOutlet weak var viewAdditionalInfo: UIView!
@@ -196,66 +196,79 @@ class AdditionalInfoVC: BaseVC {
196
196
  }
197
197
 
198
198
  @IBAction func actionBtnPayNow(_ sender: UIButton) {
199
- if isSavedNewCard {
200
- if isFrom == "AddNewCard" {
201
- self.paymentIntentAddNewCardApi(customerId: UserStoreSingleton.shared.customerId)
202
- }
199
+ if self.txtFieldName.text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true {
200
+ self.showAlert(title: "Missing Information", message: "Please enter your name.")
201
+ }
202
+ else if self.txtFieldEmail.text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true {
203
+ self.showAlert(title: "Missing Information", message: "Please enter your email address.")
204
+ }
205
+ else if self.txtFieldPhoneNumber.text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true {
206
+ self.showAlert(title: "Missing Information", message: "Please enter your phone number.")
207
+ }
208
+ else if self.txtFieldDescription.text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true {
209
+ self.showAlert(title: "Missing Information", message: "Please enter description text.")
203
210
  }
204
211
  else {
205
- if isSavedForFuture {
206
- // Navigate to EmailVerificationVC based on the selected payment method
207
- if selectedPaymentMethod == "Card" {
208
- if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
209
- // Pass any necessary data to EmailVerificationVC
210
- emailVerificationVC.cardNumber = cardNumber
211
- emailVerificationVC.expiryDate = expiryDate
212
- emailVerificationVC.cvv = cvv
213
- emailVerificationVC.nameOnCard = nameOnCard
214
- emailVerificationVC.billingInfoData = billingInfoData
215
- emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
216
- emailVerificationVC.easyPayDelegate = self.easyPayDelegate
217
- self.navigationController?.pushViewController(emailVerificationVC, animated: true)
218
- }
219
- } else if selectedPaymentMethod == "Bank" {
220
- if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
221
- // Pass any necessary data to EmailVerificationVC
222
- emailVerificationVC.accountName = accountName
223
- emailVerificationVC.routingNumber = routingNumber
224
- emailVerificationVC.accountType = accountType
225
- emailVerificationVC.accountNumber = accountNumber
226
- emailVerificationVC.billingInfoData = billingInfoData
227
- emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
228
- emailVerificationVC.easyPayDelegate = self.easyPayDelegate
229
- self.navigationController?.pushViewController(emailVerificationVC, animated: true)
230
- }
212
+ if isSavedNewCard {
213
+ if isFrom == "AddNewCard" {
214
+ self.paymentIntentAddNewCardApi(customerId: UserStoreSingleton.shared.customerId)
231
215
  }
232
- } else {
233
- // Proceed with the normal flow
234
- if selectedPaymentMethod == "Card" {
235
- if isFrom == "SavedCards" {
236
- paymentIntentFromShowCardApi()
237
- }
238
- else {
239
- paymentIntentApi()
240
- }
241
- }
242
- else if selectedPaymentMethod == "Bank" {
243
- if isFrom == "SavedBank" {
244
- accountChargeSavedBankAccountApi()
245
- }
246
- else if isFrom == "NormalBankPayWithoutSave" {
247
- accountChargeApi()
216
+ }
217
+ else {
218
+ if isSavedForFuture {
219
+ // Navigate to EmailVerificationVC based on the selected payment method
220
+ if selectedPaymentMethod == "Card" {
221
+ if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
222
+ // Pass any necessary data to EmailVerificationVC
223
+ emailVerificationVC.cardNumber = cardNumber
224
+ emailVerificationVC.expiryDate = expiryDate
225
+ emailVerificationVC.cvv = cvv
226
+ emailVerificationVC.nameOnCard = nameOnCard
227
+ emailVerificationVC.billingInfoData = billingInfoData
228
+ emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
229
+ emailVerificationVC.easyPayDelegate = self.easyPayDelegate
230
+ self.navigationController?.pushViewController(emailVerificationVC, animated: true)
231
+ }
232
+ } else if selectedPaymentMethod == "Bank" {
233
+ if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
234
+ // Pass any necessary data to EmailVerificationVC
235
+ emailVerificationVC.accountName = accountName
236
+ emailVerificationVC.routingNumber = routingNumber
237
+ emailVerificationVC.accountType = accountType
238
+ emailVerificationVC.accountNumber = accountNumber
239
+ emailVerificationVC.billingInfoData = billingInfoData
240
+ emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
241
+ emailVerificationVC.easyPayDelegate = self.easyPayDelegate
242
+ self.navigationController?.pushViewController(emailVerificationVC, animated: true)
243
+ }
248
244
  }
249
- else if isFrom == "AddNewAccountWithoutSave" {
250
- accountChargeApi()
245
+ } else {
246
+ // Proceed with the normal flow
247
+ if selectedPaymentMethod == "Card" {
248
+ if isFrom == "SavedCards" {
249
+ paymentIntentFromShowCardApi()
250
+ }
251
+ else {
252
+ paymentIntentApi()
253
+ }
251
254
  }
252
- else if isFrom == "AddNewAccountWithSave" {
253
- accountChargeApi(customerId: UserStoreSingleton.shared.customerId)
255
+ else if selectedPaymentMethod == "Bank" {
256
+ if isFrom == "SavedBank" {
257
+ accountChargeSavedBankAccountApi()
258
+ }
259
+ else if isFrom == "NormalBankPayWithoutSave" {
260
+ accountChargeApi()
261
+ }
262
+ else if isFrom == "AddNewAccountWithoutSave" {
263
+ accountChargeApi()
264
+ }
265
+ else if isFrom == "AddNewAccountWithSave" {
266
+ accountChargeApi(customerId: UserStoreSingleton.shared.customerId)
267
+ }
254
268
  }
255
269
  }
256
270
  }
257
271
  }
258
-
259
272
  }
260
273
 
261
274
  func presentPaymentErrorVC(errorMessage: String) {
@@ -272,18 +285,6 @@ class AdditionalInfoVC: BaseVC {
272
285
  func paymentIntentApi() {
273
286
  showLoadingIndicator()
274
287
 
275
- // var components = URLComponents()
276
- // components.scheme = "https"
277
- // components.host = "stage-api.stage-easymerchant.io"
278
- // components.path = "/api/v1/charges"
279
- //
280
- // guard let serviceURL = components.url else {
281
- // print("Invalid URL")
282
- // self.hideLoadingIndicator()
283
- // return
284
- // }
285
-
286
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
287
288
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
288
289
 
289
290
  guard let serviceURL = URL(string: fullURL) else {
@@ -302,20 +303,17 @@ class AdditionalInfoVC: BaseVC {
302
303
 
303
304
  guard let billingInfoData = billingInfoData else {
304
305
  print("Billing info data is nil")
306
+ hideLoadingIndicator()
305
307
  return
306
308
  }
307
309
 
308
- // Remove the flag and "+" sign from lblCountryCode.text
309
- let countryCode = lblCountryCode.text ?? ""
310
- let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
311
- // Format phone number parameter by combining cleaned country code and phone number
312
- let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
310
+ // Extract only the digits from the phone number (local only, no country code)
311
+ let localPhone = txtFieldPhoneNumber.text?.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() ?? ""
313
312
 
314
313
  let additionalInfo: [String: Any] = [
315
314
  "name": txtFieldName.text ?? "",
316
315
  "email": txtFieldEmail.text ?? "",
317
- // "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
318
- "phone_number": phoneNumber,
316
+ "phone_number": localPhone,
319
317
  "description": txtFieldDescription.text ?? ""
320
318
  ]
321
319
 
@@ -340,7 +338,7 @@ class AdditionalInfoVC: BaseVC {
340
338
  "billing_info": billingInfo,
341
339
  "additional_info": additionalInfo,
342
340
  "payment_method": "card",
343
- "save_card": 0,
341
+ "save_card": 0
344
342
  ]
345
343
 
346
344
  do {
@@ -351,7 +349,7 @@ class AdditionalInfoVC: BaseVC {
351
349
  }
352
350
  } catch let error {
353
351
  print("Error creating JSON data: \(error)")
354
- self.hideLoadingIndicator()
352
+ hideLoadingIndicator()
355
353
  return
356
354
  }
357
355
 
@@ -359,16 +357,18 @@ class AdditionalInfoVC: BaseVC {
359
357
  let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
360
358
 
361
359
  DispatchQueue.main.async {
362
- self.hideLoadingIndicator() // Stop loader when response is received
360
+ self.hideLoadingIndicator()
363
361
  }
364
362
 
365
363
  if let error = error {
366
364
  print("Error: \(error.localizedDescription)")
365
+ self.presentPaymentErrorVC(errorMessage: error.localizedDescription)
367
366
  return
368
367
  }
369
368
 
370
369
  guard let httpResponse = serviceResponse as? HTTPURLResponse else {
371
370
  print("Invalid response")
371
+ self.presentPaymentErrorVC(errorMessage: "Invalid response from server.")
372
372
  return
373
373
  }
374
374
 
@@ -378,9 +378,8 @@ class AdditionalInfoVC: BaseVC {
378
378
  if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
379
379
  print("Response Data: \(responseObject)")
380
380
 
381
- // Check if status is 0 and handle the error
382
381
  if let status = responseObject["status"] as? Int, status == 0 {
383
- let errorMessage = responseObject["message"] as? String ?? "Unknown error"
382
+ let errorMessage = responseObject["message"] as? String ?? "Unknown error occurred."
384
383
  self.presentPaymentErrorVC(errorMessage: errorMessage)
385
384
  } else {
386
385
  DispatchQueue.main.async {
@@ -396,33 +395,28 @@ class AdditionalInfoVC: BaseVC {
396
395
  self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
397
396
  }
398
397
  } catch let jsonError {
399
- self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
398
+ self.presentPaymentErrorVC(errorMessage: "Error parsing response: \(jsonError.localizedDescription)")
400
399
  }
401
400
  } else {
402
- self.presentPaymentErrorVC(errorMessage: "No data received")
401
+ self.presentPaymentErrorVC(errorMessage: "No data received from server.")
403
402
  }
404
403
  } else {
405
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
404
+ if let data = serviceData,
405
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
406
+ let message = responseObj["message"] as? String {
407
+ self.presentPaymentErrorVC(errorMessage: message)
408
+ } else {
409
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
410
+ }
406
411
  }
407
412
  }
408
413
  task.resume()
409
414
  }
410
-
415
+
411
416
  //MARK: - Credit Card Charge Api from Saved cards
412
417
  func paymentIntentFromShowCardApi() {
413
418
  showLoadingIndicator()
414
- // var components = URLComponents()
415
- // components.scheme = "https"
416
- // components.host = "stage-api.stage-easymerchant.io"
417
- // components.path = "/api/v1/charges"
418
- //
419
- // guard let serviceURL = components.url else {
420
- // print("Invalid URL")
421
- // hideLoadingIndicator()
422
- // return
423
- // }
424
419
 
425
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
426
420
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
427
421
 
428
422
  guard let serviceURL = URL(string: fullURL) else {
@@ -444,17 +438,20 @@ class AdditionalInfoVC: BaseVC {
444
438
  return
445
439
  }
446
440
 
447
- // Remove the flag and "+" sign from lblCountryCode.text
448
- let countryCode = lblCountryCode.text ?? ""
449
- let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
450
- // Format phone number parameter by combining cleaned country code and phone number
451
- let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
441
+ // // Remove the flag and "+" sign from lblCountryCode.text
442
+ // let countryCode = lblCountryCode.text ?? ""
443
+ // let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
444
+ // // Format phone number parameter by combining cleaned country code and phone number
445
+ // let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
446
+
447
+ // Extract only the digits from the phone number (local only, no country code)
448
+ let localPhone = txtFieldPhoneNumber.text?.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() ?? ""
452
449
 
453
450
  let additionalInfo: [String: Any] = [
454
451
  "name": txtFieldName.text ?? "",
455
452
  "email": txtFieldEmail.text ?? "",
456
- // "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
457
- "phone_number": phoneNumber,
453
+ "phone_number": localPhone,
454
+ // "phone_number": phoneNumber,
458
455
  "description": txtFieldDescription.text ?? ""
459
456
  ]
460
457
 
@@ -540,7 +537,13 @@ class AdditionalInfoVC: BaseVC {
540
537
  self.presentPaymentErrorVC(errorMessage: "No data received")
541
538
  }
542
539
  } else {
543
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
540
+ if let data = serviceData,
541
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
542
+ let message = responseObj["message"] as? String {
543
+ self.presentPaymentErrorVC(errorMessage: message)
544
+ } else {
545
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
546
+ }
544
547
  }
545
548
  }
546
549
  task.resume()
@@ -550,18 +553,6 @@ class AdditionalInfoVC: BaseVC {
550
553
  func paymentIntentAddNewCardApi(customerId: String?) {
551
554
  showLoadingIndicator()
552
555
 
553
- // var components = URLComponents()
554
- // components.scheme = "https"
555
- // components.host = "stage-api.stage-easymerchant.io"
556
- // components.path = "/api/v1/charges"
557
- //
558
- // guard let serviceURL = components.url else {
559
- // print("Invalid URL")
560
- // hideLoadingIndicator()
561
- // return
562
- // }
563
-
564
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
565
556
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
566
557
 
567
558
  guard let serviceURL = URL(string: fullURL) else {
@@ -691,7 +682,13 @@ class AdditionalInfoVC: BaseVC {
691
682
  self.presentPaymentErrorVC(errorMessage: "No data received")
692
683
  }
693
684
  } else {
694
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
685
+ if let data = serviceData,
686
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
687
+ let message = responseObj["message"] as? String {
688
+ self.presentPaymentErrorVC(errorMessage: message)
689
+ } else {
690
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
691
+ }
695
692
  }
696
693
  }
697
694
  task.resume()
@@ -701,18 +698,6 @@ class AdditionalInfoVC: BaseVC {
701
698
  func accountChargeApi() {
702
699
  showLoadingIndicator()
703
700
 
704
- // var components = URLComponents()
705
- // components.scheme = "https"
706
- // components.host = "stage-api.stage-easymerchant.io"
707
- // components.path = "/api/v1/ach/charge"
708
- //
709
- // guard let serviceURL = components.url else {
710
- // print("Invalid URL")
711
- // hideLoadingIndicator()
712
- // return
713
- // }
714
-
715
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
716
701
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
717
702
 
718
703
  guard let serviceURL = URL(string: fullURL) else {
@@ -734,17 +719,20 @@ class AdditionalInfoVC: BaseVC {
734
719
  return
735
720
  }
736
721
 
737
- // Remove the flag and "+" sign from lblCountryCode.text
738
- let countryCode = lblCountryCode.text ?? ""
739
- let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
740
- // Format phone number parameter by combining cleaned country code and phone number
741
- let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
722
+ // // Remove the flag and "+" sign from lblCountryCode.text
723
+ // let countryCode = lblCountryCode.text ?? ""
724
+ // let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
725
+ // // Format phone number parameter by combining cleaned country code and phone number
726
+ // let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
727
+
728
+ // Extract only the digits from the phone number (local only, no country code)
729
+ let localPhone = txtFieldPhoneNumber.text?.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() ?? ""
742
730
 
743
731
  let additionalInfo: [String: Any] = [
744
732
  "name": txtFieldName.text ?? "",
745
733
  "email": txtFieldEmail.text ?? "",
746
- // "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
747
- "phone_number": phoneNumber,
734
+ "phone_number": localPhone,
735
+ // "phone_number": phoneNumber,
748
736
  "description": txtFieldDescription.text ?? ""
749
737
  ]
750
738
 
@@ -833,7 +821,13 @@ class AdditionalInfoVC: BaseVC {
833
821
  self.presentPaymentErrorVC(errorMessage: "No data received")
834
822
  }
835
823
  } else {
836
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
824
+ if let data = serviceData,
825
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
826
+ let message = responseObj["message"] as? String {
827
+ self.presentPaymentErrorVC(errorMessage: message)
828
+ } else {
829
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
830
+ }
837
831
  }
838
832
  }
839
833
  task.resume()
@@ -843,18 +837,6 @@ class AdditionalInfoVC: BaseVC {
843
837
  func accountChargeSavedBankAccountApi() {
844
838
  showLoadingIndicator()
845
839
 
846
- // var components = URLComponents()
847
- // components.scheme = "https"
848
- // components.host = "stage-api.stage-easymerchant.io"
849
- // components.path = "/api/v1/ach/charge"
850
- //
851
- // guard let serviceURL = components.url else {
852
- // print("Invalid URL")
853
- // hideLoadingIndicator()
854
- // return
855
- // }
856
-
857
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
858
840
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
859
841
 
860
842
  guard let serviceURL = URL(string: fullURL) else {
@@ -876,17 +858,20 @@ class AdditionalInfoVC: BaseVC {
876
858
  return
877
859
  }
878
860
 
879
- // Remove the flag and "+" sign from lblCountryCode.text
880
- let countryCode = lblCountryCode.text ?? ""
881
- let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
882
- // Format phone number parameter by combining cleaned country code and phone number
883
- let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
861
+ // // Remove the flag and "+" sign from lblCountryCode.text
862
+ // let countryCode = lblCountryCode.text ?? ""
863
+ // let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
864
+ // // Format phone number parameter by combining cleaned country code and phone number
865
+ // let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
866
+
867
+ // Extract only the digits from the phone number (local only, no country code)
868
+ let localPhone = txtFieldPhoneNumber.text?.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() ?? ""
884
869
 
885
870
  let additionalInfo: [String: Any] = [
886
871
  "name": txtFieldName.text ?? "",
887
872
  "email": txtFieldEmail.text ?? "",
888
- // "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
889
- "phone_number": phoneNumber,
873
+ "phone_number": localPhone,
874
+ // "phone_number": phoneNumber,
890
875
  "description": txtFieldDescription.text ?? ""
891
876
  ]
892
877
 
@@ -972,7 +957,13 @@ class AdditionalInfoVC: BaseVC {
972
957
  self.presentPaymentErrorVC(errorMessage: "No data received")
973
958
  }
974
959
  } else {
975
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
960
+ if let data = serviceData,
961
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
962
+ let message = responseObj["message"] as? String {
963
+ self.presentPaymentErrorVC(errorMessage: message)
964
+ } else {
965
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
966
+ }
976
967
  }
977
968
  }
978
969
  task.resume()
@@ -982,18 +973,6 @@ class AdditionalInfoVC: BaseVC {
982
973
  func accountChargeApi(customerId: String?) {
983
974
  showLoadingIndicator()
984
975
 
985
- // var components = URLComponents()
986
- // components.scheme = "https"
987
- // components.host = "stage-api.stage-easymerchant.io"
988
- // components.path = "/api/v1/ach/charge"
989
- //
990
- // guard let serviceURL = components.url else {
991
- // print("Invalid URL")
992
- // hideLoadingIndicator()
993
- // return
994
- // }
995
-
996
- // Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
997
976
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
998
977
 
999
978
  guard let serviceURL = URL(string: fullURL) else {
@@ -1118,7 +1097,13 @@ class AdditionalInfoVC: BaseVC {
1118
1097
  self.presentPaymentErrorVC(errorMessage: "No data received")
1119
1098
  }
1120
1099
  } else {
1121
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
1100
+ if let data = serviceData,
1101
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
1102
+ let message = responseObj["message"] as? String {
1103
+ self.presentPaymentErrorVC(errorMessage: message)
1104
+ } else {
1105
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
1106
+ }
1122
1107
  }
1123
1108
  }
1124
1109
  task.resume()