You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.7 KiB

  1. //
  2. // SendMoneyVerificationViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class SendMoneyVerificationViewController: UITableViewController {
  10. // MARK: IBOutlets
  11. // Recievers Details
  12. @IBOutlet weak var fullNameLabel: UILabel!
  13. @IBOutlet weak var addressLabel: UILabel!
  14. @IBOutlet weak var countryLabel: UILabel!
  15. @IBOutlet weak var mobileLabel: UILabel!
  16. // Transation Details
  17. @IBOutlet weak var payoutCountryLabel: UILabel!
  18. @IBOutlet weak var payoutModeLabel: UILabel!
  19. @IBOutlet weak var payingAmountLabel: UILabel!
  20. @IBOutlet weak var exchangeRateLabel: UILabel!
  21. @IBOutlet weak var serviceChargeLabel: UILabel!
  22. @IBOutlet weak var payoutAgentBankLabel: UILabel!
  23. var url: String?
  24. // MARK: Properties
  25. var presenter: SendMoneyVerificationModuleInterface?
  26. var reciepient: Recipient?
  27. var requestModel: SendMoneyRequestModel?
  28. var hudDelegate: HUDStatusDelegate?
  29. var password: String? {
  30. didSet {
  31. if let model = self.requestModel, let reciepient = self.reciepient {
  32. model.transactionPassword = password ?? ""
  33. self.presenter?.submit(model: model, reciepient: reciepient)
  34. }
  35. }
  36. }
  37. // MARK: VC's Life cycle
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. self.setup()
  41. }
  42. override func viewWillAppear(_ animated: Bool) {
  43. super.viewWillAppear(animated)
  44. populateRecieversInformations()
  45. populateTransactionDetails()
  46. }
  47. // MARK: IBActions
  48. // @IBOutlet weak var usewUserAgreement: UIButton!
  49. @IBAction func showUserAgreement(_ sender: UIButton) {
  50. let webController = UIStoryboard.init(name: "Storyboard", bundle: nil).instantiateViewController(withIdentifier: "WebLinksViewController") as! WebLinksViewController
  51. webController.titleString = "User Agreement"
  52. webController.url = self.url ?? "https://online.gmeremit.com/Terms"
  53. let nav = UINavigationController.init(rootViewController: webController)
  54. self.present(nav, animated: true, completion: nil)
  55. // self.navigationController?.pushViewController(webController, animated: true)
  56. }
  57. @IBAction func submit(_ sender: UIButton) {
  58. self.askPassword()
  59. // submit the request model
  60. }
  61. // MARK: Other Functions
  62. private func setup() {
  63. }
  64. private func populateRecieversInformations() {
  65. self.fullNameLabel.text = self.reciepient?.getFullName()
  66. self.addressLabel.text = self.reciepient?.address
  67. self.countryLabel.text = self.reciepient?.country
  68. self.mobileLabel.text = self.reciepient?.mobileNumber
  69. }
  70. private func populateTransactionDetails() {
  71. self.payoutCountryLabel.text = self.reciepient?.country
  72. self.payoutModeLabel.text = self.requestModel?.paymemtMode?.mode
  73. self.payingAmountLabel.text = (self.requestModel?.exchangeRateDetail?.recipientAmount ?? "") + " \(self.requestModel?.exchangeRateDetail?.reciepientCurrency ?? "")"
  74. self.exchangeRateLabel.text = self.requestModel?.exchangeRateDetail?.exchangeRate
  75. self.serviceChargeLabel.text = self.requestModel?.exchangeRateDetail?.transferFee
  76. self.payoutAgentBankLabel.text = self.requestModel?.bank?.name
  77. }
  78. func askPassword() {
  79. let alertController = UIAlertController(title: "Enter your login password", message: "", preferredStyle: .alert)
  80. alertController.addTextField { (textField : UITextField!) -> Void in
  81. textField.placeholder = "Enter password"
  82. textField.isSecureTextEntry = true
  83. textField.tag = 51
  84. // textField.delegate = self
  85. }
  86. let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: {
  87. alert -> Void in
  88. let passwordTextField = alertController.textFields![0] as UITextField
  89. if passwordTextField.text! != "" {
  90. self.password = passwordTextField.text!
  91. } else {
  92. self.alert(message: "Password was missing")
  93. }
  94. })
  95. let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: {
  96. (action : UIAlertAction!) -> Void in
  97. })
  98. cancelAction.setValue(UIColor.black, forKey: "titleTextColor")
  99. confirmAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
  100. alertController.addAction(cancelAction)
  101. alertController.addAction(confirmAction)
  102. self.present(alertController, animated: true, completion: nil)
  103. }
  104. }
  105. // MARK: SendMoneyVerificationViewInterface
  106. extension SendMoneyVerificationViewController: SendMoneyVerificationViewInterface {
  107. func show(model: SendMoneySubmitModelContainer?) {
  108. self.alertWithOk(message: model?.message , title: "Success", okTitle: "OK", style: UIAlertControllerStyle.alert, OkStyle: .default) {
  109. if let id = model?.id {
  110. self.presenter?.openReciept(transactionId: id)
  111. }else {
  112. self.alert(message: "No Transaction recievied.")
  113. }
  114. }
  115. }
  116. func show(error: String) {
  117. // self.presenter?.openReciept(transactionId: "1235")
  118. self.alert(message: error)
  119. }
  120. func showLoading() {
  121. self.hudDelegate?.showLoading()
  122. }
  123. func hideLoading() {
  124. self.hudDelegate?.hideLoading()
  125. }
  126. }
  127. extension SendMoneyVerificationViewController {
  128. override func didMove(toParentViewController parent: UIViewController?) {
  129. self.viewWillAppear(true)
  130. }
  131. }