From 551e547aa0a117b3b251cf4f23a2c320ae58b1fb Mon Sep 17 00:00:00 2001 From: gme_2 Date: Mon, 3 Sep 2018 16:00:13 +0900 Subject: [PATCH] password added in model --- .../View/SendMoneyParentViewController.swift | 1 + .../SendMoneyVerificationInteractor.swift | 6 +- .../SendMoneyVerificationInteractorIO.swift | 3 +- .../SendMoneyVerificationServiceType.swift | 23 +++++++- .../SendMoneyVerificationPresenter.swift | 11 ++++ .../SendMoneyVerificationViewController.swift | 55 ++++++++++++++++++- .../SendMoneyVerificationViewInterface.swift | 1 + .../RecipientListViewController.storyboard | 2 +- 8 files changed, 94 insertions(+), 8 deletions(-) diff --git a/GMERemittance/Module/SendMoneyParent/User Interface/View/SendMoneyParentViewController.swift b/GMERemittance/Module/SendMoneyParent/User Interface/View/SendMoneyParentViewController.swift index 55fcc841..b4fc3526 100644 --- a/GMERemittance/Module/SendMoneyParent/User Interface/View/SendMoneyParentViewController.swift +++ b/GMERemittance/Module/SendMoneyParent/User Interface/View/SendMoneyParentViewController.swift @@ -40,6 +40,7 @@ class SendMoneyRequestModel { var accountNumber: String? var payingAmount: String? var exchangeRateDetail: SendMoneyExchangeRateModel? + var transactionPassword: String? } class SendMoneyParentViewController: UIViewController { diff --git a/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractor.swift b/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractor.swift index 1db76601..69013721 100644 --- a/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractor.swift +++ b/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractor.swift @@ -30,7 +30,11 @@ extension SendMoneyVerificationInteractor: SendMoneyVerificationInteractorInput func submit(model: SendMoneyRequestModel, reciepient: Recipient) { guard let username = UserDefaults.standard.value(forKey: UserKeys.userId) as? String else {return} let params = self.getParams(model: model, reciepient: reciepient, userName: username) - + self.service.submit(params: params, success: { (response) in + self.output?.show(model: response) + }) { (error) in + self.output?.show(error: error) + } } func getParams(model: SendMoneyRequestModel, reciepient: Recipient, userName: String) -> [String: String] { diff --git a/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractorIO.swift b/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractorIO.swift index c1249dc3..b62d2a55 100644 --- a/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractorIO.swift +++ b/GMERemittance/Module/SendMoneyVerification/Application Logic/Interactor/SendMoneyVerificationInteractorIO.swift @@ -11,5 +11,6 @@ protocol SendMoneyVerificationInteractorInput: class { } protocol SendMoneyVerificationInteractorOutput: class { - + func show(error: Error) + func show(model: SendMoneySubmitModel?) } diff --git a/GMERemittance/Module/SendMoneyVerification/Application Logic/Service/SendMoneyVerificationServiceType.swift b/GMERemittance/Module/SendMoneyVerification/Application Logic/Service/SendMoneyVerificationServiceType.swift index dbf5e085..0d1795c9 100644 --- a/GMERemittance/Module/SendMoneyVerification/Application Logic/Service/SendMoneyVerificationServiceType.swift +++ b/GMERemittance/Module/SendMoneyVerification/Application Logic/Service/SendMoneyVerificationServiceType.swift @@ -8,11 +8,30 @@ import Foundation -protocol SendMoneyVerificationServiceType: class { +protocol SendMoneyVerificationServiceType: class, SendMoneyVerificationSubmitApi { } protocol SendMoneyVerificationSubmitApi: ApiServiceType { - func submit(params: [String: String]) + func submit(params: [String: String], success: @escaping (SendMoneySubmitModel?) -> (), failure: @escaping (Error) -> ()) +} + + +extension SendMoneyVerificationSubmitApi { + func submit(params: [String: String], success: @escaping (SendMoneySubmitModel?) -> (), failure: @escaping (Error) -> ()) { + let url = baseUrl + "mobile/sendmoney/dotransaction" + self.auth.request(method: .post, url: url, params: params, success: { (response: SendMoneySubmitModelContainer) in + if (response.errorCode ?? "") == "1" { + let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + failure(error) + }else { + let model = response.data + success(model) + } + }) { (error) in + failure(error) + } + + } } diff --git a/GMERemittance/Module/SendMoneyVerification/User Interface/Presenter/SendMoneyVerificationPresenter.swift b/GMERemittance/Module/SendMoneyVerification/User Interface/Presenter/SendMoneyVerificationPresenter.swift index 8d8616a1..f39d01a5 100644 --- a/GMERemittance/Module/SendMoneyVerification/User Interface/Presenter/SendMoneyVerificationPresenter.swift +++ b/GMERemittance/Module/SendMoneyVerification/User Interface/Presenter/SendMoneyVerificationPresenter.swift @@ -25,6 +25,7 @@ class SendMoneyVerificationPresenter { extension SendMoneyVerificationPresenter: SendMoneyVerificationModuleInterface { func submit(model: SendMoneyRequestModel, reciepient: Recipient) { + self.view?.showLoading() self.interactor?.submit(model: model, reciepient: reciepient) } } @@ -32,5 +33,15 @@ extension SendMoneyVerificationPresenter: SendMoneyVerificationModuleInterface { // MARK: SendMoneyVerification interactor output interface extension SendMoneyVerificationPresenter: SendMoneyVerificationInteractorOutput { + func show(error: Error) { + self.view?.hideLoading() + self.view?.show(error: error.localizedDescription) + } + + func show(model: SendMoneySubmitModel?) { + self.view?.hideLoading() + self.view?.show(model: model) + } + } diff --git a/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewController.swift b/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewController.swift index bf5ae1d0..dc6fcc09 100644 --- a/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewController.swift +++ b/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewController.swift @@ -36,6 +36,15 @@ class SendMoneyVerificationViewController: UITableViewController { var reciepient: Recipient? var requestModel: SendMoneyRequestModel? var hudDelegate: HUDStatusDelegate? + + var password: String? { + didSet { + if let model = self.requestModel, let reciepient = self.reciepient { + model.transactionPassword = password ?? "" + self.presenter?.submit(model: model, reciepient: reciepient) + } + } + } // MARK: VC's Life cycle @@ -59,10 +68,9 @@ class SendMoneyVerificationViewController: UITableViewController { return } + self.askPassword() + // submit the request model - if let model = self.requestModel, let reciepient = self.reciepient { - self.presenter?.submit(model: model, reciepient: reciepient) - } } // MARK: Other Functions @@ -94,10 +102,48 @@ class SendMoneyVerificationViewController: UITableViewController { self.serviceChargeLabel.text = self.requestModel?.exchangeRateDetail?.transferFee self.payoutAgentBankLabel.text = self.requestModel?.bank?.name } + + + func askPassword() { + let alertController = UIAlertController(title: "Enter your login password", message: "", preferredStyle: .alert) + + alertController.addTextField { (textField : UITextField!) -> Void in + textField.placeholder = "Enter password" + textField.isSecureTextEntry = true + textField.tag = 51 +// textField.delegate = self + } + + let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: { + alert -> Void in + let passwordTextField = alertController.textFields![0] as UITextField + if passwordTextField.text! != "" { + self.password = passwordTextField.text! + } else { + self.alert(message: "Password was missing") + } + }) + + let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: { + (action : UIAlertAction!) -> Void in + }) + + cancelAction.setValue(UIColor.black, forKey: "titleTextColor") + confirmAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor") + + alertController.addAction(cancelAction) + alertController.addAction(confirmAction) + + self.present(alertController, animated: true, completion: nil) + } } // MARK: SendMoneyVerificationViewInterface extension SendMoneyVerificationViewController: SendMoneyVerificationViewInterface { + func show(model: SendMoneySubmitModel?) { + print(model?.charge) + } + func show(error: String) { self.alert(message: error) } @@ -116,3 +162,6 @@ extension SendMoneyVerificationViewController { self.viewWillAppear(true) } } + + + diff --git a/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewInterface.swift b/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewInterface.swift index 90df65ec..28bac250 100644 --- a/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewInterface.swift +++ b/GMERemittance/Module/SendMoneyVerification/User Interface/View/SendMoneyVerificationViewInterface.swift @@ -10,4 +10,5 @@ protocol SendMoneyVerificationViewInterface: class { func show(error: String) func showLoading() func hideLoading() + func show(model: SendMoneySubmitModel?) } diff --git a/GMERemittance/Recipient/RecipientListViewController.storyboard b/GMERemittance/Recipient/RecipientListViewController.storyboard index 827d51ed..c527fdf0 100644 --- a/GMERemittance/Recipient/RecipientListViewController.storyboard +++ b/GMERemittance/Recipient/RecipientListViewController.storyboard @@ -855,7 +855,7 @@