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.
 
 
 
 

76 lines
2.0 KiB

//
// SetupRecipientInteractor.swift
// GME Remit
//
// Created by InKwon James Kim on 09/08/2019.
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
class SetupRecipientInteractor {
// MARK: Properties
weak var output: SetupRecipientInteractorOutput?
private let service: SetupRecipientServiceType
private let recipient: Recipient?
private lazy var nativeCountries = StaticModels().nativeCountries
// MARK: Initialization
init(service: SetupRecipientServiceType, _ recipient: Recipient?) {
self.service = service
self.recipient = recipient
}
}
// MARK: SetupRecipient interactor input interface
extension SetupRecipientInteractor: SetupRecipientInteractorInput {
func fetchCountriesAndServiceTypes() {
service.fetchCountriesAndServiceTypes(
success: {self.output?.setCoutryServices(with: $0, recipient: self.recipient)},
failure: {self.output?.setError(with: $0)}
)
}
func fetchDynamicRecipientFields(country: String, paymentMode: String) {
service.fetchDynamicReceiverFields(
of: country,
paymentModeID: paymentMode,
success: {self.output?.setDynamicFields(with: $0, nativeCountires: self.nativeCountries)},
failure: {self.output?.setError(with: $0)}
)
}
func addRecipient(at recipient: Recipient) {
service.addRecipient(
at: recipient,
success: {self.output?.success(with: $0)},
failure: {self.output?.setError(with: $0)}
)
}
func editRecipient(at recipient: Recipient) {
service.editRecipient(
at: recipient,
success: {self.output?.success(with: $0)},
failure: {self.output?.setError(with: $0)}
)
}
func validateAccount(with model: ValidateAccountRequest, recipient: Recipient) {
service.validateAccount(
of: model,
success: {
if recipient.receiverID == nil {
self.addRecipient(at: recipient)
} else {
self.editRecipient(at: recipient)
}
},
failure: {self.output?.setError(with:$0)}
)
}
}