@jimrising/easymerchantsdk-react-native 1.4.5 → 1.4.6

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.
@@ -422,37 +422,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
422
422
  tapGesture.cancelsTouchesInView = false
423
423
  self.view.addGestureRecognizer(tapGesture)
424
424
 
425
- //// Check if billingInfoData is available
426
- // if let billingInfoData = request.billingInfoData,
427
- // let fieldSection = try? JSONDecoder().decode(FieldSection.self, from: billingInfoData) {
428
- //
429
- // let billingVisible = fieldSection.visibility.billing
430
- // let suffix = billingVisible ? " (Billing Info)" : " (Additional Info)"
431
- // let buttonText = (request?.submitButtonText?.isEmpty == false
432
- // ? request!.submitButtonText! + suffix
433
- // : "Next" + suffix)
434
- //
435
- // btnNext.setTitle(buttonText, for: .normal)
436
- // btnPayNowNewCardView.setTitle(buttonText, for: .normal)
437
- // btnPayNowNewAccountView.setTitle(buttonText, for: .normal)
438
- // btnPayNowSingleCard.setTitle(buttonText, for: .normal)
439
- // btnPayNowSingleAccountView.setTitle(buttonText, for: .normal)
440
- // } else {
441
- // let amountValue = request?.amount ?? 0
442
- // let amountText = String(format: "$%.2f", amountValue)
443
- // let submitText = request?.submitButtonText
444
- //
445
- // let defaultTitle = (submitText?.isEmpty == false)
446
- // ? "\(submitText!) (\(amountText))"
447
- // : "Pay Now (\(amountText))"
448
- //
449
- // btnNext.setTitle(defaultTitle, for: .normal)
450
- // btnPayNowNewCardView.setTitle(defaultTitle, for: .normal)
451
- // btnPayNowNewAccountView.setTitle(defaultTitle, for: .normal)
452
- // btnPayNowSingleCard.setTitle(defaultTitle, for: .normal)
453
- // btnPayNowSingleAccountView.setTitle(defaultTitle, for: .normal)
454
- // }
455
-
456
425
  if let billingInfoData = request.billingInfoData,
457
426
  let fieldSection = try? JSONDecoder().decode(FieldSection.self, from: billingInfoData) {
458
427
 
@@ -460,9 +429,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
460
429
  let additionalVisible = fieldSection.visibility.additional
461
430
  let submitText = request?.submitButtonText?.isEmpty == false ? request!.submitButtonText! : "Pay Now"
462
431
  let amountText = String(format: "$%.2f", request?.amount ?? 0)
463
-
432
+
464
433
  var buttonText: String
465
-
434
+
466
435
  if !billingVisible && !additionalVisible {
467
436
  // Both visibility false – show submitText with amount only
468
437
  buttonText = "\(submitText) (\(amountText))"
@@ -474,7 +443,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
474
443
  // Fallback
475
444
  buttonText = "\(submitText) (\(amountText))"
476
445
  }
477
-
446
+
478
447
  btnNext.setTitle(buttonText, for: .normal)
479
448
  btnPayNowNewCardView.setTitle(buttonText, for: .normal)
480
449
  btnPayNowNewAccountView.setTitle(buttonText, for: .normal)
@@ -485,7 +454,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
485
454
  let amountText = String(format: "$%.2f", request?.amount ?? 0)
486
455
  let submitText = request?.submitButtonText?.isEmpty == false ? request!.submitButtonText! : "Pay Now"
487
456
  let defaultTitle = "\(submitText) (\(amountText))"
488
-
457
+
489
458
  btnNext.setTitle(defaultTitle, for: .normal)
490
459
  btnPayNowNewCardView.setTitle(defaultTitle, for: .normal)
491
460
  btnPayNowNewAccountView.setTitle(defaultTitle, for: .normal)
@@ -493,6 +462,14 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
493
462
  btnPayNowSingleAccountView.setTitle(defaultTitle, for: .normal)
494
463
  }
495
464
 
465
+ lblEasyMerchantOne.text = "POWERED BY \(UserStoreSingleton.shared.companyName?.uppercased() ?? "")"
466
+ txtFieldEmailCardView.textField.text = request.email
467
+ cardNameTextField.textField.text = request.name
468
+ txtFieldNameOnCardNewCardView.text = request.name
469
+ txtFieldEmailAccountView.textField.text = request.email
470
+ txtFieldEmailGrailPayView.textField.text = request.email
471
+ txtFieldEmail.text = request.email
472
+
496
473
  emailView.isHidden = true
497
474
  OTPView.isHidden = true
498
475
 
@@ -755,11 +732,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
755
732
  self.viewSingleSavedAccount.isHidden = true
756
733
  self.viewBankFields.isHidden = true
757
734
 
758
- // self.viewBtnShowSavedCards.isHidden = false
759
- // self.lblBtnShowSaveCard.text = "Show Saved Cards"
760
- // self.viewBtnShowSavedCardHeight.constant = 50
761
- // self.viewBtnShowSavedCardTopCon.constant = 20
762
-
763
735
  if request.saveCard == false {
764
736
  self.viewBtnShowSavedCards.isHidden = true
765
737
  self.viewBtnShowSavedCardHeight.constant = 0
@@ -873,18 +845,10 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
873
845
  }
874
846
  }
875
847
  else {
876
- // self.viewBankFields.isHidden = false
877
- // self.viewTermsAndConditions.isHidden = false
878
848
  self.grailPayBankLinkView.isHidden = true
879
849
  }
880
850
  }
881
851
  else {
882
- // self.viewBankFields.isHidden = false
883
- // self.viewBtnShowSavedCards.isHidden = false
884
- // self.lblBtnShowSaveCard.text = "Show Saved Accounts"
885
- // self.viewBtnShowSavedCardHeight.constant = 50
886
- // self.viewBtnShowSavedCardTopCon.constant = 20
887
-
888
852
  if request.saveAccount == false {
889
853
  self.viewBtnShowSavedCards.isHidden = true
890
854
  self.viewBtnShowSavedCardHeight.constant = 0
@@ -1667,28 +1631,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
1667
1631
  viewAccountTypeNewAccountView.layer.cornerRadius = 8
1668
1632
 
1669
1633
  viewAccountTypeNewAccountView.isHidden = true
1670
-
1671
- // tblViewRecurring.delegate = self
1672
- // tblViewRecurring.dataSource = self
1673
- // tblViewRecurring.showsVerticalScrollIndicator = false
1674
- // tblViewRecurring.showsHorizontalScrollIndicator = false
1675
- //
1676
- // viewTblViewRecurring.clipsToBounds = false
1677
- // viewTblViewRecurring.layer.shadowColor = UIColor.black.cgColor
1678
- // viewTblViewRecurring.layer.shadowOpacity = 0.3
1679
- // viewTblViewRecurring.layer.shadowOffset = CGSize(width: 0, height: 2)
1680
- // viewTblViewRecurring.layer.shadowRadius = 4
1681
- // viewTblViewRecurring.layer.cornerRadius = 8
1682
- // viewTblViewRecurring.layer.cornerRadius = 8
1683
- //
1684
- // viewTblViewRecurring.isHidden = true
1685
1634
  }
1686
1635
 
1687
1636
  @IBAction func actionBtnChosePlanCardField(_ sender: UIButton) {
1688
- // UIView.animate(withDuration: 0.3) {
1689
- // self.viewTblViewRecurring.isHidden.toggle()
1690
- // }
1691
-
1692
1637
  guard let plans = request?.recurringIntervals, !plans.isEmpty else {
1693
1638
  print("No recurring intervals available.")
1694
1639
  return
@@ -1930,58 +1875,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
1930
1875
  }
1931
1876
  }
1932
1877
 
1933
- // Redirect based on billing visibility
1934
- // if fieldSection.visibility.billing {
1935
- // // Instantiate BillingInfoVC and pass the selected card data and CVV text
1936
- // let billingInfoVC = UIStoryboard(name: "easymerchantsdk", bundle: .easyPayBundle).instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
1937
- //
1938
- // billingInfoVC.isFrom = "SavedCards"
1939
- // billingInfoVC.selectedCard = self.selectedCard // Passing the selected card data
1940
- // billingInfoVC.cvvText = cvvText // Passing the CVV text
1941
- // billingInfoVC.amount = Int(self.request.amount ?? 0)
1942
- // billingInfoVC.selectedPaymentMethod = self.selectedPaymentMethod
1943
- //
1944
- // if let billingInfoData = self.request.billingInfoData {
1945
- // billingInfoVC.billingInfoData = billingInfoData
1946
- // }
1947
- //
1948
- // billingInfoVC.request = self.request
1949
- // billingInfoVC.chosenPlan = self.txtFieldSelectPlanSingleSavedCard.text
1950
- // billingInfoVC.startDate = self.txtFieldSelectDateSingleSavedCard.text
1951
- //
1952
- // billingInfoVC.billingInfo = fieldSection.billing
1953
- // billingInfoVC.additionalInfo = fieldSection.additional
1954
- // billingInfoVC.visibility = fieldSection.visibility
1955
- //
1956
- // // Navigate to BillingInfoVC
1957
- // self.navigationController?.pushViewController(billingInfoVC, animated: true)
1958
- // }
1959
- // else {
1960
- // let additionalInfoVC = UIStoryboard(name: "easymerchantsdk", bundle: .easyPayBundle).instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
1961
- // additionalInfoVC.isFrom = "SavedCards"
1962
- // additionalInfoVC.selectedCard = self.selectedCard // Passing the selected card data
1963
- // additionalInfoVC.cvvText = cvvText // Passing the CVV text
1964
- // additionalInfoVC.amount = Int(self.request.amount ?? 0)
1965
- // additionalInfoVC.selectedPaymentMethod = self.selectedPaymentMethod
1966
- //
1967
- // if let billingInfoData = self.request.billingInfoData {
1968
- // additionalInfoVC.billingInfoData = billingInfoData
1969
- // }
1970
- //
1971
- // additionalInfoVC.request = self.request
1972
- // additionalInfoVC.chosenPlan = self.txtFieldSelectPlanSingleSavedCard.text
1973
- // additionalInfoVC.startDate = self.txtFieldSelectDateSingleSavedCard.text
1974
- //
1975
- // additionalInfoVC.billingInfo = fieldSection.billing
1976
- // additionalInfoVC.additionalInfo = fieldSection.additional
1977
- // additionalInfoVC.visibility = fieldSection.visibility
1978
- //
1979
- // self.navigationController?.pushViewController(additionalInfoVC, animated: true)
1980
- // }
1981
-
1982
1878
  let showBilling = fieldSection.visibility.billing
1983
1879
  let showAdditional = fieldSection.visibility.additional
1984
-
1880
+
1985
1881
  if !showBilling && !showAdditional {
1986
1882
  self.paymentIntentFromShowCardApi()
1987
1883
  }
@@ -2033,7 +1929,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2033
1929
 
2034
1930
  self.navigationController?.pushViewController(additionalInfoVC, animated: true)
2035
1931
  }
2036
-
2037
1932
  }
2038
1933
  }
2039
1934
  catch {
@@ -2066,7 +1961,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2066
1961
  }
2067
1962
  }
2068
1963
  }
2069
-
2070
1964
  // All validations passed, call the API
2071
1965
  paymentIntentFromShowSavedCardApi()
2072
1966
  }
@@ -2186,67 +2080,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2186
2080
  }
2187
2081
  }
2188
2082
 
2189
- // Redirect based on billing visibility
2190
- // if fieldSection.visibility.billing {
2191
- // // Instantiate BillingInfoVC and pass the card details
2192
- // let billingInfoVC = UIStoryboard(name: "easymerchantsdk", bundle: .easyPayBundle).instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
2193
- //
2194
- // // Pass the card details
2195
- // billingInfoVC.cardNumber = cardNumber
2196
- // billingInfoVC.expiryDate = expiryDate
2197
- // billingInfoVC.cvv = cvv
2198
- // billingInfoVC.nameOnCard = nameOnCard
2199
- // billingInfoVC.isSavedNewCard = self.isSavedNewCardForFuture
2200
- //
2201
- // billingInfoVC.isFrom = "AddNewCard"
2202
- // billingInfoVC.amount = Int(self.request.amount ?? 0)
2203
- // billingInfoVC.selectedPaymentMethod = self.selectedPaymentMethod
2204
- //
2205
- // if let billingInfoData = self.request.billingInfoData {
2206
- // billingInfoVC.billingInfoData = billingInfoData
2207
- // }
2208
- //
2209
- // billingInfoVC.request = self.request
2210
- // billingInfoVC.chosenPlan = self.txtFieldSelectPlanNewCardView.text
2211
- // billingInfoVC.startDate = self.txtFieldSelectDateNewCardView.text
2212
- //
2213
- // billingInfoVC.billingInfo = fieldSection.billing
2214
- // billingInfoVC.additionalInfo = fieldSection.additional
2215
- // billingInfoVC.visibility = fieldSection.visibility
2216
- //
2217
- // // Navigate to BillingInfoVC
2218
- // self.navigationController?.pushViewController(billingInfoVC, animated: true)
2219
- // }
2220
- // else {
2221
- // let additionalInfoVC = UIStoryboard(name: "easymerchantsdk", bundle: .easyPayBundle).instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
2222
- //
2223
- // // Pass the card details
2224
- // additionalInfoVC.cardNumber = cardNumber
2225
- // additionalInfoVC.expiryDate = expiryDate
2226
- // additionalInfoVC.cvv = cvv
2227
- // additionalInfoVC.nameOnCard = nameOnCard
2228
- // additionalInfoVC.isSavedNewCard = self.isSavedNewCardForFuture
2229
- //
2230
- // additionalInfoVC.isFrom = "AddNewCard"
2231
- // additionalInfoVC.amount = Int(self.request.amount ?? 0)
2232
- // additionalInfoVC.selectedPaymentMethod = self.selectedPaymentMethod
2233
- //
2234
- // if let billingInfoData = self.request.billingInfoData {
2235
- // additionalInfoVC.billingInfoData = billingInfoData
2236
- // }
2237
- //
2238
- // additionalInfoVC.request = self.request
2239
- // additionalInfoVC.chosenPlan = self.txtFieldSelectPlanNewCardView.text
2240
- // additionalInfoVC.startDate = self.txtFieldSelectDateNewCardView.text
2241
- //
2242
- // additionalInfoVC.billingInfo = fieldSection.billing
2243
- // additionalInfoVC.additionalInfo = fieldSection.additional
2244
- // additionalInfoVC.visibility = fieldSection.visibility
2245
- //
2246
- // self.navigationController?.pushViewController(additionalInfoVC, animated: true)
2247
- // }
2248
-
2249
-
2250
2083
  let showBilling = fieldSection.visibility.billing
2251
2084
  let showAdditional = fieldSection.visibility.additional
2252
2085
 
@@ -2766,52 +2599,12 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2766
2599
  let jsonDict = json as? [String: Any], !jsonDict.isEmpty {
2767
2600
  print("Billing Info Data: \(jsonDict)")
2768
2601
 
2769
- // Redirect based on billing visibility
2770
- // if fieldSection.visibility.billing {
2771
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
2772
- // vc.billingInfoData = billingInfoData
2773
- // vc.request = self.request
2774
- // vc.chosenPlan = self.txtFieldChosePlanGrailPayBankView.text
2775
- // vc.startDate = self.txtFieldSelectDateGrailPayBankView.text
2776
- // vc.selectedPaymentMethod = "GrailPay"
2777
- // vc.isSavedForFuture = self.isSavedForFuture
2778
- // vc.grailPayAccountID = self.grailPayAccountID
2779
- // vc.selectedGrailPayAccountType = self.selectedGrailPayAccountType
2780
- // vc.selectedGrailPayAccountName = self.selectedGrailPayAccountName
2781
- // vc.amount = self.amount
2782
- // vc.billingInfo = fieldSection.billing
2783
- // vc.additionalInfo = fieldSection.additional
2784
- // vc.visibility = fieldSection.visibility
2785
- // vc.easyPayDelegate = self.easyPayDelegate
2786
- // vc.userEmail = self.txtFieldEmailGrailPayView.text
2787
- // self.navigationController?.pushViewController(vc, animated: true)
2788
- // }
2789
- // else {
2790
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
2791
- // vc.billingInfoData = billingInfoData
2792
- // vc.request = self.request
2793
- // vc.chosenPlan = self.txtFieldChosePlanGrailPayBankView.text
2794
- // vc.startDate = self.txtFieldSelectDateGrailPayBankView.text
2795
- // vc.selectedPaymentMethod = "GrailPay"
2796
- // vc.isSavedForFuture = self.isSavedForFuture
2797
- // vc.grailPayAccountID = self.grailPayAccountID
2798
- // vc.selectedGrailPayAccountType = self.selectedGrailPayAccountType
2799
- // vc.selectedGrailPayAccountName = self.selectedGrailPayAccountName
2800
- // vc.amount = self.amount
2801
- // vc.billingInfo = fieldSection.billing
2802
- // vc.additionalInfo = fieldSection.additional
2803
- // vc.visibility = fieldSection.visibility
2804
- // vc.easyPayDelegate = self.easyPayDelegate
2805
- // vc.userEmail = self.txtFieldEmailGrailPayView.text
2806
- // self.navigationController?.pushViewController(vc, animated: true)
2807
- // }
2808
-
2809
2602
  let showBilling = fieldSection.visibility.billing
2810
2603
  let showAdditional = fieldSection.visibility.additional
2811
-
2604
+
2812
2605
  if !showBilling && !showAdditional {
2813
2606
  // Navigate directly to EmailVerificationVC
2814
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "EmailVerificationVC") as! EmailVerificationVC
2607
+ // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "EmailVerificationVC") as! EmailVerificationVC
2815
2608
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "OTPVerificationVC") as! OTPVerificationVC
2816
2609
  vc.easyPayDelegate = self.easyPayDelegate
2817
2610
  vc.grailPayAccountID = self.grailPayAccountID
@@ -2871,7 +2664,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2871
2664
  vc.userEmail = self.txtFieldEmailGrailPayView.text
2872
2665
  self.navigationController?.pushViewController(vc, animated: true)
2873
2666
  }
2874
-
2667
+
2875
2668
  }
2876
2669
  }
2877
2670
  }
@@ -2882,7 +2675,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2882
2675
  else {
2883
2676
  //If billing info is nil
2884
2677
  // Navigate to EmailVerificationVC directly
2885
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "EmailVerificationVC") as! EmailVerificationVC
2678
+ // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "EmailVerificationVC") as! EmailVerificationVC
2886
2679
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "OTPVerificationVC") as! OTPVerificationVC
2887
2680
  vc.easyPayDelegate = self.easyPayDelegate
2888
2681
  vc.grailPayAccountID = self.grailPayAccountID
@@ -2910,50 +2703,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
2910
2703
  let jsonDict = json as? [String: Any], !jsonDict.isEmpty {
2911
2704
  print("Billing Info Data: \(jsonDict)")
2912
2705
 
2913
- // Redirect based on billing visibility
2914
- // if fieldSection.visibility.billing {
2915
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
2916
- // vc.billingInfoData = billingInfoData
2917
- // vc.request = self.request
2918
- // vc.chosenPlan = self.txtFieldChosePlanGrailPayBankView.text
2919
- // vc.startDate = self.txtFieldSelectDateGrailPayBankView.text
2920
- // vc.selectedPaymentMethod = "GrailPay"
2921
- // vc.isSavedForFuture = self.isSavedForFuture
2922
- // vc.grailPayAccountID = self.grailPayAccountID
2923
- // vc.selectedGrailPayAccountType = self.selectedGrailPayAccountType
2924
- // vc.selectedGrailPayAccountName = self.selectedGrailPayAccountName
2925
- // vc.amount = self.amount
2926
- // vc.billingInfo = fieldSection.billing
2927
- // vc.additionalInfo = fieldSection.additional
2928
- // vc.visibility = fieldSection.visibility
2929
- // vc.easyPayDelegate = self.easyPayDelegate
2930
- // vc.userEmail = self.txtFieldEmailGrailPayView.text
2931
- // self.navigationController?.pushViewController(vc, animated: true)
2932
- // }
2933
- // else {
2934
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
2935
- // vc.billingInfoData = billingInfoData
2936
- // vc.request = self.request
2937
- // vc.chosenPlan = self.txtFieldChosePlanGrailPayBankView.text
2938
- // vc.startDate = self.txtFieldSelectDateGrailPayBankView.text
2939
- // vc.selectedPaymentMethod = "GrailPay"
2940
- // vc.isSavedForFuture = self.isSavedForFuture
2941
- // vc.grailPayAccountID = self.grailPayAccountID
2942
- // vc.selectedGrailPayAccountType = self.selectedGrailPayAccountType
2943
- // vc.selectedGrailPayAccountName = self.selectedGrailPayAccountName
2944
- // vc.amount = self.amount
2945
- // vc.billingInfo = fieldSection.billing
2946
- // vc.additionalInfo = fieldSection.additional
2947
- // vc.visibility = fieldSection.visibility
2948
- // vc.easyPayDelegate = self.easyPayDelegate
2949
- // vc.userEmail = self.txtFieldEmailGrailPayView.text
2950
- // self.navigationController?.pushViewController(vc, animated: true)
2951
- // }
2952
-
2953
-
2954
2706
  let showBilling = fieldSection.visibility.billing
2955
2707
  let showAdditional = fieldSection.visibility.additional
2956
-
2708
+
2957
2709
  if !showBilling && !showAdditional {
2958
2710
  self.grailPayAccountChargeApi()
2959
2711
  }
@@ -3051,48 +2803,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3051
2803
  let jsonDict = json as? [String: Any], !jsonDict.isEmpty {
3052
2804
  print("Billing Info Data: \(jsonDict)")
3053
2805
 
3054
- // Redirect based on billing visibility
3055
- // if fieldSection.visibility.billing {
3056
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
3057
- // vc.billingInfoData = billingInfoData
3058
- // vc.request = self.request
3059
- // vc.chosenPlan = self.txtFieldChosePlanNewGrailPayBankView.text
3060
- // vc.startDate = self.txtFieldSelectDateNewGrailPayBankView.text
3061
- // vc.selectedPaymentMethod = "NewGrailPayAccount"
3062
- // vc.isSavedForFuture = self.isSavedForFuture
3063
- // vc.grailPayAccountID = self.newGrailPayAccountID
3064
- // vc.selectedGrailPayAccountType = self.selectedNewGrailPayAccountType
3065
- // vc.selectedGrailPayAccountName = self.selectedNewGrailPayAccountName
3066
- // vc.amount = self.amount
3067
- // vc.billingInfo = fieldSection.billing
3068
- // vc.additionalInfo = fieldSection.additional
3069
- // vc.visibility = fieldSection.visibility
3070
- // vc.easyPayDelegate = self.easyPayDelegate
3071
- // self.navigationController?.pushViewController(vc, animated: true)
3072
- // }
3073
- // else {
3074
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
3075
- // vc.billingInfoData = billingInfoData
3076
- // vc.request = self.request
3077
- // vc.chosenPlan = self.txtFieldChosePlanNewGrailPayBankView.text
3078
- // vc.startDate = self.txtFieldSelectDateNewGrailPayBankView.text
3079
- // vc.selectedPaymentMethod = "NewGrailPayAccount"
3080
- // vc.isSavedForFuture = self.isSavedForFuture
3081
- // vc.grailPayAccountID = self.newGrailPayAccountID
3082
- // vc.selectedGrailPayAccountType = self.selectedNewGrailPayAccountType
3083
- // vc.selectedGrailPayAccountName = self.selectedNewGrailPayAccountName
3084
- // vc.amount = self.amount
3085
- // vc.billingInfo = fieldSection.billing
3086
- // vc.additionalInfo = fieldSection.additional
3087
- // vc.visibility = fieldSection.visibility
3088
- // vc.easyPayDelegate = self.easyPayDelegate
3089
- // self.navigationController?.pushViewController(vc, animated: true)
3090
- // }
3091
-
3092
-
3093
2806
  let showBilling = fieldSection.visibility.billing
3094
2807
  let showAdditional = fieldSection.visibility.additional
3095
-
2808
+
3096
2809
  if !showBilling && !showAdditional {
3097
2810
  self.grailPayNewAccountChargeApi()
3098
2811
  }
@@ -3156,47 +2869,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3156
2869
  let jsonDict = json as? [String: Any], !jsonDict.isEmpty {
3157
2870
  print("Billing Info Data: \(jsonDict)")
3158
2871
 
3159
- // Redirect based on billing visibility
3160
- // if fieldSection.visibility.billing {
3161
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
3162
- // vc.billingInfoData = billingInfoData
3163
- // vc.request = self.request
3164
- // vc.chosenPlan = self.txtFieldChosePlanNewGrailPayBankView.text
3165
- // vc.startDate = self.txtFieldSelectDateNewGrailPayBankView.text
3166
- // vc.selectedPaymentMethod = "NewGrailPayAccount"
3167
- // vc.isSavedForFuture = self.isSavedForFuture
3168
- // vc.grailPayAccountID = self.newGrailPayAccountID
3169
- // vc.selectedGrailPayAccountType = self.selectedNewGrailPayAccountType
3170
- // vc.selectedGrailPayAccountName = self.selectedNewGrailPayAccountName
3171
- // vc.amount = self.amount
3172
- // vc.billingInfo = fieldSection.billing
3173
- // vc.additionalInfo = fieldSection.additional
3174
- // vc.visibility = fieldSection.visibility
3175
- // vc.easyPayDelegate = self.easyPayDelegate
3176
- // self.navigationController?.pushViewController(vc, animated: true)
3177
- // }
3178
- // else {
3179
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
3180
- // vc.billingInfoData = billingInfoData
3181
- // vc.request = self.request
3182
- // vc.chosenPlan = self.txtFieldChosePlanNewGrailPayBankView.text
3183
- // vc.startDate = self.txtFieldSelectDateNewGrailPayBankView.text
3184
- // vc.selectedPaymentMethod = "NewGrailPayAccount"
3185
- // vc.isSavedForFuture = self.isSavedForFuture
3186
- // vc.grailPayAccountID = self.newGrailPayAccountID
3187
- // vc.selectedGrailPayAccountType = self.selectedNewGrailPayAccountType
3188
- // vc.selectedGrailPayAccountName = self.selectedNewGrailPayAccountName
3189
- // vc.amount = self.amount
3190
- // vc.billingInfo = fieldSection.billing
3191
- // vc.additionalInfo = fieldSection.additional
3192
- // vc.visibility = fieldSection.visibility
3193
- // vc.easyPayDelegate = self.easyPayDelegate
3194
- // self.navigationController?.pushViewController(vc, animated: true)
3195
- // }
3196
-
3197
2872
  let showBilling = fieldSection.visibility.billing
3198
2873
  let showAdditional = fieldSection.visibility.additional
3199
-
2874
+
3200
2875
  if !showBilling && !showAdditional {
3201
2876
  self.grailPayNewAccountChargeApi()
3202
2877
  }
@@ -3376,68 +3051,16 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3376
3051
  "email": UserStoreSingleton.shared.merchantEmail ?? ""
3377
3052
  ]
3378
3053
 
3379
- // if let billingInfoData = request.billingInfoData {
3380
- // do {
3381
- // let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
3382
- //
3383
- // // Process Billing Info if available and contains any non-empty value
3384
- // let billing = fieldSection.billing.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
3385
- // if !billing.isEmpty {
3386
- // var billingDict: [String: Any] = [:]
3387
- // billing.forEach { billingDict[$0.name] = $0.value }
3388
- //
3389
- // if let address = billingDict["address"] as? String { params["address"] = address }
3390
- // if let country = billingDict["country"] as? String { params["country"] = country }
3391
- // if let state = billingDict["state"] as? String { params["state"] = state }
3392
- // if let city = billingDict["city"] as? String { params["city"] = city }
3393
- // if let postalCode = billingDict["postal_code"] as? String { params["zip"] = postalCode }
3394
- // }
3395
- //
3396
- // // Process Additional Info if available and contains any non-empty value
3397
- // let additional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
3398
- // if !additional.isEmpty {
3399
- // var additionalDict: [String: Any] = [:]
3400
- // additional.forEach { additionalDict[$0.name] = $0.value }
3401
- //
3402
- // if let desc = additionalDict["description"] as? String {
3403
- // params["description"] = desc
3404
- // }
3405
- //
3406
- // if let phone = additionalDict["phone_number"] as? String {
3407
- // params["phone_number"] = phone
3408
- // }
3409
- // if let email = additionalDict["email"] as? String {
3410
- // params["email"] = email
3411
- // }
3412
- // if let name = additionalDict["name"] as? String {
3413
- // params["name"] = name
3414
- // }
3415
- // }
3416
- //
3417
- // // Set default description only if not already set
3418
- // if params["description"] == nil {
3419
- // params["description"] = "Hosted payment checkout"
3420
- // }
3421
- //
3422
- // } catch {
3423
- // print("Failed to decode FieldSection: \(error)")
3424
- // params["description"] = "Hosted payment checkout"
3425
- // }
3426
- // } else {
3427
- // params["description"] = "Hosted payment checkout"
3428
- // }
3429
-
3430
-
3431
3054
  if let billingInfoData = request.billingInfoData {
3432
3055
  do {
3433
3056
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
3434
-
3057
+
3435
3058
  // Billing Info
3436
3059
  let billing = fieldSection.billing
3437
3060
  if !billing.isEmpty {
3438
3061
  var billingDict: [String: Any] = [:]
3439
3062
  billing.forEach { billingDict[$0.name] = $0.value }
3440
-
3063
+
3441
3064
  if let address = billingDict["address"] as? String, !address.isEmpty {
3442
3065
  params["address"] = address
3443
3066
  }
@@ -3454,19 +3077,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3454
3077
  params["zip"] = postalCode
3455
3078
  }
3456
3079
  }
3457
-
3080
+
3458
3081
  // Additional Info
3459
3082
  let additional = fieldSection.additional
3460
3083
  if !additional.isEmpty {
3461
3084
  var additionalDict: [String: Any] = [:]
3462
3085
  additional.forEach { additionalDict[$0.name] = $0.value }
3463
-
3086
+
3464
3087
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
3465
3088
  params["description"] = desc
3466
3089
  } else {
3467
3090
  params["description"] = "Hosted payment checkout"
3468
3091
  }
3469
-
3092
+
3470
3093
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
3471
3094
  params["phone_number"] = phone
3472
3095
  }
@@ -3480,7 +3103,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3480
3103
  // If no description in additional info, set default
3481
3104
  params["description"] = "Hosted payment checkout"
3482
3105
  }
3483
-
3106
+
3484
3107
  } catch {
3485
3108
  print("Failed to decode FieldSection: \(error)")
3486
3109
  params["description"] = "Hosted payment checkout"
@@ -3644,13 +3267,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3644
3267
  if let billingInfoData = request.billingInfoData {
3645
3268
  do {
3646
3269
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
3647
-
3270
+
3648
3271
  // Billing Info
3649
3272
  let billing = fieldSection.billing
3650
3273
  if !billing.isEmpty {
3651
3274
  var billingDict: [String: Any] = [:]
3652
3275
  billing.forEach { billingDict[$0.name] = $0.value }
3653
-
3276
+
3654
3277
  if let address = billingDict["address"] as? String, !address.isEmpty {
3655
3278
  params["address"] = address
3656
3279
  }
@@ -3667,19 +3290,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3667
3290
  params["zip"] = postalCode
3668
3291
  }
3669
3292
  }
3670
-
3293
+
3671
3294
  // Additional Info
3672
3295
  let additional = fieldSection.additional
3673
3296
  if !additional.isEmpty {
3674
3297
  var additionalDict: [String: Any] = [:]
3675
3298
  additional.forEach { additionalDict[$0.name] = $0.value }
3676
-
3299
+
3677
3300
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
3678
3301
  params["description"] = desc
3679
3302
  } else {
3680
3303
  params["description"] = "Hosted payment checkout"
3681
3304
  }
3682
-
3305
+
3683
3306
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
3684
3307
  params["phone_number"] = phone
3685
3308
  }
@@ -3693,7 +3316,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3693
3316
  // If no description in additional info, set default
3694
3317
  params["description"] = "Hosted payment checkout"
3695
3318
  }
3696
-
3319
+
3697
3320
  } catch {
3698
3321
  print("Failed to decode FieldSection: \(error)")
3699
3322
  params["description"] = "Hosted payment checkout"
@@ -3774,31 +3397,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3774
3397
  // Pass the selected payment method
3775
3398
  paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
3776
3399
  paymentDoneVC.easyPayDelegate = self.easyPayDelegate
3777
- // // Pass billingInfo and additionalInfo
3778
- // if let billingData = self.request.billingInfoData,
3779
- // let billingInfoDict = try? JSONSerialization.jsonObject(with: billingData, options: []) as? [String: Any] {
3780
- //
3781
- // // Extract main billing fields
3782
- // let cleanBillingInfo: [String: Any] = [
3783
- // "postal_code": billingInfoDict["postal_code"] ?? "",
3784
- // "country": billingInfoDict["country"] ?? "",
3785
- // "city": billingInfoDict["city"] ?? "",
3786
- // "address": billingInfoDict["address"] ?? "",
3787
- // "state": billingInfoDict["state"] ?? ""
3788
- // ]
3789
- // paymentDoneVC.billingInfo = cleanBillingInfo
3790
- //
3791
- // // Extract additional_info
3792
- // if let additional = billingInfoDict["additional_info"] as? [String: Any] {
3793
- // let cleanAdditionalInfo: [String: Any] = [
3794
- // "email": additional["email"] ?? "",
3795
- // "phone_number": additional["phone_number"] ?? "",
3796
- // "name": additional["name"] ?? "",
3797
- // "country_code": additional["country_code"] ?? ""
3798
- // ]
3799
- // paymentDoneVC.additionalInfo = cleanAdditionalInfo
3800
- // }
3801
- // }
3802
3400
 
3803
3401
  // Pass billing info and additional info if available
3804
3402
  if let billingInfoData = self.request.billingInfoData,
@@ -3877,13 +3475,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3877
3475
  if let billingInfoData = request.billingInfoData {
3878
3476
  do {
3879
3477
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
3880
-
3478
+
3881
3479
  // Billing Info
3882
3480
  let billing = fieldSection.billing
3883
3481
  if !billing.isEmpty {
3884
3482
  var billingDict: [String: Any] = [:]
3885
3483
  billing.forEach { billingDict[$0.name] = $0.value }
3886
-
3484
+
3887
3485
  if let address = billingDict["address"] as? String, !address.isEmpty {
3888
3486
  params["address"] = address
3889
3487
  }
@@ -3900,19 +3498,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3900
3498
  params["zip"] = postalCode
3901
3499
  }
3902
3500
  }
3903
-
3501
+
3904
3502
  // Additional Info
3905
3503
  let additional = fieldSection.additional
3906
3504
  if !additional.isEmpty {
3907
3505
  var additionalDict: [String: Any] = [:]
3908
3506
  additional.forEach { additionalDict[$0.name] = $0.value }
3909
-
3507
+
3910
3508
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
3911
3509
  params["description"] = desc
3912
3510
  } else {
3913
3511
  params["description"] = "Hosted payment checkout"
3914
3512
  }
3915
-
3513
+
3916
3514
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
3917
3515
  params["phone_number"] = phone
3918
3516
  }
@@ -3926,7 +3524,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
3926
3524
  // If no description in additional info, set default
3927
3525
  params["description"] = "Hosted payment checkout"
3928
3526
  }
3929
-
3527
+
3930
3528
  } catch {
3931
3529
  print("Failed to decode FieldSection: \(error)")
3932
3530
  params["description"] = "Hosted payment checkout"
@@ -4132,51 +3730,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4132
3730
  }
4133
3731
  }
4134
3732
 
4135
- // // Redirect based on billing visibility
4136
- // if fieldSection.visibility.billing {
4137
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
4138
- // vc.cardNumber = cardNumber
4139
- // vc.expiryDate = expiryDate
4140
- // vc.cvv = cvv
4141
- // vc.nameOnCard = cardName
4142
- // vc.selectedPaymentMethod = self.selectedPaymentMethod
4143
- // vc.isSavedForFuture = self.isSavedForFuture
4144
- // vc.request = self.request
4145
- // vc.chosenPlan = self.txtFieldChosePlanCard.text
4146
- // vc.startDate = self.txtFieldStartDateCard.text
4147
- // vc.userEmail = self.txtFieldEmailCardView.text
4148
- // vc.amount = self.amount
4149
- // vc.billingInfoData = billingInfoData
4150
- // vc.billingInfo = fieldSection.billing
4151
- // vc.additionalInfo = fieldSection.additional
4152
- // vc.visibility = fieldSection.visibility
4153
- // vc.easyPayDelegate = self.easyPayDelegate
4154
- // self.navigationController?.pushViewController(vc, animated: true)
4155
- // } else {
4156
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
4157
- // vc.billingInfoData = billingInfoData
4158
- // vc.cardNumber = cardNumber
4159
- // vc.expiryDate = expiryDate
4160
- // vc.cvv = cvv
4161
- // vc.nameOnCard = cardName
4162
- // vc.selectedPaymentMethod = self.selectedPaymentMethod
4163
- // vc.isSavedForFuture = self.isSavedForFuture
4164
- // vc.request = self.request
4165
- // vc.chosenPlan = self.txtFieldChosePlanCard.text
4166
- // vc.startDate = self.txtFieldStartDateCard.text
4167
- // vc.userEmail = self.txtFieldEmailCardView.text
4168
- // vc.billingInfo = fieldSection.billing
4169
- // vc.additionalInfo = fieldSection.additional
4170
- // vc.amount = self.amount
4171
- // vc.visibility = fieldSection.visibility
4172
- // vc.easyPayDelegate = self.easyPayDelegate
4173
- // self.navigationController?.pushViewController(vc, animated: true)
4174
- // }
4175
-
4176
-
4177
3733
  let showBilling = fieldSection.visibility.billing
4178
3734
  let showAdditional = fieldSection.visibility.additional
4179
-
3735
+
4180
3736
  if !showBilling && !showAdditional {
4181
3737
  if self.isSavedForFuture {
4182
3738
  self.navigateCardDataToEmailVerificationVC()
@@ -4289,9 +3845,18 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4289
3845
  }
4290
3846
  }
4291
3847
 
4292
- // Redirect based on billing visibility
4293
- if fieldSection.visibility.billing {
4294
- // Proceed to BillingInfoVC
3848
+ let showBilling = fieldSection.visibility.billing
3849
+ let showAdditional = fieldSection.visibility.additional
3850
+
3851
+ if !showBilling && !showAdditional {
3852
+ if self.isSavedForFuture {
3853
+ self.navigateBankDataToEmailVerificationVC()
3854
+ } else {
3855
+ self.accountBankChargeApi()
3856
+ }
3857
+ }
3858
+ else if showBilling {
3859
+ // Push to BillingInfoVC
4295
3860
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
4296
3861
  vc.accountName = self.txtFieldAccountName.text
4297
3862
  vc.routingNumber = self.txtFieldRoutingNumber.text
@@ -4314,6 +3879,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4314
3879
  self.navigationController?.pushViewController(vc, animated: true)
4315
3880
  }
4316
3881
  else {
3882
+ // Push to AdditionalInfoVC
4317
3883
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
4318
3884
  vc.accountName = self.txtFieldAccountName.text
4319
3885
  vc.routingNumber = self.txtFieldRoutingNumber.text
@@ -4517,7 +4083,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4517
4083
 
4518
4084
  // Function to navigate to EmailVerificationVC
4519
4085
  func navigateCardDataToEmailVerificationVC() {
4520
- // if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
4086
+ // if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
4521
4087
  if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "OTPVerificationVC") as? OTPVerificationVC {
4522
4088
  if let billingInfoData = request.billingInfoData {
4523
4089
  do {
@@ -4549,9 +4115,10 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4549
4115
  self.navigationController?.pushViewController(emailVerificationVC, animated: true)
4550
4116
  }
4551
4117
  }
4552
-
4118
+
4553
4119
  func navigateBankDataToEmailVerificationVC() {
4554
- if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
4120
+ // if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
4121
+ if let emailVerificationVC = storyboard?.instantiateViewController(withIdentifier: "OTPVerificationVC") as? OTPVerificationVC {
4555
4122
  if let billingInfoData = request.billingInfoData {
4556
4123
  do {
4557
4124
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
@@ -4600,10 +4167,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4600
4167
  if selectedPaymentMethod == "Card" {
4601
4168
  self.viewSingleSavedAccount.isHidden = true
4602
4169
  self.viewBankFields.isHidden = true
4603
- // self.viewBtnShowSavedCards.isHidden = false
4604
- // self.lblBtnShowSaveCard.text = "Show Saved Cards"
4605
- // self.viewBtnShowSavedCardHeight.constant = 50
4606
- // self.viewBtnShowSavedCardTopCon.constant = 20
4607
4170
 
4608
4171
  if request.saveCard == false {
4609
4172
  self.viewBtnShowSavedCards.isHidden = true
@@ -4632,10 +4195,6 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4632
4195
  }
4633
4196
  else if selectedPaymentMethod == "Bank" {
4634
4197
  self.viewBankFields.isHidden = false
4635
- // self.viewBtnShowSavedCards.isHidden = false
4636
- // self.lblBtnShowSaveCard.text = "Show Saved Accounts"
4637
- // self.viewBtnShowSavedCardHeight.constant = 50
4638
- // self.viewBtnShowSavedCardTopCon.constant = 20
4639
4198
 
4640
4199
  if request.saveAccount == false {
4641
4200
  self.viewBtnShowSavedCards.isHidden = true
@@ -4823,50 +4382,15 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
4823
4382
  return
4824
4383
  }
4825
4384
 
4826
- // // Redirect based on billing visibility
4827
- // if fieldSection.visibility.billing {
4828
- // // Proceed with the Pay Now action
4829
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
4830
- // // Pass the customer_id and account_id to BillingInfoVC
4831
- // vc.customerID = self.selectedbankAccounts?.customer_id
4832
- // vc.accountID = self.selectedbankAccounts?.account_id
4833
- // vc.billingInfoData = billingInfoData
4834
- // vc.isFrom = "SavedBank"
4835
- // vc.selectedPaymentMethod = "Bank"
4836
- // vc.chosenPlan = self.txtFieldSelectPlanSingleSavedBankView.text
4837
- // vc.startDate = self.txtFieldSelectDateSingleSavedBankView.text
4838
- // vc.request = self.request
4839
- // vc.amount = self.amount
4840
- // vc.billingInfo = fieldSection.billing
4841
- // vc.additionalInfo = fieldSection.additional
4842
- // vc.visibility = fieldSection.visibility
4843
- // vc.easyPayDelegate = self.easyPayDelegate
4844
- // self.navigationController?.pushViewController(vc, animated: true)
4845
- // }
4846
- // else {
4847
- // let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
4848
- // vc.customerID = self.selectedbankAccounts?.customer_id
4849
- // vc.accountID = self.selectedbankAccounts?.account_id
4850
- // vc.billingInfoData = billingInfoData
4851
- // vc.isFrom = "SavedBank"
4852
- // vc.selectedPaymentMethod = "Bank"
4853
- // vc.chosenPlan = self.txtFieldSelectPlanSingleSavedBankView.text
4854
- // vc.startDate = self.txtFieldSelectDateSingleSavedBankView.text
4855
- // vc.request = self.request
4856
- // vc.amount = self.amount
4857
- // vc.billingInfo = fieldSection.billing
4858
- // vc.additionalInfo = fieldSection.additional
4859
- // vc.visibility = fieldSection.visibility
4860
- // vc.easyPayDelegate = self.easyPayDelegate
4861
- // self.navigationController?.pushViewController(vc, animated: true)
4862
- // }
4863
-
4864
-
4865
4385
  let showBilling = fieldSection.visibility.billing
4866
4386
  let showAdditional = fieldSection.visibility.additional
4867
-
4387
+
4868
4388
  if !showBilling && !showAdditional {
4869
- self.grailPayAaccountChargeSingleSavedAccountApi()
4389
+ if self.request.authenticatedACH == true {
4390
+ self.grailPayAaccountChargeSingleSavedAccountApi()
4391
+ } else {
4392
+ self.accountBankChargeSavedBankAccountApi()
4393
+ }
4870
4394
  }
4871
4395
  else if showBilling {
4872
4396
  // Push to BillingInfoVC
@@ -5015,9 +4539,14 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
5015
4539
  let isSavedNewAccount = self.isSavedNewAccount
5016
4540
  let isFromValue = isSavedNewAccount ? "AddNewAccountWithSave" : "AddNewAccountWithoutSave"
5017
4541
 
5018
- // Redirect based on billing visibility
5019
- if fieldSection.visibility.billing {
5020
- // Proceed with the Pay Now action
4542
+ let showBilling = fieldSection.visibility.billing
4543
+ let showAdditional = fieldSection.visibility.additional
4544
+
4545
+ if !showBilling && !showAdditional {
4546
+ self.accountBankChargeAddNewAccountApi()
4547
+ }
4548
+ else if showBilling {
4549
+ // Push to BillingInfoVC
5021
4550
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "BillingInfoVC") as! BillingInfoVC
5022
4551
  vc.accountName = accountName
5023
4552
  vc.routingNumber = routingNumber
@@ -5040,6 +4569,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
5040
4569
  self.navigationController?.pushViewController(vc, animated: true)
5041
4570
  }
5042
4571
  else {
4572
+ // Push to AdditionalInfoVC
5043
4573
  let vc = easymerchantsdk.instantiateViewController(withIdentifier: "AdditionalInfoVC") as! AdditionalInfoVC
5044
4574
  vc.accountName = accountName
5045
4575
  vc.routingNumber = routingNumber
@@ -5867,13 +5397,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
5867
5397
  if let billingInfoData = request.billingInfoData {
5868
5398
  do {
5869
5399
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
5870
-
5400
+
5871
5401
  // Billing Info
5872
5402
  let billing = fieldSection.billing
5873
5403
  if !billing.isEmpty {
5874
5404
  var billingDict: [String: Any] = [:]
5875
5405
  billing.forEach { billingDict[$0.name] = $0.value }
5876
-
5406
+
5877
5407
  if let address = billingDict["address"] as? String, !address.isEmpty {
5878
5408
  params["address"] = address
5879
5409
  }
@@ -5890,19 +5420,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
5890
5420
  params["zip"] = postalCode
5891
5421
  }
5892
5422
  }
5893
-
5423
+
5894
5424
  // Additional Info
5895
5425
  let additional = fieldSection.additional
5896
5426
  if !additional.isEmpty {
5897
5427
  var additionalDict: [String: Any] = [:]
5898
5428
  additional.forEach { additionalDict[$0.name] = $0.value }
5899
-
5429
+
5900
5430
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
5901
5431
  params["description"] = desc
5902
5432
  } else {
5903
5433
  params["description"] = "Hosted payment checkout"
5904
5434
  }
5905
-
5435
+
5906
5436
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
5907
5437
  params["phone_number"] = phone
5908
5438
  }
@@ -5916,7 +5446,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
5916
5446
  // If no description in additional info, set default
5917
5447
  params["description"] = "Hosted payment checkout"
5918
5448
  }
5919
-
5449
+
5920
5450
  } catch {
5921
5451
  print("Failed to decode FieldSection: \(error)")
5922
5452
  params["description"] = "Hosted payment checkout"
@@ -6007,7 +5537,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6007
5537
  var billingDict: [String: Any] = [:]
6008
5538
  filteredBilling.forEach { billingDict[$0.name] = $0.value }
6009
5539
  paymentDoneVC.billingInfo = billingDict
6010
-
5540
+
6011
5541
  // Filter additional info: only include non-empty values
6012
5542
  let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
6013
5543
  paymentDoneVC.additionalInfoData = filteredAdditional
@@ -6234,13 +5764,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6234
5764
  if let billingInfoData = request.billingInfoData {
6235
5765
  do {
6236
5766
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
6237
-
5767
+
6238
5768
  // Billing Info
6239
5769
  let billing = fieldSection.billing
6240
5770
  if !billing.isEmpty {
6241
5771
  var billingDict: [String: Any] = [:]
6242
5772
  billing.forEach { billingDict[$0.name] = $0.value }
6243
-
5773
+
6244
5774
  if let address = billingDict["address"] as? String, !address.isEmpty {
6245
5775
  params["address"] = address
6246
5776
  }
@@ -6257,19 +5787,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6257
5787
  params["zip"] = postalCode
6258
5788
  }
6259
5789
  }
6260
-
5790
+
6261
5791
  // Additional Info
6262
5792
  let additional = fieldSection.additional
6263
5793
  if !additional.isEmpty {
6264
5794
  var additionalDict: [String: Any] = [:]
6265
5795
  additional.forEach { additionalDict[$0.name] = $0.value }
6266
-
5796
+
6267
5797
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
6268
5798
  params["description"] = desc
6269
5799
  } else {
6270
5800
  params["description"] = "Hosted payment checkout"
6271
5801
  }
6272
-
5802
+
6273
5803
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
6274
5804
  params["phone_number"] = phone
6275
5805
  }
@@ -6283,7 +5813,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6283
5813
  // If no description in additional info, set default
6284
5814
  params["description"] = "Hosted payment checkout"
6285
5815
  }
6286
-
5816
+
6287
5817
  } catch {
6288
5818
  print("Failed to decode FieldSection: \(error)")
6289
5819
  params["description"] = "Hosted payment checkout"
@@ -6371,7 +5901,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6371
5901
  var billingDict: [String: Any] = [:]
6372
5902
  filteredBilling.forEach { billingDict[$0.name] = $0.value }
6373
5903
  paymentDoneVC.billingInfo = billingDict
6374
-
5904
+
6375
5905
  // Filter additional info: only include non-empty values
6376
5906
  let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
6377
5907
  paymentDoneVC.additionalInfoData = filteredAdditional
@@ -6698,13 +6228,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6698
6228
  if let billingInfoData = request.billingInfoData {
6699
6229
  do {
6700
6230
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
6701
-
6231
+
6702
6232
  // Billing Info
6703
6233
  let billing = fieldSection.billing
6704
6234
  if !billing.isEmpty {
6705
6235
  var billingDict: [String: Any] = [:]
6706
6236
  billing.forEach { billingDict[$0.name] = $0.value }
6707
-
6237
+
6708
6238
  if let address = billingDict["address"] as? String, !address.isEmpty {
6709
6239
  params["address"] = address
6710
6240
  }
@@ -6721,19 +6251,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6721
6251
  params["zip"] = postalCode
6722
6252
  }
6723
6253
  }
6724
-
6254
+
6725
6255
  // Additional Info
6726
6256
  let additional = fieldSection.additional
6727
6257
  if !additional.isEmpty {
6728
6258
  var additionalDict: [String: Any] = [:]
6729
6259
  additional.forEach { additionalDict[$0.name] = $0.value }
6730
-
6260
+
6731
6261
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
6732
6262
  params["description"] = desc
6733
6263
  } else {
6734
6264
  params["description"] = "Hosted payment checkout"
6735
6265
  }
6736
-
6266
+
6737
6267
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
6738
6268
  params["phone_number"] = phone
6739
6269
  }
@@ -6747,7 +6277,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6747
6277
  // If no description in additional info, set default
6748
6278
  params["description"] = "Hosted payment checkout"
6749
6279
  }
6750
-
6280
+
6751
6281
  } catch {
6752
6282
  print("Failed to decode FieldSection: \(error)")
6753
6283
  params["description"] = "Hosted payment checkout"
@@ -6845,7 +6375,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
6845
6375
  var billingDict: [String: Any] = [:]
6846
6376
  filteredBilling.forEach { billingDict[$0.name] = $0.value }
6847
6377
  paymentDoneVC.billingInfo = billingDict
6848
-
6378
+
6849
6379
  // Filter additional info: only include non-empty values
6850
6380
  let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
6851
6381
  paymentDoneVC.additionalInfoData = filteredAdditional
@@ -7042,11 +6572,12 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7042
6572
  task.resume()
7043
6573
  }
7044
6574
 
7045
- //MARK: - Delete Cards Api.
6575
+ // MARK: - Delete Card API
7046
6576
  func deleteCardApi(cardID: String, at index: Int) {
7047
6577
  showLoadingIndicator()
7048
6578
 
7049
- let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.getCards.path()+"/\(cardID)"
6579
+ let endpoint = EnvironmentConfig.Endpoints.getCards.path()
6580
+ let fullURL = EnvironmentConfig.baseURL + "\(endpoint)/\(cardID)"
7050
6581
 
7051
6582
  guard let serviceURL = URL(string: fullURL) else {
7052
6583
  print("Invalid URL")
@@ -7058,68 +6589,70 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7058
6589
  request.httpMethod = "DELETE"
7059
6590
  request.addValue("application/json", forHTTPHeaderField: "Content-Type")
7060
6591
 
7061
- let token = UserStoreSingleton.shared.customerToken
7062
- print("Setting customerToken header: \(token ?? "None")")
7063
- request.addValue(token ?? "", forHTTPHeaderField: "Customer-Token")
6592
+ // Add Customer-Token
6593
+ if let token = UserStoreSingleton.shared.customerToken {
6594
+ request.addValue(token, forHTTPHeaderField: "Customer-Token")
6595
+ } else {
6596
+ print("Customer-Token is nil")
6597
+ }
7064
6598
 
7065
6599
  // Add API headers
7066
- if let apiKey = EnvironmentConfig.apiKey,
7067
- let apiSecret = EnvironmentConfig.apiSecret {
6600
+ if let apiKey = EnvironmentConfig.apiKey {
7068
6601
  request.addValue(apiKey, forHTTPHeaderField: "x-api-key")
6602
+ }
6603
+ if let apiSecret = EnvironmentConfig.apiSecret {
7069
6604
  request.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
7070
6605
  }
7071
6606
 
7072
6607
  let session = URLSession.shared
7073
- let task = session.dataTask(with: request) { [weak self] (serviceData, serviceResponse, error) in
6608
+ let task = session.dataTask(with: request) { [weak self] data, response, error in
7074
6609
  guard let self = self else { return }
7075
6610
 
7076
6611
  DispatchQueue.main.async {
7077
- self.hideLoadingIndicator() // Stop loader when response is received
6612
+ self.hideLoadingIndicator()
7078
6613
  }
7079
6614
 
7080
6615
  if let error = error {
7081
6616
  DispatchQueue.main.async {
7082
- self.presentPaymentErrorVC(errorMessage: error.localizedDescription)
6617
+ self.presentPaymentErrorVC(errorMessage: "Request failed: \(error.localizedDescription)")
7083
6618
  }
7084
6619
  return
7085
6620
  }
7086
6621
 
7087
- guard let httpResponse = serviceResponse as? HTTPURLResponse else {
6622
+ guard let httpResponse = response as? HTTPURLResponse else {
7088
6623
  DispatchQueue.main.async {
7089
- self.presentPaymentErrorVC(errorMessage: "Invalid response")
6624
+ self.presentPaymentErrorVC(errorMessage: "Invalid server response")
7090
6625
  }
7091
6626
  return
7092
6627
  }
7093
6628
 
7094
- if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
7095
-
7096
- if let data = serviceData {
6629
+ if (200...299).contains(httpResponse.statusCode) {
6630
+ if let data = data {
7097
6631
  do {
7098
- // Try to parse the data as JSON
7099
- if let jsonResponse = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
7100
- let message = jsonResponse["message"] as? String {
6632
+ if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any],
6633
+ let message = json["message"] as? String {
7101
6634
  DispatchQueue.main.async {
7102
6635
  self.showToast(message: message)
6636
+ // Optionally, remove the card from list at `index`
7103
6637
  }
7104
6638
  }
7105
- } catch let jsonError {
7106
- print("Error parsing JSON response: \(jsonError.localizedDescription)")
6639
+ } catch {
6640
+ print("JSON parsing error: \(error)")
7107
6641
  }
7108
- } else {
7109
- print("No data received.")
7110
6642
  }
7111
6643
  } else {
7112
6644
  DispatchQueue.main.async {
7113
- if let data = serviceData,
7114
- let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
7115
- let message = responseObj["message"] as? String {
6645
+ if let data = data,
6646
+ let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
6647
+ let message = json["message"] as? String {
7116
6648
  self.presentPaymentErrorVC(errorMessage: message)
7117
6649
  } else {
7118
- self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
6650
+ self.presentPaymentErrorVC(errorMessage: "Failed with status: \(httpResponse.statusCode)")
7119
6651
  }
7120
6652
  }
7121
6653
  }
7122
6654
  }
6655
+
7123
6656
  task.resume()
7124
6657
  }
7125
6658
 
@@ -7438,10 +6971,9 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7438
6971
  task.resume()
7439
6972
  }
7440
6973
 
7441
- //MARK: - Banking Account Charge Api from Regular saved bank account if Billing info is nil
7442
- func accountChargeSavedBankAccountApi() {
6974
+ //MARK: - Banking Account Charge Api If Billing info is availalbe but their visibility is false
6975
+ func accountBankChargeApi() {
7443
6976
  showLoadingIndicator()
7444
-
7445
6977
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
7446
6978
 
7447
6979
  guard let serviceURL = URL(string: fullURL) else {
@@ -7466,35 +6998,629 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7466
6998
  }
7467
6999
 
7468
7000
  var params: [String: Any] = [
7469
- "account_id": selectedbankAccounts?.account_id ?? "",
7470
- "customer": selectedbankAccounts?.customer_id ?? "",
7471
- "payment_method": "ach",
7472
- "description": "Test Description",
7001
+ "name": txtFieldAccountName.text ?? "",
7002
+ "email": "test@gmail.com",
7003
+ "description": "TestDescription",
7473
7004
  "currency": "usd",
7005
+ "account_type": txtFieldAccountType.text?.lowercased() ?? "",
7006
+ "routing_number": txtFieldRoutingNumber.text?.replacingOccurrences(of: " ", with: "") ?? "",
7007
+ "account_number": txtFieldAccountNumber.text?.replacingOccurrences(of: " ", with: "") ?? "",
7008
+ "payment_mode": "auth_and_capture",
7009
+ "payment_intent": UserStoreSingleton.shared.paymentIntent ?? "",
7010
+ "levelIndicator": 1,
7474
7011
  ]
7475
7012
 
7476
- // Add these if recurring is enabled
7477
- if let req = request, req.is_recurring == true {
7478
- if let recurringType = req.recurringStartDateType, recurringType == .custom {
7479
- // Only send start_date if type is .custom and field is not empty
7480
- if let startDateText = txtFieldSelectDateSingleSavedBankView?.text, !startDateText.isEmpty {
7481
- let inputFormatter = DateFormatter()
7482
- inputFormatter.dateFormat = "dd/MM/yyyy"
7483
-
7484
- let outputFormatter = DateFormatter()
7485
- outputFormatter.dateFormat = "MM/dd/yyyy"
7013
+ if let billingInfoData = request.billingInfoData {
7014
+ do {
7015
+ let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
7016
+
7017
+ // Billing Info
7018
+ let billing = fieldSection.billing
7019
+ if !billing.isEmpty {
7020
+ var billingDict: [String: Any] = [:]
7021
+ billing.forEach { billingDict[$0.name] = $0.value }
7486
7022
 
7487
- if let date = inputFormatter.date(from: startDateText) {
7488
- let apiFormattedDate = outputFormatter.string(from: date)
7489
- params["start_date"] = apiFormattedDate
7490
- } else {
7491
- print("Invalid date format in startDateText")
7023
+ if let address = billingDict["address"] as? String, !address.isEmpty {
7024
+ params["address"] = address
7025
+ }
7026
+ if let country = billingDict["country"] as? String, !country.isEmpty {
7027
+ params["country"] = country
7028
+ }
7029
+ if let state = billingDict["state"] as? String, !state.isEmpty {
7030
+ params["state"] = state
7031
+ }
7032
+ if let city = billingDict["city"] as? String, !city.isEmpty {
7033
+ params["city"] = city
7034
+ }
7035
+ if let postalCode = billingDict["postal_code"] as? String, !postalCode.isEmpty {
7036
+ params["zip"] = postalCode
7492
7037
  }
7493
7038
  }
7494
- }
7495
-
7496
- params["interval"] = txtFieldSelectPlanSingleSavedBankView.text.lowercased()
7497
- }
7039
+
7040
+ // Additional Info
7041
+ let additional = fieldSection.additional
7042
+ if !additional.isEmpty {
7043
+ var additionalDict: [String: Any] = [:]
7044
+ additional.forEach { additionalDict[$0.name] = $0.value }
7045
+
7046
+ if let desc = additionalDict["description"] as? String, !desc.isEmpty {
7047
+ params["description"] = desc
7048
+ } else {
7049
+ params["description"] = "Hosted payment checkout"
7050
+ }
7051
+
7052
+ if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
7053
+ params["phone_number"] = phone
7054
+ }
7055
+ if let email = additionalDict["email"] as? String, !email.isEmpty {
7056
+ params["email"] = email
7057
+ }
7058
+ if let name = additionalDict["name"] as? String, !name.isEmpty {
7059
+ params["name"] = name
7060
+ }
7061
+ } else {
7062
+ // If no description in additional info, set default
7063
+ params["description"] = "Hosted payment checkout"
7064
+ }
7065
+
7066
+ } catch {
7067
+ print("Failed to decode FieldSection: \(error)")
7068
+ params["description"] = "Hosted payment checkout"
7069
+ }
7070
+ } else {
7071
+ // Fallback if billingInfoData is missing
7072
+ params["description"] = "Hosted payment checkout"
7073
+ }
7074
+
7075
+ // Add these if recurring is enabled
7076
+ if let req = request, req.is_recurring == true {
7077
+ if let recurringType = req.recurringStartDateType, recurringType == .custom {
7078
+ // Only send start_date if type is .custom and field is not empty
7079
+ if let startDateText = txtFieldSelectDateViewBankFields?.text, !startDateText.isEmpty {
7080
+ let inputFormatter = DateFormatter()
7081
+ inputFormatter.dateFormat = "dd/MM/yyyy"
7082
+
7083
+ let outputFormatter = DateFormatter()
7084
+ outputFormatter.dateFormat = "MM/dd/yyyy"
7085
+
7086
+ if let date = inputFormatter.date(from: startDateText) {
7087
+ let apiFormattedDate = outputFormatter.string(from: date)
7088
+ params["start_date"] = apiFormattedDate
7089
+ } else {
7090
+ print("Invalid date format in startDateText")
7091
+ }
7092
+ }
7093
+ }
7094
+
7095
+ params["interval"] = txtFieldSelectPlanViewBankFields.text.lowercased()
7096
+ }
7097
+
7098
+ do {
7099
+ let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
7100
+ uRLRequest.httpBody = jsonData
7101
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
7102
+ print("JSON Payload: \(jsonString)")
7103
+ }
7104
+ } catch let error {
7105
+ print("Error creating JSON data: \(error)")
7106
+ hideLoadingIndicator()
7107
+ return
7108
+ }
7109
+
7110
+ let session = URLSession.shared
7111
+ let task = session.dataTask(with: uRLRequest) { (serviceData, serviceResponse, error) in
7112
+
7113
+ DispatchQueue.main.async {
7114
+ self.hideLoadingIndicator() // Stop loader when response is received
7115
+ }
7116
+
7117
+ if let error = error {
7118
+ print("Error: \(error.localizedDescription)")
7119
+ return
7120
+ }
7121
+
7122
+ guard let httpResponse = serviceResponse as? HTTPURLResponse else {
7123
+ print("Invalid response")
7124
+ return
7125
+ }
7126
+
7127
+ if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
7128
+ if let data = serviceData {
7129
+ do {
7130
+ if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
7131
+ print("Response Data: \(responseObject)")
7132
+
7133
+ // Check if status is 0 and handle the error
7134
+ if let status = responseObject["status"] as? Int, status == 0 {
7135
+ let errorMessage = responseObject["message"] as? String ?? "Unknown error"
7136
+ self.presentPaymentErrorVC(errorMessage: errorMessage)
7137
+ } else {
7138
+ DispatchQueue.main.async {
7139
+ if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
7140
+ paymentDoneVC.chargeData = responseObject
7141
+ // Pass the selected payment method
7142
+ paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
7143
+ paymentDoneVC.easyPayDelegate = self.easyPayDelegate
7144
+ // Pass billing info and additional info if available
7145
+ if let billingInfoData = self.request.billingInfoData,
7146
+ let fieldSection = try? JSONDecoder().decode(FieldSection.self, from: billingInfoData) {
7147
+
7148
+ // Filter billing info: only include non-empty values
7149
+ let filteredBilling = fieldSection.billing.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7150
+ paymentDoneVC.billingInfoData = filteredBilling
7151
+ var billingDict: [String: Any] = [:]
7152
+ filteredBilling.forEach { billingDict[$0.name] = $0.value }
7153
+ paymentDoneVC.billingInfo = billingDict
7154
+
7155
+ // Filter additional info: only include non-empty values
7156
+ let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7157
+ paymentDoneVC.additionalInfoData = filteredAdditional
7158
+ var additionalDict: [String: Any] = [:]
7159
+ filteredAdditional.forEach { additionalDict[$0.name] = $0.value }
7160
+ paymentDoneVC.additionalInfo = additionalDict
7161
+ }
7162
+ self.navigationController?.pushViewController(paymentDoneVC, animated: true)
7163
+ }
7164
+ }
7165
+ }
7166
+ } else {
7167
+ self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
7168
+ }
7169
+ } catch let jsonError {
7170
+ self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
7171
+ }
7172
+ } else {
7173
+ self.presentPaymentErrorVC(errorMessage: "No data received")
7174
+ }
7175
+ } else {
7176
+ if let data = serviceData,
7177
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
7178
+ let message = responseObj["message"] as? String {
7179
+ self.presentPaymentErrorVC(errorMessage: message)
7180
+ } else {
7181
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
7182
+ }
7183
+ }
7184
+ }
7185
+ task.resume()
7186
+ }
7187
+
7188
+ //MARK: - Banking Account Charge Api from Regular saved bank account if Billing info is nil
7189
+ func accountChargeSavedBankAccountApi() {
7190
+ showLoadingIndicator()
7191
+
7192
+ let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
7193
+
7194
+ guard let serviceURL = URL(string: fullURL) else {
7195
+ print("Invalid URL")
7196
+ hideLoadingIndicator()
7197
+ return
7198
+ }
7199
+
7200
+ var uRLRequest = URLRequest(url: serviceURL)
7201
+ uRLRequest.httpMethod = "POST"
7202
+ uRLRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
7203
+
7204
+ let token = UserStoreSingleton.shared.clientToken
7205
+ print("Setting clientToken header: \(token ?? "None")")
7206
+ uRLRequest.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
7207
+
7208
+ // Add API headers
7209
+ if let apiKey = EnvironmentConfig.apiKey,
7210
+ let apiSecret = EnvironmentConfig.apiSecret {
7211
+ uRLRequest.addValue(apiKey, forHTTPHeaderField: "x-api-key")
7212
+ uRLRequest.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
7213
+ }
7214
+
7215
+ var params: [String: Any] = [
7216
+ "account_id": selectedbankAccounts?.account_id ?? "",
7217
+ "customer": selectedbankAccounts?.customer_id ?? "",
7218
+ "payment_method": "ach",
7219
+ "description": "Test Description",
7220
+ "currency": "usd",
7221
+ ]
7222
+
7223
+ // Add these if recurring is enabled
7224
+ if let req = request, req.is_recurring == true {
7225
+ if let recurringType = req.recurringStartDateType, recurringType == .custom {
7226
+ // Only send start_date if type is .custom and field is not empty
7227
+ if let startDateText = txtFieldSelectDateSingleSavedBankView?.text, !startDateText.isEmpty {
7228
+ let inputFormatter = DateFormatter()
7229
+ inputFormatter.dateFormat = "dd/MM/yyyy"
7230
+
7231
+ let outputFormatter = DateFormatter()
7232
+ outputFormatter.dateFormat = "MM/dd/yyyy"
7233
+
7234
+ if let date = inputFormatter.date(from: startDateText) {
7235
+ let apiFormattedDate = outputFormatter.string(from: date)
7236
+ params["start_date"] = apiFormattedDate
7237
+ } else {
7238
+ print("Invalid date format in startDateText")
7239
+ }
7240
+ }
7241
+ }
7242
+
7243
+ params["interval"] = txtFieldSelectPlanSingleSavedBankView.text.lowercased()
7244
+ }
7245
+
7246
+ print(params)
7247
+
7248
+ do {
7249
+ let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
7250
+ uRLRequest.httpBody = jsonData
7251
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
7252
+ print("JSON Payload: \(jsonString)")
7253
+ }
7254
+ } catch let error {
7255
+ print("Error creating JSON data: \(error)")
7256
+ hideLoadingIndicator()
7257
+ return
7258
+ }
7259
+
7260
+ let session = URLSession.shared
7261
+ let task = session.dataTask(with: uRLRequest) { (serviceData, serviceResponse, error) in
7262
+
7263
+ DispatchQueue.main.async {
7264
+ self.hideLoadingIndicator() // Stop loader when response is received
7265
+ }
7266
+
7267
+ if let error = error {
7268
+ print("Error: \(error.localizedDescription)")
7269
+ return
7270
+ }
7271
+
7272
+ guard let httpResponse = serviceResponse as? HTTPURLResponse else {
7273
+ print("Invalid response")
7274
+ return
7275
+ }
7276
+
7277
+ if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
7278
+ if let data = serviceData {
7279
+ do {
7280
+ if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
7281
+ print("Response Data: \(responseObject)")
7282
+
7283
+ // Check if status is 0 and handle the error
7284
+ if let status = responseObject["status"] as? Int, status == 0 {
7285
+ let errorMessage = responseObject["message"] as? String ?? "Unknown error"
7286
+ self.presentPaymentErrorVC(errorMessage: errorMessage)
7287
+ } else {
7288
+ DispatchQueue.main.async {
7289
+ if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
7290
+ paymentDoneVC.chargeData = responseObject
7291
+ // Pass the selected payment method
7292
+ paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
7293
+ paymentDoneVC.easyPayDelegate = self.easyPayDelegate
7294
+ // Pass billingInfo and additionalInfo
7295
+ if let billingData = self.request.billingInfoData,
7296
+ let billingInfoDict = try? JSONSerialization.jsonObject(with: billingData, options: []) as? [String: Any] {
7297
+
7298
+ // Extract main billing fields
7299
+ let cleanBillingInfo: [String: Any] = [
7300
+ "postal_code": billingInfoDict["postal_code"] ?? "",
7301
+ "country": billingInfoDict["country"] ?? "",
7302
+ "city": billingInfoDict["city"] ?? "",
7303
+ "address": billingInfoDict["address"] ?? "",
7304
+ "state": billingInfoDict["state"] ?? ""
7305
+ ]
7306
+ paymentDoneVC.billingInfo = cleanBillingInfo
7307
+
7308
+ // Extract additional_info
7309
+ if let additional = billingInfoDict["additional_info"] as? [String: Any] {
7310
+ let cleanAdditionalInfo: [String: Any] = [
7311
+ "email": additional["email"] ?? "",
7312
+ "phone_number": additional["phone_number"] ?? "",
7313
+ "name": additional["name"] ?? "",
7314
+ "country_code": additional["country_code"] ?? ""
7315
+ ]
7316
+ paymentDoneVC.additionalInfo = cleanAdditionalInfo
7317
+ }
7318
+ }
7319
+ self.navigationController?.pushViewController(paymentDoneVC, animated: true)
7320
+ }
7321
+ }
7322
+ }
7323
+ } else {
7324
+ self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
7325
+ }
7326
+ } catch let jsonError {
7327
+ self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
7328
+ }
7329
+ } else {
7330
+ self.presentPaymentErrorVC(errorMessage: "No data received")
7331
+ }
7332
+ } else {
7333
+ if let data = serviceData,
7334
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
7335
+ let message = responseObj["message"] as? String {
7336
+ self.presentPaymentErrorVC(errorMessage: message)
7337
+ } else {
7338
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
7339
+ }
7340
+ }
7341
+ }
7342
+ task.resume()
7343
+ }
7344
+
7345
+ //MARK: - Banking Account Charge Api from Regular saved bank account if Billing info is available but their visibility is false
7346
+ func accountBankChargeSavedBankAccountApi() {
7347
+ showLoadingIndicator()
7348
+
7349
+ let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
7350
+
7351
+ guard let serviceURL = URL(string: fullURL) else {
7352
+ print("Invalid URL")
7353
+ hideLoadingIndicator()
7354
+ return
7355
+ }
7356
+
7357
+ var uRLRequest = URLRequest(url: serviceURL)
7358
+ uRLRequest.httpMethod = "POST"
7359
+ uRLRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
7360
+
7361
+ let token = UserStoreSingleton.shared.clientToken
7362
+ print("Setting clientToken header: \(token ?? "None")")
7363
+ uRLRequest.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
7364
+
7365
+ // Add API headers
7366
+ if let apiKey = EnvironmentConfig.apiKey,
7367
+ let apiSecret = EnvironmentConfig.apiSecret {
7368
+ uRLRequest.addValue(apiKey, forHTTPHeaderField: "x-api-key")
7369
+ uRLRequest.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
7370
+ }
7371
+
7372
+ var params: [String: Any] = [
7373
+ "account_id": selectedbankAccounts?.account_id ?? "",
7374
+ "customer": selectedbankAccounts?.customer_id ?? "",
7375
+ "payment_method": "ach",
7376
+ "description": "Test Description",
7377
+ "currency": "usd",
7378
+ ]
7379
+
7380
+ if let billingInfoData = request.billingInfoData {
7381
+ do {
7382
+ let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
7383
+
7384
+ // Billing Info
7385
+ let billing = fieldSection.billing
7386
+ if !billing.isEmpty {
7387
+ var billingDict: [String: Any] = [:]
7388
+ billing.forEach { billingDict[$0.name] = $0.value }
7389
+
7390
+ if let address = billingDict["address"] as? String, !address.isEmpty {
7391
+ params["address"] = address
7392
+ }
7393
+ if let country = billingDict["country"] as? String, !country.isEmpty {
7394
+ params["country"] = country
7395
+ }
7396
+ if let state = billingDict["state"] as? String, !state.isEmpty {
7397
+ params["state"] = state
7398
+ }
7399
+ if let city = billingDict["city"] as? String, !city.isEmpty {
7400
+ params["city"] = city
7401
+ }
7402
+ if let postalCode = billingDict["postal_code"] as? String, !postalCode.isEmpty {
7403
+ params["zip"] = postalCode
7404
+ }
7405
+ }
7406
+
7407
+ // Additional Info
7408
+ let additional = fieldSection.additional
7409
+ if !additional.isEmpty {
7410
+ var additionalDict: [String: Any] = [:]
7411
+ additional.forEach { additionalDict[$0.name] = $0.value }
7412
+
7413
+ if let desc = additionalDict["description"] as? String, !desc.isEmpty {
7414
+ params["description"] = desc
7415
+ } else {
7416
+ params["description"] = "Hosted payment checkout"
7417
+ }
7418
+
7419
+ if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
7420
+ params["phone_number"] = phone
7421
+ }
7422
+ if let email = additionalDict["email"] as? String, !email.isEmpty {
7423
+ params["email"] = email
7424
+ }
7425
+ if let name = additionalDict["name"] as? String, !name.isEmpty {
7426
+ params["name"] = name
7427
+ }
7428
+ } else {
7429
+ // If no description in additional info, set default
7430
+ params["description"] = "Hosted payment checkout"
7431
+ }
7432
+
7433
+ } catch {
7434
+ print("Failed to decode FieldSection: \(error)")
7435
+ params["description"] = "Hosted payment checkout"
7436
+ }
7437
+ } else {
7438
+ // Fallback if billingInfoData is missing
7439
+ params["description"] = "Hosted payment checkout"
7440
+ }
7441
+
7442
+ // Add these if recurring is enabled
7443
+ if let req = request, req.is_recurring == true {
7444
+ if let recurringType = req.recurringStartDateType, recurringType == .custom {
7445
+ // Only send start_date if type is .custom and field is not empty
7446
+ if let startDateText = txtFieldSelectDateSingleSavedBankView?.text, !startDateText.isEmpty {
7447
+ let inputFormatter = DateFormatter()
7448
+ inputFormatter.dateFormat = "dd/MM/yyyy"
7449
+
7450
+ let outputFormatter = DateFormatter()
7451
+ outputFormatter.dateFormat = "MM/dd/yyyy"
7452
+
7453
+ if let date = inputFormatter.date(from: startDateText) {
7454
+ let apiFormattedDate = outputFormatter.string(from: date)
7455
+ params["start_date"] = apiFormattedDate
7456
+ } else {
7457
+ print("Invalid date format in startDateText")
7458
+ }
7459
+ }
7460
+ }
7461
+
7462
+ params["interval"] = txtFieldSelectPlanSingleSavedBankView.text.lowercased()
7463
+ }
7464
+
7465
+ print(params)
7466
+
7467
+ do {
7468
+ let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
7469
+ uRLRequest.httpBody = jsonData
7470
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
7471
+ print("JSON Payload: \(jsonString)")
7472
+ }
7473
+ } catch let error {
7474
+ print("Error creating JSON data: \(error)")
7475
+ hideLoadingIndicator()
7476
+ return
7477
+ }
7478
+
7479
+ let session = URLSession.shared
7480
+ let task = session.dataTask(with: uRLRequest) { (serviceData, serviceResponse, error) in
7481
+
7482
+ DispatchQueue.main.async {
7483
+ self.hideLoadingIndicator() // Stop loader when response is received
7484
+ }
7485
+
7486
+ if let error = error {
7487
+ print("Error: \(error.localizedDescription)")
7488
+ return
7489
+ }
7490
+
7491
+ guard let httpResponse = serviceResponse as? HTTPURLResponse else {
7492
+ print("Invalid response")
7493
+ return
7494
+ }
7495
+
7496
+ if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
7497
+ if let data = serviceData {
7498
+ do {
7499
+ if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
7500
+ print("Response Data: \(responseObject)")
7501
+
7502
+ // Check if status is 0 and handle the error
7503
+ if let status = responseObject["status"] as? Int, status == 0 {
7504
+ let errorMessage = responseObject["message"] as? String ?? "Unknown error"
7505
+ self.presentPaymentErrorVC(errorMessage: errorMessage)
7506
+ } else {
7507
+ DispatchQueue.main.async {
7508
+ if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
7509
+ paymentDoneVC.chargeData = responseObject
7510
+ // Pass the selected payment method
7511
+ paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
7512
+ paymentDoneVC.easyPayDelegate = self.easyPayDelegate
7513
+ // Pass billing info and additional info if available
7514
+ if let billingInfoData = self.request.billingInfoData,
7515
+ let fieldSection = try? JSONDecoder().decode(FieldSection.self, from: billingInfoData) {
7516
+
7517
+ // Filter billing info: only include non-empty values
7518
+ let filteredBilling = fieldSection.billing.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7519
+ paymentDoneVC.billingInfoData = filteredBilling
7520
+ var billingDict: [String: Any] = [:]
7521
+ filteredBilling.forEach { billingDict[$0.name] = $0.value }
7522
+ paymentDoneVC.billingInfo = billingDict
7523
+
7524
+ // Filter additional info: only include non-empty values
7525
+ let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7526
+ paymentDoneVC.additionalInfoData = filteredAdditional
7527
+ var additionalDict: [String: Any] = [:]
7528
+ filteredAdditional.forEach { additionalDict[$0.name] = $0.value }
7529
+ paymentDoneVC.additionalInfo = additionalDict
7530
+ }
7531
+ self.navigationController?.pushViewController(paymentDoneVC, animated: true)
7532
+ }
7533
+ }
7534
+ }
7535
+ } else {
7536
+ self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
7537
+ }
7538
+ } catch let jsonError {
7539
+ self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
7540
+ }
7541
+ } else {
7542
+ self.presentPaymentErrorVC(errorMessage: "No data received")
7543
+ }
7544
+ } else {
7545
+ if let data = serviceData,
7546
+ let responseObj = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
7547
+ let message = responseObj["message"] as? String {
7548
+ self.presentPaymentErrorVC(errorMessage: message)
7549
+ } else {
7550
+ self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
7551
+ }
7552
+ }
7553
+ }
7554
+ task.resume()
7555
+ }
7556
+
7557
+ //MARK: - Banking Account Charge Api from add new account if billing info is nil and user not saved the account
7558
+ func accountChargeAddNewAccountApi() {
7559
+ showLoadingIndicator()
7560
+
7561
+ let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
7562
+
7563
+ guard let serviceURL = URL(string: fullURL) else {
7564
+ print("Invalid URL")
7565
+ hideLoadingIndicator()
7566
+ return
7567
+ }
7568
+
7569
+ var uRLRequest = URLRequest(url: serviceURL)
7570
+ uRLRequest.httpMethod = "POST"
7571
+ uRLRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
7572
+
7573
+ let token = UserStoreSingleton.shared.clientToken
7574
+ print("Setting clientToken header: \(token ?? "None")")
7575
+ uRLRequest.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
7576
+
7577
+ // Add API headers
7578
+ if let apiKey = EnvironmentConfig.apiKey,
7579
+ let apiSecret = EnvironmentConfig.apiSecret {
7580
+ uRLRequest.addValue(apiKey, forHTTPHeaderField: "x-api-key")
7581
+ uRLRequest.addValue(apiSecret, forHTTPHeaderField: "x-api-secret")
7582
+ }
7583
+
7584
+ let accountName = txtFieldAccountNameNewAccountView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
7585
+ let routingNumber = txtFieldRoutingNumberNewAccountView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
7586
+ let accountType = txtFieldAccountTypeNewAccountView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
7587
+ let accountNumber = txtFieldAccountNumberNewAccountView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
7588
+
7589
+ var params: [String: Any] = [
7590
+ "name": accountName,
7591
+ "email": UserStoreSingleton.shared.verificationEmail ?? "",
7592
+ "description": "Test Description",
7593
+ "currency": "usd",
7594
+ "account_type": accountType.lowercased(),
7595
+ "routing_number": routingNumber,
7596
+ "account_number": accountNumber,
7597
+ "payment_mode": "auth_and_capture",
7598
+ "payment_intent": UserStoreSingleton.shared.paymentIntent ?? "",
7599
+ "levelIndicator": 1,
7600
+ ]
7601
+
7602
+ // Add these if recurring is enabled
7603
+ if let req = request, req.is_recurring == true {
7604
+ if let recurringType = req.recurringStartDateType, recurringType == .custom {
7605
+ // Only send start_date if type is .custom and field is not empty
7606
+ if let startDateText = txtFieldSelectDateNewAccountView?.text, !startDateText.isEmpty {
7607
+ let inputFormatter = DateFormatter()
7608
+ inputFormatter.dateFormat = "dd/MM/yyyy"
7609
+
7610
+ let outputFormatter = DateFormatter()
7611
+ outputFormatter.dateFormat = "MM/dd/yyyy"
7612
+
7613
+ if let date = inputFormatter.date(from: startDateText) {
7614
+ let apiFormattedDate = outputFormatter.string(from: date)
7615
+ params["start_date"] = apiFormattedDate
7616
+ } else {
7617
+ print("Invalid date format in startDateText")
7618
+ }
7619
+ }
7620
+ }
7621
+
7622
+ params["interval"] = txtFieldSelectPlanNewAccountView.text.lowercased()
7623
+ }
7498
7624
 
7499
7625
  print(params)
7500
7626
 
@@ -7595,8 +7721,8 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7595
7721
  task.resume()
7596
7722
  }
7597
7723
 
7598
- //MARK: - Banking Account Charge Api from add new account if billing info is nil and user not saved the account
7599
- func accountChargeAddNewAccountApi() {
7724
+ //MARK: - Banking Account Charge Api from add new account if billing info is available but their visibilty is false
7725
+ func accountBankChargeAddNewAccountApi() {
7600
7726
  showLoadingIndicator()
7601
7727
 
7602
7728
  let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
@@ -7640,6 +7766,68 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7640
7766
  "levelIndicator": 1,
7641
7767
  ]
7642
7768
 
7769
+ if let billingInfoData = request.billingInfoData {
7770
+ do {
7771
+ let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
7772
+
7773
+ // Billing Info
7774
+ let billing = fieldSection.billing
7775
+ if !billing.isEmpty {
7776
+ var billingDict: [String: Any] = [:]
7777
+ billing.forEach { billingDict[$0.name] = $0.value }
7778
+
7779
+ if let address = billingDict["address"] as? String, !address.isEmpty {
7780
+ params["address"] = address
7781
+ }
7782
+ if let country = billingDict["country"] as? String, !country.isEmpty {
7783
+ params["country"] = country
7784
+ }
7785
+ if let state = billingDict["state"] as? String, !state.isEmpty {
7786
+ params["state"] = state
7787
+ }
7788
+ if let city = billingDict["city"] as? String, !city.isEmpty {
7789
+ params["city"] = city
7790
+ }
7791
+ if let postalCode = billingDict["postal_code"] as? String, !postalCode.isEmpty {
7792
+ params["zip"] = postalCode
7793
+ }
7794
+ }
7795
+
7796
+ // Additional Info
7797
+ let additional = fieldSection.additional
7798
+ if !additional.isEmpty {
7799
+ var additionalDict: [String: Any] = [:]
7800
+ additional.forEach { additionalDict[$0.name] = $0.value }
7801
+
7802
+ if let desc = additionalDict["description"] as? String, !desc.isEmpty {
7803
+ params["description"] = desc
7804
+ } else {
7805
+ params["description"] = "Hosted payment checkout"
7806
+ }
7807
+
7808
+ if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
7809
+ params["phone_number"] = phone
7810
+ }
7811
+ if let email = additionalDict["email"] as? String, !email.isEmpty {
7812
+ params["email"] = email
7813
+ }
7814
+ if let name = additionalDict["name"] as? String, !name.isEmpty {
7815
+ params["name"] = name
7816
+ }
7817
+ } else {
7818
+ // If no description in additional info, set default
7819
+ params["description"] = "Hosted payment checkout"
7820
+ }
7821
+
7822
+ } catch {
7823
+ print("Failed to decode FieldSection: \(error)")
7824
+ params["description"] = "Hosted payment checkout"
7825
+ }
7826
+ } else {
7827
+ // Fallback if billingInfoData is missing
7828
+ params["description"] = "Hosted payment checkout"
7829
+ }
7830
+
7643
7831
  // Add these if recurring is enabled
7644
7832
  if let req = request, req.is_recurring == true {
7645
7833
  if let recurringType = req.recurringStartDateType, recurringType == .custom {
@@ -7711,30 +7899,23 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
7711
7899
  // Pass the selected payment method
7712
7900
  paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
7713
7901
  paymentDoneVC.easyPayDelegate = self.easyPayDelegate
7714
- // Pass billingInfo and additionalInfo
7715
- if let billingData = self.request.billingInfoData,
7716
- let billingInfoDict = try? JSONSerialization.jsonObject(with: billingData, options: []) as? [String: Any] {
7902
+ // Pass billing info and additional info if available
7903
+ if let billingInfoData = self.request.billingInfoData,
7904
+ let fieldSection = try? JSONDecoder().decode(FieldSection.self, from: billingInfoData) {
7717
7905
 
7718
- // Extract main billing fields
7719
- let cleanBillingInfo: [String: Any] = [
7720
- "postal_code": billingInfoDict["postal_code"] ?? "",
7721
- "country": billingInfoDict["country"] ?? "",
7722
- "city": billingInfoDict["city"] ?? "",
7723
- "address": billingInfoDict["address"] ?? "",
7724
- "state": billingInfoDict["state"] ?? ""
7725
- ]
7726
- paymentDoneVC.billingInfo = cleanBillingInfo
7906
+ // Filter billing info: only include non-empty values
7907
+ let filteredBilling = fieldSection.billing.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7908
+ paymentDoneVC.billingInfoData = filteredBilling
7909
+ var billingDict: [String: Any] = [:]
7910
+ filteredBilling.forEach { billingDict[$0.name] = $0.value }
7911
+ paymentDoneVC.billingInfo = billingDict
7727
7912
 
7728
- // Extract additional_info
7729
- if let additional = billingInfoDict["additional_info"] as? [String: Any] {
7730
- let cleanAdditionalInfo: [String: Any] = [
7731
- "email": additional["email"] ?? "",
7732
- "phone_number": additional["phone_number"] ?? "",
7733
- "name": additional["name"] ?? "",
7734
- "country_code": additional["country_code"] ?? ""
7735
- ]
7736
- paymentDoneVC.additionalInfo = cleanAdditionalInfo
7737
- }
7913
+ // Filter additional info: only include non-empty values
7914
+ let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
7915
+ paymentDoneVC.additionalInfoData = filteredAdditional
7916
+ var additionalDict: [String: Any] = [:]
7917
+ filteredAdditional.forEach { additionalDict[$0.name] = $0.value }
7918
+ paymentDoneVC.additionalInfo = additionalDict
7738
7919
  }
7739
7920
  self.navigationController?.pushViewController(paymentDoneVC, animated: true)
7740
7921
  }
@@ -8280,13 +8461,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8280
8461
  if let billingInfoData = request.billingInfoData {
8281
8462
  do {
8282
8463
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
8283
-
8464
+
8284
8465
  // Billing Info
8285
8466
  let billing = fieldSection.billing
8286
8467
  if !billing.isEmpty {
8287
8468
  var billingDict: [String: Any] = [:]
8288
8469
  billing.forEach { billingDict[$0.name] = $0.value }
8289
-
8470
+
8290
8471
  if let address = billingDict["address"] as? String, !address.isEmpty {
8291
8472
  params["address"] = address
8292
8473
  }
@@ -8303,19 +8484,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8303
8484
  params["zip"] = postalCode
8304
8485
  }
8305
8486
  }
8306
-
8487
+
8307
8488
  // Additional Info
8308
8489
  let additional = fieldSection.additional
8309
8490
  if !additional.isEmpty {
8310
8491
  var additionalDict: [String: Any] = [:]
8311
8492
  additional.forEach { additionalDict[$0.name] = $0.value }
8312
-
8493
+
8313
8494
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
8314
8495
  params["description"] = desc
8315
8496
  } else {
8316
8497
  params["description"] = "Hosted payment checkout"
8317
8498
  }
8318
-
8499
+
8319
8500
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
8320
8501
  params["phone_number"] = phone
8321
8502
  }
@@ -8329,7 +8510,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8329
8510
  // If no description in additional info, set default
8330
8511
  params["description"] = "Hosted payment checkout"
8331
8512
  }
8332
-
8513
+
8333
8514
  } catch {
8334
8515
  print("Failed to decode FieldSection: \(error)")
8335
8516
  params["description"] = "Hosted payment checkout"
@@ -8422,7 +8603,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8422
8603
  var billingDict: [String: Any] = [:]
8423
8604
  filteredBilling.forEach { billingDict[$0.name] = $0.value }
8424
8605
  paymentDoneVC.billingInfo = billingDict
8425
-
8606
+
8426
8607
  // Filter additional info: only include non-empty values
8427
8608
  let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
8428
8609
  paymentDoneVC.additionalInfoData = filteredAdditional
@@ -8572,13 +8753,13 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8572
8753
  if let billingInfoData = request.billingInfoData {
8573
8754
  do {
8574
8755
  let fieldSection = try JSONDecoder().decode(FieldSection.self, from: billingInfoData)
8575
-
8756
+
8576
8757
  // Billing Info
8577
8758
  let billing = fieldSection.billing
8578
8759
  if !billing.isEmpty {
8579
8760
  var billingDict: [String: Any] = [:]
8580
8761
  billing.forEach { billingDict[$0.name] = $0.value }
8581
-
8762
+
8582
8763
  if let address = billingDict["address"] as? String, !address.isEmpty {
8583
8764
  params["address"] = address
8584
8765
  }
@@ -8595,19 +8776,19 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8595
8776
  params["zip"] = postalCode
8596
8777
  }
8597
8778
  }
8598
-
8779
+
8599
8780
  // Additional Info
8600
8781
  let additional = fieldSection.additional
8601
8782
  if !additional.isEmpty {
8602
8783
  var additionalDict: [String: Any] = [:]
8603
8784
  additional.forEach { additionalDict[$0.name] = $0.value }
8604
-
8785
+
8605
8786
  if let desc = additionalDict["description"] as? String, !desc.isEmpty {
8606
8787
  params["description"] = desc
8607
8788
  } else {
8608
8789
  params["description"] = "Hosted payment checkout"
8609
8790
  }
8610
-
8791
+
8611
8792
  if let phone = additionalDict["phone_number"] as? String, !phone.isEmpty {
8612
8793
  params["phone_number"] = phone
8613
8794
  }
@@ -8621,7 +8802,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8621
8802
  // If no description in additional info, set default
8622
8803
  params["description"] = "Hosted payment checkout"
8623
8804
  }
8624
-
8805
+
8625
8806
  } catch {
8626
8807
  print("Failed to decode FieldSection: \(error)")
8627
8808
  params["description"] = "Hosted payment checkout"
@@ -8712,7 +8893,7 @@ class PaymentInfoVC: BaseVC, BillingInfoVCDelegate {
8712
8893
  var billingDict: [String: Any] = [:]
8713
8894
  filteredBilling.forEach { billingDict[$0.name] = $0.value }
8714
8895
  paymentDoneVC.billingInfo = billingDict
8715
-
8896
+
8716
8897
  // Filter additional info: only include non-empty values
8717
8898
  let filteredAdditional = fieldSection.additional.filter { !($0.value.trimmingCharacters(in: .whitespaces).isEmpty) }
8718
8899
  paymentDoneVC.additionalInfoData = filteredAdditional
@@ -8846,10 +9027,6 @@ extension PaymentInfoVC: UICollectionViewDelegate, UICollectionViewDataSource, U
8846
9027
  if UserStoreSingleton.shared.isLoggedIn == false {
8847
9028
  self.viewSingleSavedAccount.isHidden = true
8848
9029
  self.viewBankFields.isHidden = true
8849
- // self.viewBtnShowSavedCards.isHidden = false
8850
- // self.lblBtnShowSaveCard.text = "Show Saved Cards"
8851
- // self.viewBtnShowSavedCardHeight.constant = 50
8852
- // self.viewBtnShowSavedCardTopCon.constant = 20
8853
9030
 
8854
9031
  if request.saveCard == false {
8855
9032
  self.viewBtnShowSavedCards.isHidden = true
@@ -8931,11 +9108,6 @@ extension PaymentInfoVC: UICollectionViewDelegate, UICollectionViewDataSource, U
8931
9108
 
8932
9109
  case "Bank":
8933
9110
  if UserStoreSingleton.shared.isLoggedIn == false {
8934
- // self.viewBankFields.isHidden = false
8935
- // self.viewBtnShowSavedCards.isHidden = false
8936
- // self.lblBtnShowSaveCard.text = "Show Saved Accounts"
8937
- // self.viewBtnShowSavedCardHeight.constant = 50
8938
- // self.viewBtnShowSavedCardTopCon.constant = 20
8939
9111
 
8940
9112
  if request.saveAccount == false {
8941
9113
  self.viewBtnShowSavedCards.isHidden = true
@@ -10158,7 +10330,7 @@ extension PaymentInfoVC: UITextFieldDelegate {
10158
10330
 
10159
10331
  }
10160
10332
 
10161
- //MARK: - BlinkCard
10333
+ ////MARK: - BlinkCard
10162
10334
  //extension PaymentInfoVC: MBCBlinkCardOverlayViewControllerDelegate {
10163
10335
  // func blinkCardOverlayViewControllerDidFinishScanning(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController, state: MBCRecognizerResultState) {
10164
10336
  // /** This is done on background thread */
@@ -10213,7 +10385,7 @@ extension PaymentInfoVC: UITextFieldDelegate {
10213
10385
  // }
10214
10386
  //
10215
10387
  //}
10216
-
10388
+ //
10217
10389
  //extension PaymentInfoVC: CustomOverlayDelegate {
10218
10390
  // func didFinishScanningCard(cardNumber: String, expiryDate: String, cvv: String, nameOnCard: String) {
10219
10391
  // // Update the text fields with scanned details