// // SendMoneyReceiptService.swift // GMERemittance // // Created by gme_2 on 04/09/2018. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. // import Foundation class SendMoneyReceiptService: SendMoneyReceiptServiceType { func fetch( type: ReceiptType, transactionId: String, success: @escaping (SendMoneyReciept) -> Void, failure: @escaping (Error) -> Void ) { switch type { case .overseas: overseaReciept(transactionId, success: success, failure: failure) case .domestic: domesticReciept(transactionId, success: success, failure: failure) } } private func overseaReciept( _ transactionId: String, success: @escaping (SendMoneyReciept) -> Void, failure: @escaping (Error) -> Void ) { let url = baseUrl + "/mobile/receipt/" + transactionId self.auth.request( method: .post, url: url, params: nil, success: { (response: SendMoneyRecieptContainer) in if (response.errorCode ?? "") == "1" { let error = NSError( domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""] ) failure(error) } else { guard let model = response.data else { let error = NSError( domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : "Data is nil"] ) failure(error) return } success(model) } }, failure: { (error) in failure(error) } ) } private func domesticReciept( _ transactionId: String, success: @escaping (SendMoneyReciept) -> Void, failure: @escaping (Error) -> Void ) { APIRouter.domesticReceipt(transactionID: transactionId).json(success: success, failure: failure) } }