Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CommonPaymentListVC.swift
- // CreatedApp
- //
- // Created by Tushar on 21/01/20.
- //
- import UIKit
- class CommonPaymentListVC: PAGEMainViewController,HeaderDelegate {
- var paymentSettingList:Array<Dictionary<String,Any>> = []
- var userPaymentDetails : UserPaymentDetails?
- weak var paymentDelegate: CommonPaymentDelegate? = nil
- @IBOutlet weak var parentView: UIView!
- @IBOutlet weak var headView: UIView!
- @IBOutlet weak var lbl_Amounttxt: UILabel!
- @IBOutlet weak var lbl_Amount: UILabel!
- @IBOutlet weak var subHeadView: UIView!
- @IBOutlet weak var lbl_Subhead: UILabel!
- @IBOutlet weak var paymentTableViewController: UITableView!
- override func viewDidLoad() {
- self.addHeader(type: AppManager.shared.getheaderBarType(), disableheaderImage_forinnerpages: AppManager.shared.getinnerNavbarImage())
- super.viewDidLoad()
- self.header?.delegate = self
- navigationPageuiSetup()
- setupStyleNavigationSetup()
- }
- override func viewWillAppear(_ animated: Bool) {
- makeNavbarHidden()
- super.viewWillAppear(animated)
- }
- }
- extension CommonPaymentListVC {
- func setupStyleNavigationSetup() {
- // Setup ParentView
- self.getContainerView().addSubview(parentView)
- LayoutEngine.shared.addViewConstraints(withVw: parentView)
- self.paymentTableViewController.tableFooterView = UIView()
- }
- }
- //MARK: NAVIGATION SETUP
- extension CommonPaymentListVC {
- func navigationPageuiSetup() {
- self.setHeadersubviews(settings: [:])
- }
- private func setHeadersubviews(settings:NSDictionary) {
- do {
- try self.addHeaderSubviews(avail_leftBtn1:true , urlStr_leftBtn1:nil, avail_leftBtn2:false, urlStr_leftBtn2:nil, avail_rightBtn1:false, urlStr_rightBtn1:nil, avail_rightBtn2: false, urlStr_rightBtn2:nil, titleViewType:.LABEL)
- }catch {
- debugPrint("Header Error \(error.localizedDescription)")
- }
- self.setTitleColor(colorStr: AppManager.shared.getheaderBarTextColor(), colorType: .Hex)
- self.setTitle(font: AppManager.shared.getheaderBarFont(), fontSize: "medium", textStr:"Payment", titleType: .LABEL)
- self.header?.rightBtn1?.isHidden = true
- //Setup Amount
- lbl_Amount.text = userPaymentDetails?.amount.converIntoCurrencey() ?? ""
- }
- }
- //Handle Events and Setup View
- extension CommonPaymentListVC {
- func clickOn_leftbtn1(sender: UIButton) {
- DispatchQueue.main.async {
- self.dismiss(animated: true)
- }
- }
- }
- //Table View Controller
- extension CommonPaymentListVC :UITableViewDataSource,UITableViewDelegate
- {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if(self.paymentSettingList.count > 0){
- return self.paymentSettingList.count
- }
- var imageView : UIImageView
- imageView = UIImageView(frame:CGRect(x: 0,
- y: 0,
- width: paymentTableViewController.bounds.size.width,
- height: paymentTableViewController.bounds.size.height));
- imageView.image = UIImage(named: "NoData_icon")?.tint(with: ("#a9a9a9").setColorFromString());
- imageView.contentMode = .center;
- paymentTableViewController.backgroundView = imageView
- paymentTableViewController.separatorStyle = .none
- return 0
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier:"PaymentListCell") as! PaymentListCell;
- cell.selectionStyle = UITableViewCell.SelectionStyle.none;
- cell.separatorInset = UIEdgeInsets.zero;
- if let payment = self.paymentSettingList[safe : indexPath.row] {
- cell.setValueInCell(cellData : payment)
- }
- return cell
- }
- //TableView DelegateMethod
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if let paymentData = paymentSettingList[indexPath.row] as? Dictionary<String,Any> {
- didClickPaymentMethod(withPaymentData: paymentData)
- }
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 60
- }
- }
- extension CommonPaymentListVC {
- func getPaymentDetails(withFlag:String,withPaymentData:Dictionary<String,Any>)->String{
- let paymentKey = withPaymentData["key"] as? String
- let paymentCredentials = withPaymentData["credentials"] as? Dictionary<String,Any>
- var apiURL = ""
- var paymentMethod = ""
- switch paymentKey {
- case "cod":
- apiURL = paymentCredentials?["cod_api_url"] as? String ?? ""
- paymentMethod = "getCodForm"
- break;
- case "pu":
- apiURL = paymentCredentials?["pu_api_url"] as? String ?? ""
- paymentMethod = "getPuForm"
- break;
- case "cc_phone":
- apiURL = paymentCredentials?["cc_phone_api_url"] as? String ?? ""
- paymentMethod = "getCcPhoneForm"
- break;
- case "mercado":
- apiURL = paymentCredentials?["mercado_api_url"] as? String ?? ""
- paymentMethod = "getMercadoForm"
- break;
- case "paypal":
- apiURL = paymentCredentials?["paypal_api_url"] as? String ?? ""
- paymentMethod = "getPaypalExpressForm"
- break;
- case "stripe":
- apiURL = paymentCredentials?["stripe_api_url"] as? String ?? ""
- paymentMethod = "getStripeForm"
- break;
- case "velocity":
- apiURL = paymentCredentials?["velocity_api_url"] as? String ?? ""
- paymentMethod = "velocityForm"
- break;
- case "payu_money":
- apiURL = paymentCredentials?["payu_money_api_url"] as? String ?? ""
- paymentMethod = "getPayuForm"
- break;
- case "braintree":
- apiURL = paymentCredentials?["braintree_api_url"] as? String ?? ""
- paymentMethod = "braintreeDirectForm"
- break;
- case "payfast":
- apiURL = paymentCredentials?["velocity_api_url"] as? String ?? ""
- paymentMethod = "getPayfastForm"
- break;
- case "pesapal":
- apiURL = paymentCredentials?["pesapal_api_url"] as? String ?? ""
- paymentMethod = "getPesapalForm"
- break;
- case "authorize":
- apiURL = paymentCredentials?["authorize_api_url"] as? String ?? ""
- paymentMethod = "getAuthorizeForm"
- break;
- case "boleto":
- apiURL = paymentCredentials?["boleto_api_url"] as? String ?? ""
- paymentMethod = "getBoletoForm"
- break;
- case "hubtel":
- apiURL = paymentCredentials?["hubtel_api_url"] as? String ?? ""
- paymentMethod = "getHubtelForm"
- break;
- default:
- break;
- }
- if(withFlag == "apiurl"){
- return apiURL
- }
- return paymentMethod
- }
- func didClickPaymentMethod(withPaymentData:Dictionary<String,Any>){
- let query = GetCommonPaymentFormQuery(
- api_url: getPaymentDetails(withFlag: "apiurl", withPaymentData: withPaymentData) ,
- method: getPaymentDetails(withFlag: "method", withPaymentData: withPaymentData),
- appId: userPaymentDetails?.appId,
- pageId: userPaymentDetails?.pageId,
- pagename: userPaymentDetails?.pagename,
- orderDesc: userPaymentDetails?.orderDesc,
- amount: userPaymentDetails?.amount,
- orderId: userPaymentDetails?.orderId,
- fName: userPaymentDetails?.fName,
- mobile: userPaymentDetails?.mobile,
- currency: userPaymentDetails?.currency,
- email: userPaymentDetails?.email,
- pname: userPaymentDetails?.pname,
- quantity: userPaymentDetails?.quantity,
- pinfo: userPaymentDetails?.pinfo,
- itemName: userPaymentDetails?.itemName,
- userId: userPaymentDetails?.userId
- )
- MBProgressHUD.showAdded(to: self.view, animated: true)
- AWSAPIManager.shared.awsApiRequest(queryRequest: query) { (result) in
- DispatchQueue.main.async {[unowned self] in
- MBProgressHUD.hide(for: self.view, animated: true)
- if let dictionary = (result?.getCommonPaymentForm?.jsonObject) , let error_message = dictionary["error_message"] as? String , let error_code = dictionary["error_code"] as? String{
- if(error_code != "0" && error_message != "Success"){
- self.dismiss(animated: true, completion: {[] in
- self.paymentDelegate?.paymentFailure?(responseData: dictionary)
- })
- return;
- }
- //Success Method
- self.getPaymentFormSuccess(withPaymentData:withPaymentData , withResponseData:dictionary)
- }
- }
- }
- }
- func getPaymentFormSuccess(withPaymentData:Dictionary<String,Any>,withResponseData:Dictionary<String,Any>){
- let paymentKey = withPaymentData["key"] as? String;
- switch paymentKey{
- case "pu","cod","cc_phone":
- self.dismiss(animated: true, completion: {[] in
- self.paymentDelegate?.paymentSuccess?(responseData: withResponseData)
- })
- break;
- default:
- self.navigateToWebView(withPaymentData:withPaymentData,withResponseData:withResponseData)
- break;
- }
- }
- func navigateToWebView(withPaymentData:Dictionary<String,Any>,withResponseData:Dictionary<String,Any>){
- let story = UIStoryboard.init(name: "HyperStore", bundle: nil)
- let viewcontroller : PaymentWebviewVC = story.instantiateViewController(withIdentifier: "PaymentWebviewVC") as! PaymentWebviewVC
- viewcontroller.paymentDelegate = paymentDelegate
- viewcontroller.userPaymentDetails = userPaymentDetails
- viewcontroller.paymentData = withPaymentData
- viewcontroller.responseData = withResponseData
- viewcontroller.modalPresentationStyle = .fullScreen
- self.navigationController?.present(viewcontroller, animated: true, completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement