From 00eb1907a944d456d0a2d2e93112799a9c5821da Mon Sep 17 00:00:00 2001 From: InKwon James Kim Date: Tue, 2 Jul 2019 09:37:06 +0900 Subject: [PATCH] renew kftc token --- GMERemittance/AppDelegate.swift | 2 +- .../Extension/UIViewControllerExtension.swift | 16 +++++- .../WebLinks/WkWebView/WKWebView.storyboard | 35 +++++++++++- .../WkWebView/WkWebViewController.swift | 12 ++++ .../View/AddAccountViewController.swift | 2 + .../Interactor/AutoDebitInteractor.swift | 34 +++++++++++ .../Interactor/AutoDebitInteractorIO.swift | 18 ++++++ .../Service/AutoDebitService.swift | 2 +- .../Service/AutoDebitServiceType.swift | 13 +++++ .../AutoDebitModuleInterface.swift | 7 +++ .../Presenter/AutoDebitPresenter.swift | 12 ++++ .../View/AutoDebitViewController.swift | 57 ++++++++++++++----- .../View/AutoDebitViewInterface.swift | 1 + .../Wireframe/AutoDebitWireframe.swift | 11 ++++ .../Wireframe/AutoDebitWireframeInput.swift | 8 +++ .../SideMenu/SideMenuViewController.swift | 3 +- GMERemittanceTests/APITest.swift | 2 +- 17 files changed, 213 insertions(+), 22 deletions(-) diff --git a/GMERemittance/AppDelegate.swift b/GMERemittance/AppDelegate.swift index 2bc18166..c2c61953 100644 --- a/GMERemittance/AppDelegate.swift +++ b/GMERemittance/AppDelegate.swift @@ -20,7 +20,7 @@ import IQKeyboardManagerSwift import LGSideMenuController import Localize_Swift -let server: Server = .stagging +let server: Server = .kftcTest var overlayView: UIView? @UIApplicationMain diff --git a/GMERemittance/Extension/UIViewControllerExtension.swift b/GMERemittance/Extension/UIViewControllerExtension.swift index 4127f772..ca6e2bb6 100644 --- a/GMERemittance/Extension/UIViewControllerExtension.swift +++ b/GMERemittance/Extension/UIViewControllerExtension.swift @@ -80,8 +80,20 @@ extension UIViewController { style: style ) - alertController.addAction(title: okTitle,style: OkStyle, handler: okAction) - alertController.addAction(title: cancelTitle, style: cancelStyle, handler: cancelAction) + let cancelAlertAction = UIAlertAction(title: cancelTitle, style: cancelStyle, handler: {_ in + cancelAction?() + }) + + let okAlertAction = UIAlertAction(title: okTitle, style: OkStyle, handler: {_ in + okAction?() + }) + + cancelAlertAction.setValue(UIColor.black, forKey: "titleTextColor") + okAlertAction.setValue(UIColor.black, forKey: "titleTextColor") + alertController.addAction(cancelAlertAction) + alertController.addAction(okAlertAction) + +// noAction.setValue(UIColor.black, forKey: "titleTextColor") self.present(alertController, animated: true, completion: nil) } diff --git a/GMERemittance/Library/WebLinks/WkWebView/WKWebView.storyboard b/GMERemittance/Library/WebLinks/WkWebView/WKWebView.storyboard index ae5041b6..55c688a0 100644 --- a/GMERemittance/Library/WebLinks/WkWebView/WKWebView.storyboard +++ b/GMERemittance/Library/WebLinks/WkWebView/WKWebView.storyboard @@ -1,11 +1,11 @@ - + - + @@ -20,10 +20,39 @@ + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + diff --git a/GMERemittance/Library/WebLinks/WkWebView/WkWebViewController.swift b/GMERemittance/Library/WebLinks/WkWebView/WkWebViewController.swift index 61538cbd..8c0fcbf7 100644 --- a/GMERemittance/Library/WebLinks/WkWebView/WkWebViewController.swift +++ b/GMERemittance/Library/WebLinks/WkWebView/WkWebViewController.swift @@ -17,6 +17,7 @@ class WkWebViewController: UIViewController { var activityIndicator: UIActivityIndicatorView? let userContentController = WKUserContentController() + @IBOutlet weak var closeButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() @@ -49,6 +50,17 @@ class WkWebViewController: UIViewController { let myRequest = URLRequest(url: myURL) webView.load(myRequest) } + + closeButton.title = "penny_test_close_text".localized() + + if let count = navigationController?.viewControllers.count, + count > 1 { + navigationItem.leftBarButtonItem = nil + } + } + + @IBAction func touchCloseButton(_ sender: UIBarButtonItem) { + dismiss(animated: true, completion: nil) } } diff --git a/GMERemittance/Module/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift b/GMERemittance/Module/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift index b3d60018..e704755c 100644 --- a/GMERemittance/Module/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift +++ b/GMERemittance/Module/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift @@ -39,10 +39,12 @@ class AddAccountViewController: UIViewController { languagePickerView.delegate = self languagePickerView.dataSource = self languageTextField.inputView = languagePickerView + languagePickerView.backgroundColor = .white bankPickerView.delegate = self bankPickerView.dataSource = self bankNameTextField.inputView = bankPickerView + bankPickerView.backgroundColor = .white let originalBanks = model.bankList?.map{ $0.bankName ?? "" } let originalLanguages = model.kftcModel?.languages?.map { $0.value ?? ""} diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift index 548e9db3..d057a69a 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift @@ -64,4 +64,38 @@ extension AutoDebitInteractor: AutoDebitInteractorInput { } ) } + + func refreshToken(language: KftcLanguage?) { + guard + let email = UserDefaults.standard.string(forKey: UserKeys.email), + let language = language else { return } + + let service2 = AddAccountService() + + service.refreshTokenStep1( + username: email, + success: { response in + let url = "\(response?.url?.replacingOccurrences(of: "&lang=", with: "&lang=\(language.key ?? "eng")") ?? "")" + var header = [String: String]() + response?.header?.forEach({ + header[$0.key ?? ""] = $0.value ?? "" + }) + + service2.fetchKftcUrlService( + url: url, + header: header, + success: { + self.output?.refreshTokenSuccess(header: response?.header, url: $0) + }, + failure: { + self.output?.refreshTokenError(with: $0) + } + ) + + }, + failure: { + self.output?.refreshTokenError(with: $0) + } + ) + } } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift index c505fdee..b634e0c8 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift @@ -18,6 +18,12 @@ protocol AutoDebitInteractorInput: class { /// - username: customer name /// - account: bank account func deleteKFTCBankAccount(of username: String, with account: Account) + + + /// Refresh Token + /// + /// - Parameter language: selected language + func refreshToken(language: KftcLanguage?) } protocol AutoDebitInteractorOutput: class { @@ -39,4 +45,16 @@ protocol AutoDebitInteractorOutput: class { /// /// - Parameter error: Error func didFailSetModel(with error: Error) + + + /// If did fail refreshToken + /// + /// - Parameter error: Error + func refreshTokenError(with error: Error) + + + /// if Succeess then get url for refresh token + /// + /// - Parameter url: String + func refreshTokenSuccess(header: [KftcHeader]?, url: String?) } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift index 49acc7b2..2e04049b 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift @@ -73,7 +73,7 @@ class AutoDebitService: AutoDebitServiceType { ) } - func refreshAccount( + func refreshTokenStep1( username: String, success: @escaping (KFTCModel?) -> Void, failure: @escaping (Error) -> Void diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitServiceType.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitServiceType.swift index 7c5a353d..55593027 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitServiceType.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitServiceType.swift @@ -35,4 +35,17 @@ protocol AutoDebitServiceType: class, ApiServiceType { success: @escaping () -> Void, failure: @escaping (Error) -> Void ) + + + /// Refresh token + /// + /// - Parameters: + /// - username: username + /// - success: (KFTCModel?) -> Void) + /// - failure: (Error) -> Void) + func refreshTokenStep1( + username: String, + success: @escaping (KFTCModel?) -> Void, + failure: @escaping (Error) -> Void + ) } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift index b1fa0431..38c95ae4 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift @@ -24,4 +24,11 @@ protocol AutoDebitModuleInterface: class { /// /// - Parameter model: KFTCModel func goAddAccount(model: KFTCModel?) + + /// Present Refresh Token + /// + /// - Parameters: + /// - model: KFTCModel + /// - selectedLanguage: KftcLanguage + func goRefreshToken(selectedLanguage: KftcLanguage?) } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift index c5f3d79b..f05e83ab 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift @@ -35,11 +35,23 @@ extension AutoDebitPresenter: AutoDebitModuleInterface { func goAddAccount(model: KFTCModel?){ wireframe?.goAddAccountViewController(with: model) } + + func goRefreshToken(selectedLanguage: KftcLanguage?) { + interactor?.refreshToken(language: selectedLanguage) + } } // MARK: AutoDebit interactor output interface extension AutoDebitPresenter: AutoDebitInteractorOutput { + func refreshTokenSuccess(header: [KftcHeader]?, url: String?) { + wireframe?.goRefreshToken(header: header, url: url) + } + + func refreshTokenError(with error: Error) { + view?.didFailRefreshToken(with: error) + } + func setModel(with model: KFTCModel?) { view?.endLoading() view?.setModel(with: model) diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift index 19c3c592..4bd534dd 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import IQKeyboardManagerSwift class AutoDebitViewController: UIViewController { @@ -32,14 +33,15 @@ class AutoDebitViewController: UIViewController { @IBOutlet weak var refreshAccountButton: UIBarButtonItem! // MARK:- properties - var presenter: AutoDebitPresenter? + var presenter: AutoDebitModuleInterface? var languages: [String] = ["--- Select Language ---"] lazy var languageTextField = UITextField(frame: .zero) var selectedLanguage: KftcLanguage? { didSet { - print("\(selectedLanguage?.value ?? "undefined")") +// print("\(selectedLanguage?.value ?? "undefined")") +// presenter?.goRefreshToken(selectedLanguage: selectedLanguage) } } @@ -48,9 +50,11 @@ class AutoDebitViewController: UIViewController { accounts = kftcDetail?.model tableView.reloadData() - let originalLanguages = kftcDetail?.languages?.map { $0.value ?? ""} - languages.append(contentsOf: originalLanguages ?? []) - + if languages.count < 2 { + let originalLanguages = kftcDetail?.languages?.map { $0.value ?? ""} + languages.append(contentsOf: originalLanguages ?? []) + } + } } @@ -60,11 +64,16 @@ class AutoDebitViewController: UIViewController { let account = accounts, !account.isEmpty else { + refreshAccountButton.isEnabled = false + refreshAccountButton.tintColor = .clear return } tableView.isHidden = false labelSwipeInfo.isHidden = false + + refreshAccountButton.isEnabled = true + refreshAccountButton.tintColor = .black } } @@ -94,12 +103,13 @@ class AutoDebitViewController: UIViewController { super.viewWillDisappear(animated) navigationItem.title = "" + view.endEditing(true) + if #available(iOS 11.0, *) { navigationController?.navigationBar.prefersLargeTitles = false } } - // MARK:- IBAction @IBAction func touchAddAccountButton(_ sender: UIBarButtonItem) { addNewAccount(UITapGestureRecognizer()) @@ -107,15 +117,32 @@ class AutoDebitViewController: UIViewController { } @IBAction func touchRefreshAccountButton(_ sender: UIBarButtonItem) { - let languagePickerView = UIPickerView() - languagePickerView.delegate = self - languagePickerView.dataSource = self - - languageTextField.inputView = languagePickerView - languageTextField.placeholder = "Select Language for Refresh AutoDebit" - languageTextField.becomeFirstResponder() + alertWithOkCancel( + type: .normal, + message: "Do you try to renew token of registered Auto Debit Accounts?\n(It must be renewed every one year.)", + title: "Token Renewal", + okTitle: "yes_text".localized(), + style: .alert, + cancelTitle: "no_text".localized(), + okAction: { + let languagePickerView = UIPickerView() + languagePickerView.delegate = self + languagePickerView.dataSource = self + languagePickerView.backgroundColor = .white + + self.languageTextField.inputView = languagePickerView + self.languageTextField.placeholder = "Select Language for Refresh AutoDebit" + self.languageTextField.becomeFirstResponder() + + self.languageTextField.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(self.editingDidEnd(_:))) + }, + cancelAction: nil + ) } + @objc func editingDidEnd(_ textField: UITextField) { + presenter?.goRefreshToken(selectedLanguage: selectedLanguage) + } @IBAction private func addNewAccount(_ sender: UITapGestureRecognizer) { @@ -201,6 +228,10 @@ extension AutoDebitViewController: UITableViewDelegate { // MARK: - AutoDebitViewInterface extension AutoDebitViewController: AutoDebitViewInterface { + func didFailRefreshToken(with error: Error) { + alert(message: error.localizedDescription) + } + func didDeleteAccount() { presenter?.fetchKFTCBankAccountList() } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift index 07362b0e..b2ab59ec 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift @@ -29,6 +29,7 @@ protocol AutoDebitViewInterface: class { /// - Parameter error: Error func didFailDeleteAccount(with error: Error) + func didFailRefreshToken(with error: Error) /// Start ActivityIndicator func startLoading() diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift index 6162f1f6..cdaf75ad 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift @@ -35,4 +35,15 @@ extension AutoDebitWireframe: AutoDebitWireframeInput { func goAddAccountViewController(with model: KFTCModel?) { AddAccountWireframe().openPushMainView(with: model, source: view) } + + func goRefreshToken(header: [KftcHeader]?, url: String?) { + let viewcontroller = UIStoryboard.init(name: "WKWebView", bundle: nil).instantiateViewController(withIdentifier: "WkWebViewController") as! WkWebViewController + + viewcontroller.url = url?.components(separatedBy: .whitespaces).joined() + viewcontroller.headers = header + + let navigationController = UINavigationController(rootViewController: viewcontroller) + + view.present(navigationController, animated: true, completion: nil) + } } diff --git a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframeInput.swift b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframeInput.swift index 0ebcfcfb..bf4e8fdb 100644 --- a/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframeInput.swift +++ b/GMERemittance/Module/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframeInput.swift @@ -12,4 +12,12 @@ protocol AutoDebitWireframeInput: WireframeInput { /// /// - Parameter model: KFTCModel func goAddAccountViewController(with model: KFTCModel?) + + + /// Present Refresh Token + /// + /// - Parameters: + /// - hearder: [String: String]] + /// - url: String + func goRefreshToken(header: [KftcHeader]?, url: String?) } diff --git a/GMERemittance/Module/SideMenu/SideMenuViewController.swift b/GMERemittance/Module/SideMenu/SideMenuViewController.swift index bd7ef94b..cac0c61a 100644 --- a/GMERemittance/Module/SideMenu/SideMenuViewController.swift +++ b/GMERemittance/Module/SideMenu/SideMenuViewController.swift @@ -175,8 +175,9 @@ class SideMenuViewController: UIViewController { let noAction = UIAlertAction(title: StringConstants().noText, style: .default, handler: nil) noAction.setValue(UIColor.black, forKey: "titleTextColor") yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor") - alert.addAction(yesAction) + alert.addAction(noAction) + alert.addAction(yesAction) self.present(alert, animated: true, completion: nil) } diff --git a/GMERemittanceTests/APITest.swift b/GMERemittanceTests/APITest.swift index 4b9dfe13..2364192f 100644 --- a/GMERemittanceTests/APITest.swift +++ b/GMERemittanceTests/APITest.swift @@ -83,7 +83,7 @@ class APITest: XCTestCase { let service2 = AddAccountService() let expt = expectation(description: "Test KFTC Refresh") - service.refreshAccount( + service.refreshTokenStep1( username: "maxkim@gmeremit.com", success: { let url = "\($0?.url?.replacingOccurrences(of: "&lang=", with: "&lang=kor") ?? "")"