@jimrising/easymerchantsdk-react-native 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/caches/deviceStreaming.xml +340 -0
- package/.idea/em-MobileCheckoutSDK-ReactNative.iml +9 -0
- package/.idea/misc.xml +5 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +230 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/results.bin +1 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/BuildConfig.dex +0 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule$1.dex +0 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule.dex +0 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkPackage.dex +0 -0
- package/android/build/.transforms/27d3a0c22098810ca42038b1b8102417/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/.transforms/41cd2635778c1bb5c18af2c46eb9196e/results.bin +1 -0
- package/android/build/.transforms/41cd2635778c1bb5c18af2c46eb9196e/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/results.bin +1 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/BuildConfig.dex +0 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule$1.dex +0 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule.dex +0 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkPackage.dex +0 -0
- package/android/build/.transforms/6b36622787f586c4b6e3df98c5efa11c/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/.transforms/7eb7ceaa43c9e8323ac65b4f785987b6/results.bin +1 -0
- package/android/build/.transforms/7eb7ceaa43c9e8323ac65b4f785987b6/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/results.bin +1 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/BuildConfig.dex +0 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule$1.dex +0 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkModule.dex +0 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/reactlibrary/RNEasymerchantsdkPackage.dex +0 -0
- package/android/build/.transforms/a8b93af4be449a0e2cca4bd6ddb6685e/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/.transforms/f1a160720415bc76d8d6c6734c5acf3e/results.bin +1 -0
- package/android/build/.transforms/f1a160720415bc76d8d6c6734c5acf3e/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/generated/source/buildConfig/debug/com/reactlibrary/BuildConfig.java +10 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +7 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
- package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
- package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/reactlibrary/BuildConfig.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/reactlibrary/RNEasymerchantsdkModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/reactlibrary/RNEasymerchantsdkModule.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/reactlibrary/RNEasymerchantsdkPackage.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +2 -0
- package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +7 -0
- package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +7 -0
- package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
- package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/reactlibrary/BuildConfig.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/reactlibrary/RNEasymerchantsdkModule$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/reactlibrary/RNEasymerchantsdkModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/reactlibrary/RNEasymerchantsdkPackage.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +1 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +17 -0
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNEasymerchantsdkModule$1.class.uniqueId2 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNEasymerchantsdkModule.class.uniqueId1 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/RNEasymerchantsdkPackage.class.uniqueId0 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build.gradle +55 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/reactlibrary/RNEasymerchantsdkModule.java +72 -0
- package/android/src/main/java/com/reactlibrary/RNEasymerchantsdkPackage.java +28 -0
- package/index.js +5 -0
- package/ios/Bundle/EasyPayBundle.swift +22 -0
- package/ios/Classes/EasyMerchantSdk.h +4 -0
- package/ios/Classes/EasyMerchantSdk.m +43 -0
- package/ios/Classes/EasyMerchantSdk.swift +124 -0
- package/ios/Classes/EasyPayViewController.swift +90 -0
- package/ios/CustomComponents/CheckboxButton.swift +20 -0
- package/ios/CustomComponents/FilledButton.swift +17 -0
- package/ios/CustomComponents/OutlineButton.swift +26 -0
- package/ios/CustomComponents/TextFieldStackView.swift +96 -0
- package/ios/EnvironmentConfig.swift +63 -0
- package/ios/Example/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- package/ios/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
- package/ios/Example/Assets.xcassets/Contents.json +6 -0
- package/ios/Example/Base.lproj/LaunchScreen.storyboard +25 -0
- package/ios/Example/Base.lproj/Main.storyboard +65 -0
- package/ios/Example/SceneDelegate.swift +52 -0
- package/ios/Example/ViewController.swift +84 -0
- package/ios/Extensions/UIColor.swift +22 -0
- package/ios/Extensions/UIFont.swift +80 -0
- package/ios/Extensions/UIViewController+Extension.swift +42 -0
- package/ios/Models/AdditionalInfo.swift +16 -0
- package/ios/Models/BankAccountModel.swift +23 -0
- package/ios/Models/BillingInfo.swift +16 -0
- package/ios/Models/CardModel.swift +19 -0
- package/ios/Models/Country.swift +19 -0
- package/ios/Models/PaymentInfo.swift +46 -0
- package/ios/Models/Request.swift +245 -0
- package/ios/Models/Result.swift +69 -0
- package/ios/Pods/UserDefaults/UserStoreSingleton.swift +200 -0
- package/ios/Pods/ViewControllers/AdditionalInfoVC.swift +1073 -0
- package/ios/Pods/ViewControllers/BaseVC.swift +117 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/BillingInfoVC.swift +616 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/CityListTVC.swift +19 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/CountryListTVC.swift +19 -0
- package/ios/Pods/ViewControllers/BillingInfoVC/Cells/StateListTVC.swift +19 -0
- package/ios/Pods/ViewControllers/CountryListVC.swift +367 -0
- package/ios/Pods/ViewControllers/EmailVerificationVC.swift +192 -0
- package/ios/Pods/ViewControllers/OTPVerificationVC.swift +1009 -0
- package/ios/Pods/ViewControllers/PaymentDoneVC.swift +94 -0
- package/ios/Pods/ViewControllers/PaymentErrorVC.swift +43 -0
- package/ios/Pods/ViewControllers/PaymentInformation/AccountTypeTVC.swift +19 -0
- package/ios/Pods/ViewControllers/PaymentInformation/PaymentInfoVC.swift +4269 -0
- package/ios/Pods/ViewControllers/PaymentInformation/PaymentInformationCVC.swift +20 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedAccountsTVC/SavedAccountTVC.swift +37 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedAccountsTVC/SavedAccountTVC.xib +163 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedCardsTVC/SavedCardsTVC.swift +40 -0
- package/ios/Pods/ViewControllers/PaymentInformation/SavedCardsTVC/SavedCardsTVC.xib +184 -0
- package/ios/Pods/ViewControllers/TermAndConditionsVC.swift +21 -0
- package/ios/Resources/Assets.xcassets/Card/Amex.imageset/206682_american_express_method_card_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/Amex.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/Contents.json +6 -0
- package/ios/Resources/Assets.xcassets/Card/DinersClub.imageset/472318_card_club_diners_dinner_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/DinersClub.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/Discover.imageset/206686_network_payment_discover_card_method_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/Discover.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/JCB.imageset/358102_card_jcb_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/JCB.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/MasterCard.imageset/206680_master_method_card_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/MasterCard.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/UnionPay.imageset/1468976_card_payment_unionpay_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/UnionPay.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/Visa.imageset/206684_visa_method_card_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/Visa.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/maestro.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/maestro.imageset/maestro.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/paypal.imageset/206675_paypal_method_payment_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/paypal.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/rupay.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/rupay.imageset/rupay.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/unknown_card.imageset/4635000_card_credit_digital_money_icon.svg +1 -0
- package/ios/Resources/Assets.xcassets/Card/unknown_card.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/worldpay.imageset/Contents.json +12 -0
- package/ios/Resources/Assets.xcassets/Card/worldpay.imageset/worldpay.svg +1 -0
- package/ios/Resources/Assets.xcassets/Contents.json +6 -0
- package/ios/Resources/Assets.xcassets/Ellipsis.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/Ellipsis.imageset/icons8-menu-30.png +0 -0
- package/ios/Resources/Assets.xcassets/Ellipsis.imageset/icons8-menu-60.png +0 -0
- package/ios/Resources/Assets.xcassets/Ellipsis.imageset/icons8-menu-90.png +0 -0
- package/ios/Resources/Assets.xcassets/Rotate.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/Rotate.imageset/refresh-cw-2.png +0 -0
- package/ios/Resources/Assets.xcassets/Rotate.imageset/refresh-cw-3.png +0 -0
- package/ios/Resources/Assets.xcassets/Rotate.imageset/refresh-cw.png +0 -0
- package/ios/Resources/Assets.xcassets/amexCvc.imageset/Contents.json +22 -0
- package/ios/Resources/Assets.xcassets/amexCvc.imageset/Group-1.png +0 -0
- package/ios/Resources/Assets.xcassets/amexCvc.imageset/Group.png +0 -0
- package/ios/Resources/Assets.xcassets/check.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/check.imageset/check-circle-4.png +0 -0
- package/ios/Resources/Assets.xcassets/check.imageset/check-circle-5.png +0 -0
- package/ios/Resources/Assets.xcassets/check.imageset/check-circle-6.png +0 -0
- package/ios/Resources/Assets.xcassets/chip.imageset/Contents.json +21 -0
- package/ios/Resources/Assets.xcassets/chip.imageset/chip.png +0 -0
- package/ios/Resources/Assets.xcassets/loaderImage.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/loaderImage.imageset/check-circle-2.png +0 -0
- package/ios/Resources/Assets.xcassets/loaderImage.imageset/check-circle-3.png +0 -0
- package/ios/Resources/Assets.xcassets/loaderImage.imageset/check-circle.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_done_icon.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/payment_done_icon.imageset/payment_done_icon 1.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_done_icon.imageset/payment_done_icon 2.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_done_icon.imageset/payment_done_icon.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_error_icon.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/payment_error_icon.imageset/payment_error_icon 1.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_error_icon.imageset/payment_error_icon 2.png +0 -0
- package/ios/Resources/Assets.xcassets/payment_error_icon.imageset/payment_error_icon.png +0 -0
- package/ios/Resources/Assets.xcassets/wallet.imageset/Contents.json +23 -0
- package/ios/Resources/Assets.xcassets/wallet.imageset/icons8-wallet-24(@1/303/227).png +0 -0
- package/ios/Resources/Assets.xcassets/wallet.imageset/icons8-wallet-48(@2/303/227).png +0 -0
- package/ios/Resources/Assets.xcassets/wallet.imageset/icons8-wallet-72(@3/303/227).png +0 -0
- package/ios/Resources/Colors.xcassets/00000008.colorset/Contents.json +20 -0
- package/ios/Resources/Colors.xcassets/00000016.colorset/Contents.json +20 -0
- package/ios/Resources/Colors.xcassets/00000038.colorset/Contents.json +20 -0
- package/ios/Resources/Colors.xcassets/00000060.colorset/Contents.json +20 -0
- package/ios/Resources/Colors.xcassets/1757D9.colorset/Contents.json +20 -0
- package/ios/Resources/Colors.xcassets/Contents.json +6 -0
- package/ios/Resources/Colors.xcassets/E93939.colorset/Contents.json +20 -0
- package/ios/Resources/PrivacyInfo.xcprivacy +10 -0
- package/ios/ThirdParty/Keyboad Handling/KeyboardObserver.swift +74 -0
- package/ios/easymerchantsdk.podspec +80 -0
- package/ios/easymerchantsdk.storyboard +5885 -0
- package/package.json +27 -0
- package/src/index.js +44 -0
|
@@ -0,0 +1,1073 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AdditionalInfoVC.swift
|
|
3
|
+
// EasyPay
|
|
4
|
+
//
|
|
5
|
+
// Created by Mony's Mac on 13/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
|
|
10
|
+
@available(iOS 16.0, *)
|
|
11
|
+
class AdditionalInfoVC: BaseVC {
|
|
12
|
+
|
|
13
|
+
@IBOutlet weak var viewAdditionalInfo: UIView!
|
|
14
|
+
@IBOutlet weak var txtFieldName: UITextField!
|
|
15
|
+
@IBOutlet weak var txtFieldEmail: UITextField!
|
|
16
|
+
@IBOutlet weak var txtFieldPhoneNumber: UITextField!
|
|
17
|
+
@IBOutlet weak var txtFieldDescription: UITextField!
|
|
18
|
+
@IBOutlet weak var lblCountryCode: UILabel!
|
|
19
|
+
@IBOutlet weak var btnPrevious: UIButton!
|
|
20
|
+
@IBOutlet weak var imgViewCountryFlag: UIImageView!
|
|
21
|
+
|
|
22
|
+
@IBOutlet weak var btnPayNow: UIButton!
|
|
23
|
+
|
|
24
|
+
var cardNumber: String?
|
|
25
|
+
var expiryDate: String?
|
|
26
|
+
var cvv: String?
|
|
27
|
+
var nameOnCard: String?
|
|
28
|
+
var billingInfoData: [String: Any]?
|
|
29
|
+
|
|
30
|
+
var selectedPaymentMethod: String?
|
|
31
|
+
|
|
32
|
+
//Banking Params
|
|
33
|
+
var accountName: String?
|
|
34
|
+
var routingNumber: String?
|
|
35
|
+
var accountType: String?
|
|
36
|
+
var accountNumber: String?
|
|
37
|
+
|
|
38
|
+
var easyPayDelegate: EasyPayViewControllerDelegate?
|
|
39
|
+
|
|
40
|
+
var isSavedForFuture: Bool = false
|
|
41
|
+
|
|
42
|
+
var selectedCard: CardModel?
|
|
43
|
+
var amount: Int?
|
|
44
|
+
var cvvText: String?
|
|
45
|
+
var isFrom = String()
|
|
46
|
+
|
|
47
|
+
var isSavedNewCard: Bool = false
|
|
48
|
+
|
|
49
|
+
//From Regular Saved Bank Accounts
|
|
50
|
+
var customerID: String?
|
|
51
|
+
var accountID: String?
|
|
52
|
+
|
|
53
|
+
var isSavedNewAccount: Bool?
|
|
54
|
+
|
|
55
|
+
override func viewDidLoad() {
|
|
56
|
+
super.viewDidLoad()
|
|
57
|
+
|
|
58
|
+
viewAdditionalInfo.layer.borderColor = UIColor.systemGray.cgColor
|
|
59
|
+
viewAdditionalInfo.layer.borderWidth = 1
|
|
60
|
+
viewAdditionalInfo.layer.cornerRadius = 8
|
|
61
|
+
|
|
62
|
+
btnPrevious.layer.borderColor = UIColor.systemBlue.cgColor
|
|
63
|
+
btnPrevious.layer.borderWidth = 1
|
|
64
|
+
btnPrevious.layer.cornerRadius = 8
|
|
65
|
+
|
|
66
|
+
txtFieldName.delegate = self
|
|
67
|
+
txtFieldEmail.delegate = self
|
|
68
|
+
txtFieldDescription.delegate = self
|
|
69
|
+
txtFieldPhoneNumber.delegate = self
|
|
70
|
+
|
|
71
|
+
// Add tap gesture to hide the views and dismiss the keyboard
|
|
72
|
+
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapOutside))
|
|
73
|
+
tapGesture.cancelsTouchesInView = false
|
|
74
|
+
self.view.addGestureRecognizer(tapGesture)
|
|
75
|
+
|
|
76
|
+
if let billingInfoData = billingInfoData {
|
|
77
|
+
print("Billing Info Data: \(billingInfoData)")
|
|
78
|
+
|
|
79
|
+
// Extract the additional_info dictionary
|
|
80
|
+
if let additionalInfo = billingInfoData["additional_info"] as? [String: Any] {
|
|
81
|
+
// Set the name field
|
|
82
|
+
if let name = additionalInfo["name"] as? String {
|
|
83
|
+
txtFieldName.text = name
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if let email = additionalInfo["email"] as? String {
|
|
87
|
+
txtFieldEmail.text = email
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if let phoneNumber = additionalInfo["phone_number"] as? String {
|
|
91
|
+
txtFieldPhoneNumber.text = phoneNumber
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if let description = additionalInfo["description"] as? String {
|
|
95
|
+
txtFieldDescription.text = description
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//Show Default USA code in starting.
|
|
101
|
+
let usaCountry = Country()
|
|
102
|
+
usaCountry.name = "United States"
|
|
103
|
+
usaCountry.countryCode = "US"
|
|
104
|
+
usaCountry.extensionCode = "1"
|
|
105
|
+
usaCountry.flag = String.flag(for: "US")
|
|
106
|
+
lblCountryCode.text = "\(usaCountry.flag ?? "") +\(usaCountry.extensionCode ?? "")"
|
|
107
|
+
|
|
108
|
+
// print(amount ?? "")
|
|
109
|
+
// let am = Int(amount ?? "0")
|
|
110
|
+
// btnPayNow.setTitle("Pay Now ($\(am ?? 0))", for: .normal)
|
|
111
|
+
//
|
|
112
|
+
// print("Received customerID: \(customerID ?? "nil")")
|
|
113
|
+
// print("Received accountID: \(accountID ?? "nil")")
|
|
114
|
+
// print(billingInfoData ?? "")
|
|
115
|
+
// print(isFrom)
|
|
116
|
+
// print(selectedPaymentMethod ?? "")
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@objc func didTapOutside() {
|
|
120
|
+
// Dismiss the keyboard
|
|
121
|
+
self.view.endEditing(true)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@IBAction func actionBtnSelectCountryCode(_ sender: UIButton) {
|
|
125
|
+
let vc = EasyPaySdk.instantiateViewController(withIdentifier: "CountryListVC") as! CountryListVC
|
|
126
|
+
vc.delegate = self
|
|
127
|
+
self.navigationController?.pushViewController(vc, animated: true)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@IBAction func actionBtnPrevious(_ sender: UIButton) {
|
|
131
|
+
self.navigationController?.popViewController(animated: true)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@IBAction func actionBtnPayNow(_ sender: UIButton) {
|
|
135
|
+
if isSavedNewCard {
|
|
136
|
+
if isFrom == "AddNewCard" {
|
|
137
|
+
self.paymentIntentAddNewCardApi(customerId: UserStoreSingleton.shared.customerId)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if isSavedForFuture {
|
|
142
|
+
// Navigate to EmailVerificationVC based on the selected payment method
|
|
143
|
+
if selectedPaymentMethod == "Card" {
|
|
144
|
+
if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
|
|
145
|
+
// Pass any necessary data to EmailVerificationVC
|
|
146
|
+
emailVerificationVC.cardNumber = cardNumber
|
|
147
|
+
emailVerificationVC.expiryDate = expiryDate
|
|
148
|
+
emailVerificationVC.cvv = cvv
|
|
149
|
+
emailVerificationVC.nameOnCard = nameOnCard
|
|
150
|
+
emailVerificationVC.billingInfoData = billingInfoData
|
|
151
|
+
emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
|
|
152
|
+
emailVerificationVC.easyPayDelegate = self.easyPayDelegate
|
|
153
|
+
self.navigationController?.pushViewController(emailVerificationVC, animated: true)
|
|
154
|
+
}
|
|
155
|
+
} else if selectedPaymentMethod == "Bank" {
|
|
156
|
+
if let emailVerificationVC = self.storyboard?.instantiateViewController(withIdentifier: "EmailVerificationVC") as? EmailVerificationVC {
|
|
157
|
+
// Pass any necessary data to EmailVerificationVC
|
|
158
|
+
emailVerificationVC.accountName = accountName
|
|
159
|
+
emailVerificationVC.routingNumber = routingNumber
|
|
160
|
+
emailVerificationVC.accountType = accountType
|
|
161
|
+
emailVerificationVC.accountNumber = accountNumber
|
|
162
|
+
emailVerificationVC.billingInfoData = billingInfoData
|
|
163
|
+
emailVerificationVC.selectedPaymentMethod = selectedPaymentMethod
|
|
164
|
+
emailVerificationVC.easyPayDelegate = self.easyPayDelegate
|
|
165
|
+
self.navigationController?.pushViewController(emailVerificationVC, animated: true)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
// Proceed with the normal flow
|
|
170
|
+
if selectedPaymentMethod == "Card" {
|
|
171
|
+
if isFrom == "SavedCards" {
|
|
172
|
+
paymentIntentFromShowCardApi()
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
paymentIntentApi()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else if selectedPaymentMethod == "Bank" {
|
|
179
|
+
if isFrom == "SavedBank" {
|
|
180
|
+
accountChargeSavedBankAccountApi()
|
|
181
|
+
}
|
|
182
|
+
else if isFrom == "NormalBankPayWithoutSave" {
|
|
183
|
+
accountChargeApi()
|
|
184
|
+
}
|
|
185
|
+
else if isFrom == "AddNewAccountWithoutSave" {
|
|
186
|
+
accountChargeApi()
|
|
187
|
+
}
|
|
188
|
+
else if isFrom == "AddNewAccountWithSave" {
|
|
189
|
+
accountChargeApi(customerId: UserStoreSingleton.shared.customerId)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func presentPaymentErrorVC(errorMessage: String) {
|
|
198
|
+
DispatchQueue.main.async {
|
|
199
|
+
if let paymentErrorVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentErrorVC") as? PaymentErrorVC {
|
|
200
|
+
paymentErrorVC.errorMessage = errorMessage
|
|
201
|
+
paymentErrorVC.easyPayDelegate = self.easyPayDelegate // Pass the reference here
|
|
202
|
+
self.navigationController?.pushViewController(paymentErrorVC, animated: true)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// MARK: - Credit Card Charge Api
|
|
208
|
+
func paymentIntentApi() {
|
|
209
|
+
showLoadingIndicator()
|
|
210
|
+
|
|
211
|
+
// var components = URLComponents()
|
|
212
|
+
// components.scheme = "https"
|
|
213
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
214
|
+
// components.path = "/api/v1/charges"
|
|
215
|
+
//
|
|
216
|
+
// guard let serviceURL = components.url else {
|
|
217
|
+
// print("Invalid URL")
|
|
218
|
+
// self.hideLoadingIndicator()
|
|
219
|
+
// return
|
|
220
|
+
// }
|
|
221
|
+
|
|
222
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
223
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
|
|
224
|
+
|
|
225
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
226
|
+
print("Invalid URL")
|
|
227
|
+
hideLoadingIndicator()
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var request = URLRequest(url: serviceURL)
|
|
232
|
+
request.httpMethod = "POST"
|
|
233
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
234
|
+
|
|
235
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
236
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
237
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
238
|
+
|
|
239
|
+
guard let billingInfoData = billingInfoData else {
|
|
240
|
+
print("Billing info data is nil")
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Remove the flag and "+" sign from lblCountryCode.text
|
|
245
|
+
let countryCode = lblCountryCode.text ?? ""
|
|
246
|
+
let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
|
|
247
|
+
// Format phone number parameter by combining cleaned country code and phone number
|
|
248
|
+
let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
|
|
249
|
+
|
|
250
|
+
let additionalInfo: [String: Any] = [
|
|
251
|
+
"name": txtFieldName.text ?? "",
|
|
252
|
+
"email": txtFieldEmail.text ?? "",
|
|
253
|
+
// "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
|
|
254
|
+
"phone_number": phoneNumber,
|
|
255
|
+
"description": txtFieldDescription.text ?? ""
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
let billingInfo: [String: Any] = [
|
|
259
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
260
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
261
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
262
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
263
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
let params: [String: Any] = [
|
|
267
|
+
"name": txtFieldName.text ?? "",
|
|
268
|
+
"email": txtFieldEmail.text ?? "",
|
|
269
|
+
"card_number": cardNumber?.replacingOccurrences(of: " ", with: "") ?? "",
|
|
270
|
+
"cardholder_name": nameOnCard ?? "",
|
|
271
|
+
"exp_month": expiryDate?.components(separatedBy: "/").first ?? "",
|
|
272
|
+
"exp_year": expiryDate?.components(separatedBy: "/").last ?? "",
|
|
273
|
+
"cvc": cvv ?? "",
|
|
274
|
+
"description": txtFieldDescription.text ?? "",
|
|
275
|
+
"currency": "usd",
|
|
276
|
+
"billing_info": billingInfo,
|
|
277
|
+
"additional_info": additionalInfo,
|
|
278
|
+
"payment_method": "card",
|
|
279
|
+
"save_card": 0,
|
|
280
|
+
]
|
|
281
|
+
|
|
282
|
+
do {
|
|
283
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
284
|
+
request.httpBody = jsonData
|
|
285
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
286
|
+
print("JSON Payload: \(jsonString)")
|
|
287
|
+
}
|
|
288
|
+
} catch let error {
|
|
289
|
+
print("Error creating JSON data: \(error)")
|
|
290
|
+
self.hideLoadingIndicator()
|
|
291
|
+
return
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
let session = URLSession.shared
|
|
295
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
296
|
+
|
|
297
|
+
DispatchQueue.main.async {
|
|
298
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if let error = error {
|
|
302
|
+
print("Error: \(error.localizedDescription)")
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
307
|
+
print("Invalid response")
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
312
|
+
if let data = serviceData {
|
|
313
|
+
do {
|
|
314
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
315
|
+
print("Response Data: \(responseObject)")
|
|
316
|
+
|
|
317
|
+
// Check if status is 0 and handle the error
|
|
318
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
319
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
320
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
321
|
+
} else {
|
|
322
|
+
DispatchQueue.main.async {
|
|
323
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
324
|
+
paymentDoneVC.chargeData = responseObject
|
|
325
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
326
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate
|
|
327
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
333
|
+
}
|
|
334
|
+
} catch let jsonError {
|
|
335
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
task.resume()
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//MARK: - Credit Card Charge Api from Saved cards
|
|
348
|
+
func paymentIntentFromShowCardApi() {
|
|
349
|
+
showLoadingIndicator()
|
|
350
|
+
// var components = URLComponents()
|
|
351
|
+
// components.scheme = "https"
|
|
352
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
353
|
+
// components.path = "/api/v1/charges"
|
|
354
|
+
//
|
|
355
|
+
// guard let serviceURL = components.url else {
|
|
356
|
+
// print("Invalid URL")
|
|
357
|
+
// hideLoadingIndicator()
|
|
358
|
+
// return
|
|
359
|
+
// }
|
|
360
|
+
|
|
361
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
362
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
|
|
363
|
+
|
|
364
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
365
|
+
print("Invalid URL")
|
|
366
|
+
hideLoadingIndicator()
|
|
367
|
+
return
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
var request = URLRequest(url: serviceURL)
|
|
371
|
+
request.httpMethod = "POST"
|
|
372
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
373
|
+
|
|
374
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
375
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
376
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
377
|
+
|
|
378
|
+
guard let billingInfoData = billingInfoData else {
|
|
379
|
+
print("Billing info data is nil")
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Remove the flag and "+" sign from lblCountryCode.text
|
|
384
|
+
let countryCode = lblCountryCode.text ?? ""
|
|
385
|
+
let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
|
|
386
|
+
// Format phone number parameter by combining cleaned country code and phone number
|
|
387
|
+
let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
|
|
388
|
+
|
|
389
|
+
let additionalInfo: [String: Any] = [
|
|
390
|
+
"name": txtFieldName.text ?? "",
|
|
391
|
+
"email": txtFieldEmail.text ?? "",
|
|
392
|
+
// "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
|
|
393
|
+
"phone_number": phoneNumber,
|
|
394
|
+
"description": txtFieldDescription.text ?? ""
|
|
395
|
+
]
|
|
396
|
+
|
|
397
|
+
let billingInfo: [String: Any] = [
|
|
398
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
399
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
400
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
401
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
402
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
403
|
+
]
|
|
404
|
+
|
|
405
|
+
let params: [String: Any] = [
|
|
406
|
+
"name": txtFieldName.text ?? "",
|
|
407
|
+
"email": txtFieldEmail.text ?? "",
|
|
408
|
+
"description": txtFieldDescription.text ?? "",
|
|
409
|
+
"currency": "usd",
|
|
410
|
+
"billing_info": billingInfo,
|
|
411
|
+
"additional_info": additionalInfo,
|
|
412
|
+
"payment_method": "card",
|
|
413
|
+
"save_card": 0,
|
|
414
|
+
"customer" : selectedCard?.customerId ?? "",
|
|
415
|
+
"customer_id" : selectedCard?.customerId ?? "",
|
|
416
|
+
"card_id" : selectedCard?.cardId ?? "",
|
|
417
|
+
"cvc" : cvvText ?? ""
|
|
418
|
+
]
|
|
419
|
+
|
|
420
|
+
do {
|
|
421
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
422
|
+
request.httpBody = jsonData
|
|
423
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
424
|
+
print("JSON Payload: \(jsonString)")
|
|
425
|
+
}
|
|
426
|
+
} catch let error {
|
|
427
|
+
print("Error creating JSON data: \(error)")
|
|
428
|
+
hideLoadingIndicator()
|
|
429
|
+
return
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
let session = URLSession.shared
|
|
433
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
434
|
+
|
|
435
|
+
DispatchQueue.main.async {
|
|
436
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if let error = error {
|
|
440
|
+
print("Error: \(error.localizedDescription)")
|
|
441
|
+
return
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
445
|
+
print("Invalid response")
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
450
|
+
if let data = serviceData {
|
|
451
|
+
do {
|
|
452
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
453
|
+
print("Response Data: \(responseObject)")
|
|
454
|
+
|
|
455
|
+
// Check if status is 0 and handle the error
|
|
456
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
457
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
458
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
459
|
+
} else {
|
|
460
|
+
DispatchQueue.main.async {
|
|
461
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
462
|
+
paymentDoneVC.chargeData = responseObject
|
|
463
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
464
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate
|
|
465
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
471
|
+
}
|
|
472
|
+
} catch let jsonError {
|
|
473
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
task.resume()
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
//MARK: - Credit Card Charge Api from Add new card from saved cards.
|
|
486
|
+
func paymentIntentAddNewCardApi(customerId: String?) {
|
|
487
|
+
showLoadingIndicator()
|
|
488
|
+
|
|
489
|
+
// var components = URLComponents()
|
|
490
|
+
// components.scheme = "https"
|
|
491
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
492
|
+
// components.path = "/api/v1/charges"
|
|
493
|
+
//
|
|
494
|
+
// guard let serviceURL = components.url else {
|
|
495
|
+
// print("Invalid URL")
|
|
496
|
+
// hideLoadingIndicator()
|
|
497
|
+
// return
|
|
498
|
+
// }
|
|
499
|
+
|
|
500
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
501
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.charges.path()
|
|
502
|
+
|
|
503
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
504
|
+
print("Invalid URL")
|
|
505
|
+
hideLoadingIndicator()
|
|
506
|
+
return
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
var request = URLRequest(url: serviceURL)
|
|
510
|
+
request.httpMethod = "POST"
|
|
511
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
512
|
+
|
|
513
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
514
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
515
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
516
|
+
|
|
517
|
+
guard let billingInfoData = billingInfoData else {
|
|
518
|
+
print("Billing info data is nil")
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
let additionalInfoFromBilling = billingInfoData["additional_info"] as? [String: Any] ?? [:]
|
|
523
|
+
|
|
524
|
+
let additionalInfo: [String: Any] = [
|
|
525
|
+
"name": additionalInfoFromBilling["name"] as? String ?? "",
|
|
526
|
+
"email": additionalInfoFromBilling["email"] as? String ?? "",
|
|
527
|
+
"phone_number": additionalInfoFromBilling["phone_number"] as? String ?? "",
|
|
528
|
+
"description": additionalInfoFromBilling["description"] as? String ?? ""
|
|
529
|
+
]
|
|
530
|
+
|
|
531
|
+
let billingInfo: [String: Any] = [
|
|
532
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
533
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
534
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
535
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
536
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
537
|
+
]
|
|
538
|
+
|
|
539
|
+
let emailPrefix = UserStoreSingleton.shared.verificationEmail?.components(separatedBy: "@").first ?? ""
|
|
540
|
+
|
|
541
|
+
var params: [String: Any] = [
|
|
542
|
+
"name": additionalInfoFromBilling["name"] as? String ?? "",
|
|
543
|
+
"card_number": cardNumber?.replacingOccurrences(of: " ", with: "") ?? "",
|
|
544
|
+
"cardholder_name": nameOnCard ?? "",
|
|
545
|
+
"exp_month": expiryDate?.components(separatedBy: "/").first ?? "",
|
|
546
|
+
"exp_year": expiryDate?.components(separatedBy: "/").last ?? "",
|
|
547
|
+
"cvc": cvv ?? "",
|
|
548
|
+
"description": additionalInfoFromBilling["description"] as? String ?? "",
|
|
549
|
+
"currency": "usd",
|
|
550
|
+
"billing_info": billingInfo,
|
|
551
|
+
"additional_info": additionalInfo,
|
|
552
|
+
"payment_method": selectedPaymentMethod ?? "",
|
|
553
|
+
"save_card": isSavedNewCard ? 1 : 0
|
|
554
|
+
]
|
|
555
|
+
|
|
556
|
+
// Add is_default parameter if save_card is 1
|
|
557
|
+
if isSavedNewCard {
|
|
558
|
+
params["is_default"] = "1"
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if let customerId = customerId {
|
|
562
|
+
params["customer"] = customerId
|
|
563
|
+
params["customer_id"] = customerId
|
|
564
|
+
} else {
|
|
565
|
+
params["username"] = emailPrefix
|
|
566
|
+
params["email"] = UserStoreSingleton.shared.verificationEmail
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
print(params)
|
|
570
|
+
|
|
571
|
+
do {
|
|
572
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
573
|
+
request.httpBody = jsonData
|
|
574
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
575
|
+
print("JSON Payload: \(jsonString)")
|
|
576
|
+
}
|
|
577
|
+
} catch let error {
|
|
578
|
+
print("Error creating JSON data: \(error)")
|
|
579
|
+
hideLoadingIndicator()
|
|
580
|
+
return
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
let session = URLSession.shared
|
|
584
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
585
|
+
|
|
586
|
+
DispatchQueue.main.async {
|
|
587
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if let error = error {
|
|
591
|
+
self.presentPaymentErrorVC(errorMessage: error.localizedDescription)
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
596
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid response")
|
|
597
|
+
return
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
601
|
+
if let data = serviceData {
|
|
602
|
+
do {
|
|
603
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
604
|
+
print("Response Data: \(responseObject)")
|
|
605
|
+
|
|
606
|
+
// Check if status is 0 and handle the error
|
|
607
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
608
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
609
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
610
|
+
} else {
|
|
611
|
+
DispatchQueue.main.async {
|
|
612
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
613
|
+
paymentDoneVC.chargeData = responseObject
|
|
614
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
615
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate
|
|
616
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
622
|
+
}
|
|
623
|
+
} catch let jsonError {
|
|
624
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
625
|
+
}
|
|
626
|
+
} else {
|
|
627
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
task.resume()
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
//MARK: - Banking Account Charge Api
|
|
637
|
+
func accountChargeApi() {
|
|
638
|
+
showLoadingIndicator()
|
|
639
|
+
|
|
640
|
+
// var components = URLComponents()
|
|
641
|
+
// components.scheme = "https"
|
|
642
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
643
|
+
// components.path = "/api/v1/ach/charge"
|
|
644
|
+
//
|
|
645
|
+
// guard let serviceURL = components.url else {
|
|
646
|
+
// print("Invalid URL")
|
|
647
|
+
// hideLoadingIndicator()
|
|
648
|
+
// return
|
|
649
|
+
// }
|
|
650
|
+
|
|
651
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
652
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
|
|
653
|
+
|
|
654
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
655
|
+
print("Invalid URL")
|
|
656
|
+
hideLoadingIndicator()
|
|
657
|
+
return
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
var request = URLRequest(url: serviceURL)
|
|
661
|
+
request.httpMethod = "POST"
|
|
662
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
663
|
+
|
|
664
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
665
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
666
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
667
|
+
|
|
668
|
+
guard let billingInfoData = billingInfoData else {
|
|
669
|
+
print("Billing info data is nil")
|
|
670
|
+
return
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Remove the flag and "+" sign from lblCountryCode.text
|
|
674
|
+
let countryCode = lblCountryCode.text ?? ""
|
|
675
|
+
let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
|
|
676
|
+
// Format phone number parameter by combining cleaned country code and phone number
|
|
677
|
+
let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
|
|
678
|
+
|
|
679
|
+
let additionalInfo: [String: Any] = [
|
|
680
|
+
"name": txtFieldName.text ?? "",
|
|
681
|
+
"email": txtFieldEmail.text ?? "",
|
|
682
|
+
// "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
|
|
683
|
+
"phone_number": phoneNumber,
|
|
684
|
+
"description": txtFieldDescription.text ?? ""
|
|
685
|
+
]
|
|
686
|
+
|
|
687
|
+
let billingInfo: [String: Any] = [
|
|
688
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
689
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
690
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
691
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
692
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
693
|
+
]
|
|
694
|
+
|
|
695
|
+
let params: [String: Any] = [
|
|
696
|
+
"name": txtFieldName.text ?? "",
|
|
697
|
+
"email": txtFieldEmail.text ?? "",
|
|
698
|
+
"description": txtFieldDescription.text ?? "",
|
|
699
|
+
"currency": "usd",
|
|
700
|
+
"billing_info": billingInfo,
|
|
701
|
+
"additional_info": additionalInfo,
|
|
702
|
+
"account_type": accountType?.lowercased() ?? "",
|
|
703
|
+
"routing_number": routingNumber ?? "",
|
|
704
|
+
"account_number": accountNumber ?? "",
|
|
705
|
+
"payment_mode": "auth_and_capture",
|
|
706
|
+
"payment_intent": UserStoreSingleton.shared.paymentIntent ?? "",
|
|
707
|
+
"levelIndicator": 1,
|
|
708
|
+
]
|
|
709
|
+
|
|
710
|
+
print(params)
|
|
711
|
+
|
|
712
|
+
do {
|
|
713
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
714
|
+
request.httpBody = jsonData
|
|
715
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
716
|
+
print("JSON Payload: \(jsonString)")
|
|
717
|
+
}
|
|
718
|
+
} catch let error {
|
|
719
|
+
print("Error creating JSON data: \(error)")
|
|
720
|
+
hideLoadingIndicator()
|
|
721
|
+
return
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
let session = URLSession.shared
|
|
725
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
726
|
+
|
|
727
|
+
DispatchQueue.main.async {
|
|
728
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if let error = error {
|
|
732
|
+
print("Error: \(error.localizedDescription)")
|
|
733
|
+
return
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
737
|
+
print("Invalid response")
|
|
738
|
+
return
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
742
|
+
if let data = serviceData {
|
|
743
|
+
do {
|
|
744
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
745
|
+
print("Response Data: \(responseObject)")
|
|
746
|
+
|
|
747
|
+
// Check if status is 0 and handle the error
|
|
748
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
749
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
750
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
751
|
+
} else {
|
|
752
|
+
DispatchQueue.main.async {
|
|
753
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
754
|
+
paymentDoneVC.chargeData = responseObject
|
|
755
|
+
// Pass the selected payment method
|
|
756
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
757
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate // Pass the delegate
|
|
758
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
} else {
|
|
763
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
764
|
+
}
|
|
765
|
+
} catch let jsonError {
|
|
766
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
767
|
+
}
|
|
768
|
+
} else {
|
|
769
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
770
|
+
}
|
|
771
|
+
} else {
|
|
772
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
task.resume()
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
//MARK: - Banking Account Charge Api from Regular saved bank account
|
|
779
|
+
func accountChargeSavedBankAccountApi() {
|
|
780
|
+
showLoadingIndicator()
|
|
781
|
+
|
|
782
|
+
// var components = URLComponents()
|
|
783
|
+
// components.scheme = "https"
|
|
784
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
785
|
+
// components.path = "/api/v1/ach/charge"
|
|
786
|
+
//
|
|
787
|
+
// guard let serviceURL = components.url else {
|
|
788
|
+
// print("Invalid URL")
|
|
789
|
+
// hideLoadingIndicator()
|
|
790
|
+
// return
|
|
791
|
+
// }
|
|
792
|
+
|
|
793
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
794
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
|
|
795
|
+
|
|
796
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
797
|
+
print("Invalid URL")
|
|
798
|
+
hideLoadingIndicator()
|
|
799
|
+
return
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
var request = URLRequest(url: serviceURL)
|
|
803
|
+
request.httpMethod = "POST"
|
|
804
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
805
|
+
|
|
806
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
807
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
808
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
809
|
+
|
|
810
|
+
guard let billingInfoData = billingInfoData else {
|
|
811
|
+
print("Billing info data is nil")
|
|
812
|
+
return
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// Remove the flag and "+" sign from lblCountryCode.text
|
|
816
|
+
let countryCode = lblCountryCode.text ?? ""
|
|
817
|
+
let cleanedCountryCode = countryCode.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression)
|
|
818
|
+
// Format phone number parameter by combining cleaned country code and phone number
|
|
819
|
+
let phoneNumber = "\(cleanedCountryCode)\(txtFieldPhoneNumber.text ?? "")"
|
|
820
|
+
|
|
821
|
+
let additionalInfo: [String: Any] = [
|
|
822
|
+
"name": txtFieldName.text ?? "",
|
|
823
|
+
"email": txtFieldEmail.text ?? "",
|
|
824
|
+
// "phone_number": "\("1") \(txtFieldPhoneNumber.text ?? "")",
|
|
825
|
+
"phone_number": phoneNumber,
|
|
826
|
+
"description": txtFieldDescription.text ?? ""
|
|
827
|
+
]
|
|
828
|
+
|
|
829
|
+
let billingInfo: [String: Any] = [
|
|
830
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
831
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
832
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
833
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
834
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
835
|
+
]
|
|
836
|
+
|
|
837
|
+
let params: [String: Any] = [
|
|
838
|
+
"name": UserStoreSingleton.shared.merchantName ?? "",
|
|
839
|
+
"account_id": accountID ?? "",
|
|
840
|
+
"payment_method": "ach",
|
|
841
|
+
"customer": customerID ?? "",
|
|
842
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
843
|
+
"description": txtFieldDescription.text ?? "",
|
|
844
|
+
"currency": "usd",
|
|
845
|
+
"billing_info": billingInfo,
|
|
846
|
+
"additional_info": additionalInfo
|
|
847
|
+
]
|
|
848
|
+
|
|
849
|
+
print(params)
|
|
850
|
+
|
|
851
|
+
do {
|
|
852
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
853
|
+
request.httpBody = jsonData
|
|
854
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
855
|
+
print("JSON Payload: \(jsonString)")
|
|
856
|
+
}
|
|
857
|
+
} catch let error {
|
|
858
|
+
print("Error creating JSON data: \(error)")
|
|
859
|
+
hideLoadingIndicator()
|
|
860
|
+
return
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
let session = URLSession.shared
|
|
864
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
865
|
+
|
|
866
|
+
DispatchQueue.main.async {
|
|
867
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if let error = error {
|
|
871
|
+
print("Error: \(error.localizedDescription)")
|
|
872
|
+
return
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
876
|
+
print("Invalid response")
|
|
877
|
+
return
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
881
|
+
if let data = serviceData {
|
|
882
|
+
do {
|
|
883
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
884
|
+
print("Response Data: \(responseObject)")
|
|
885
|
+
|
|
886
|
+
// Check if status is 0 and handle the error
|
|
887
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
888
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
889
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
890
|
+
} else {
|
|
891
|
+
DispatchQueue.main.async {
|
|
892
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
893
|
+
paymentDoneVC.chargeData = responseObject
|
|
894
|
+
// Pass the selected payment method
|
|
895
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
896
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate // Pass the delegate
|
|
897
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
903
|
+
}
|
|
904
|
+
} catch let jsonError {
|
|
905
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
906
|
+
}
|
|
907
|
+
} else {
|
|
908
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
909
|
+
}
|
|
910
|
+
} else {
|
|
911
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
task.resume()
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
//MARK: - Account Charge Api if user saved the account.
|
|
918
|
+
func accountChargeApi(customerId: String?) {
|
|
919
|
+
showLoadingIndicator()
|
|
920
|
+
|
|
921
|
+
// var components = URLComponents()
|
|
922
|
+
// components.scheme = "https"
|
|
923
|
+
// components.host = "stage-api.stage-easymerchant.io"
|
|
924
|
+
// components.path = "/api/v1/ach/charge"
|
|
925
|
+
//
|
|
926
|
+
// guard let serviceURL = components.url else {
|
|
927
|
+
// print("Invalid URL")
|
|
928
|
+
// hideLoadingIndicator()
|
|
929
|
+
// return
|
|
930
|
+
// }
|
|
931
|
+
|
|
932
|
+
// Construct the full URL using baseURL from EnvironmentConfig and path from the endpoint
|
|
933
|
+
let fullURL = EnvironmentConfig.baseURL + EnvironmentConfig.Endpoints.achCharge.path()
|
|
934
|
+
|
|
935
|
+
guard let serviceURL = URL(string: fullURL) else {
|
|
936
|
+
print("Invalid URL")
|
|
937
|
+
hideLoadingIndicator()
|
|
938
|
+
return
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
var request = URLRequest(url: serviceURL)
|
|
942
|
+
request.httpMethod = "POST"
|
|
943
|
+
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
944
|
+
|
|
945
|
+
let token = UserStoreSingleton.shared.clientToken
|
|
946
|
+
print("Setting clientToken header: \(token ?? "None")")
|
|
947
|
+
request.addValue(token ?? "", forHTTPHeaderField: "Client-Token")
|
|
948
|
+
|
|
949
|
+
guard let billingInfoData = billingInfoData else {
|
|
950
|
+
print("Billing info data is nil")
|
|
951
|
+
return
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
let additionalInfoFromBilling = billingInfoData["additional_info"] as? [String: Any] ?? [:]
|
|
955
|
+
|
|
956
|
+
let additionalInfo: [String: Any] = [
|
|
957
|
+
"name": additionalInfoFromBilling["name"] as? String ?? "",
|
|
958
|
+
"email": additionalInfoFromBilling["email"] as? String ?? "",
|
|
959
|
+
"phone_number": additionalInfoFromBilling["phone_number"] as? String ?? "",
|
|
960
|
+
"description": additionalInfoFromBilling["description"] as? String ?? ""
|
|
961
|
+
]
|
|
962
|
+
|
|
963
|
+
let billingInfo: [String: Any] = [
|
|
964
|
+
"address": billingInfoData["address"] as? String ?? "",
|
|
965
|
+
"country": billingInfoData["country"] as? String ?? "",
|
|
966
|
+
"state": billingInfoData["state"] as? String ?? "",
|
|
967
|
+
"city": billingInfoData["city"] as? String ?? "",
|
|
968
|
+
"postal_code": billingInfoData["postal_code"] as? String ?? ""
|
|
969
|
+
]
|
|
970
|
+
|
|
971
|
+
let emailPrefix = UserStoreSingleton.shared.verificationEmail?.components(separatedBy: "@").first ?? ""
|
|
972
|
+
|
|
973
|
+
var params: [String: Any] = [
|
|
974
|
+
"name": additionalInfoFromBilling["name"] as? String ?? "",
|
|
975
|
+
"email": UserStoreSingleton.shared.verificationEmail ?? "",
|
|
976
|
+
"description": additionalInfoFromBilling["description"] as? String ?? "",
|
|
977
|
+
"currency": "usd",
|
|
978
|
+
"billing_info": billingInfo,
|
|
979
|
+
"additional_info": additionalInfo,
|
|
980
|
+
"account_type": accountType?.lowercased() ?? "",
|
|
981
|
+
"routing_number": routingNumber ?? "",
|
|
982
|
+
"account_number": accountNumber ?? "",
|
|
983
|
+
"payment_mode": "auth_and_capture",
|
|
984
|
+
"payment_intent": UserStoreSingleton.shared.paymentIntent ?? "",
|
|
985
|
+
"levelIndicator": 1,
|
|
986
|
+
"save_account": 1,
|
|
987
|
+
"payment_method": "ach"
|
|
988
|
+
]
|
|
989
|
+
|
|
990
|
+
if let customerId = customerId {
|
|
991
|
+
params["customer"] = customerId
|
|
992
|
+
} else {
|
|
993
|
+
params["username"] = emailPrefix
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
print(params)
|
|
997
|
+
|
|
998
|
+
do {
|
|
999
|
+
let jsonData = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
1000
|
+
request.httpBody = jsonData
|
|
1001
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
1002
|
+
print("JSON Payload: \(jsonString)")
|
|
1003
|
+
}
|
|
1004
|
+
} catch let error {
|
|
1005
|
+
print("Error creating JSON data: \(error)")
|
|
1006
|
+
hideLoadingIndicator()
|
|
1007
|
+
return
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
let session = URLSession.shared
|
|
1011
|
+
let task = session.dataTask(with: request) { (serviceData, serviceResponse, error) in
|
|
1012
|
+
|
|
1013
|
+
DispatchQueue.main.async {
|
|
1014
|
+
self.hideLoadingIndicator() // Stop loader when response is received
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
if let error = error {
|
|
1018
|
+
self.presentPaymentErrorVC(errorMessage: error.localizedDescription)
|
|
1019
|
+
return
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
guard let httpResponse = serviceResponse as? HTTPURLResponse else {
|
|
1023
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid response")
|
|
1024
|
+
return
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 {
|
|
1028
|
+
if let data = serviceData {
|
|
1029
|
+
do {
|
|
1030
|
+
if let responseObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
|
1031
|
+
print("Response Data: \(responseObject)")
|
|
1032
|
+
|
|
1033
|
+
// Check if status is 0 and handle the error
|
|
1034
|
+
if let status = responseObject["status"] as? Int, status == 0 {
|
|
1035
|
+
let errorMessage = responseObject["message"] as? String ?? "Unknown error"
|
|
1036
|
+
self.presentPaymentErrorVC(errorMessage: errorMessage)
|
|
1037
|
+
} else {
|
|
1038
|
+
DispatchQueue.main.async {
|
|
1039
|
+
if let paymentDoneVC = self.storyboard?.instantiateViewController(withIdentifier: "PaymentDoneVC") as? PaymentDoneVC {
|
|
1040
|
+
paymentDoneVC.chargeData = responseObject
|
|
1041
|
+
paymentDoneVC.selectedPaymentMethod = self.selectedPaymentMethod
|
|
1042
|
+
paymentDoneVC.easyPayDelegate = self.easyPayDelegate
|
|
1043
|
+
self.navigationController?.pushViewController(paymentDoneVC, animated: true)
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
self.presentPaymentErrorVC(errorMessage: "Invalid JSON format")
|
|
1049
|
+
}
|
|
1050
|
+
} catch let jsonError {
|
|
1051
|
+
self.presentPaymentErrorVC(errorMessage: "Error parsing JSON: \(jsonError)")
|
|
1052
|
+
}
|
|
1053
|
+
} else {
|
|
1054
|
+
self.presentPaymentErrorVC(errorMessage: "No data received")
|
|
1055
|
+
}
|
|
1056
|
+
} else {
|
|
1057
|
+
self.presentPaymentErrorVC(errorMessage: "HTTP Status Code: \(httpResponse.statusCode)")
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
task.resume()
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
extension AdditionalInfoVC: UITextFieldDelegate {
|
|
1066
|
+
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
extension AdditionalInfoVC: CountryListVCDelegate {
|
|
1070
|
+
func didSelectCountry(_ country: Country) {
|
|
1071
|
+
lblCountryCode.text = "\(country.flag ?? "") +\(country.extensionCode ?? "")"
|
|
1072
|
+
}
|
|
1073
|
+
}
|