// // AutoDebitService.swift // GME Remit // // Created by Mac on 12/19/18. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. // import Foundation import Alamofire class AutoDebitService: AutoDebitServiceType { // MARK: Properties // MARK: Initialization // MARK: Data management // MARK: Netword Service func fetchAccountList( username: String, success: @escaping (KFTCModel?) -> Void, failure: @escaping (Error) -> Void ) { let url = baseUrl + "/kftc/GetKftcParameters/" + username auth.request( method: .get, url: url, params: nil, encoding: URLEncoding.default, success: { (response: KftcAccountContainer) 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) } }, failure: { (error) in failure(error) } ) } func deleteAccount( username: String, account: Account, success: @escaping () -> Void, failure: @escaping (Error) -> Void ) { let url = baseUrl + "/kftc/DeleteAccount/\(username)" let params = ["KftcLogId" : account.kftcLogId ?? ""] auth.request( method: .post, url: url, params: params, encoding: JSONEncoding.default, success: { (response: KftcAccountContainer) in if (response.errorCode ?? "") == "1" { let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) failure(error) }else { success() } }, failure:{ (error) in failure(error) } ) } func refreshTokenStep1( username: String, success: @escaping (KFTCModel?) -> Void, failure: @escaping (Error) -> Void ) { let url = baseUrl + "/kftc/CheckKFTCAccounts/" + username auth.request( method: .get, url: url, params: nil, encoding: URLEncoding.default, success: { (response: KftcAccountContainer) 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) } }, failure: { (error) in failure(error) } ) } }