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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // SetupRecipientInteractor.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 09/08/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class SetupRecipientInteractor {
  10. // MARK: Properties
  11. weak var output: SetupRecipientInteractorOutput?
  12. private let service: SetupRecipientServiceType
  13. private let recipient: Recipient?
  14. private lazy var nativeCountries = StaticModels().nativeCountries
  15. // MARK: Initialization
  16. init(service: SetupRecipientServiceType, _ recipient: Recipient?) {
  17. self.service = service
  18. self.recipient = recipient
  19. }
  20. }
  21. // MARK: SetupRecipient interactor input interface
  22. extension SetupRecipientInteractor: SetupRecipientInteractorInput {
  23. func fetchCountriesAndServiceTypes() {
  24. service.fetchCountriesAndServiceTypes(
  25. success: {self.output?.setCoutryServices(with: $0, recipient: self.recipient)},
  26. failure: {self.output?.setError(with: $0)}
  27. )
  28. }
  29. func fetchDynamicRecipientFields(country: String, paymentMode: String) {
  30. service.fetchDynamicReceiverFields(
  31. of: country,
  32. paymentModeID: paymentMode,
  33. success: {self.output?.setDynamicFields(with: $0, nativeCountires: self.nativeCountries)},
  34. failure: {self.output?.setError(with: $0)}
  35. )
  36. }
  37. func addRecipient(at recipient: Recipient) {
  38. service.addRecipient(
  39. at: recipient,
  40. success: {self.output?.success(with: $0)},
  41. failure: {self.output?.setError(with: $0)}
  42. )
  43. }
  44. func editRecipient(at recipient: Recipient) {
  45. service.editRecipient(
  46. at: recipient,
  47. success: {self.output?.success(with: $0)},
  48. failure: {self.output?.setError(with: $0)}
  49. )
  50. }
  51. func validateAccount(with model: ValidateAccountRequest, recipient: Recipient) {
  52. service.validateAccount(
  53. of: model,
  54. success: {
  55. if recipient.receiverID == nil {
  56. self.addRecipient(at: recipient)
  57. } else {
  58. self.editRecipient(at: recipient)
  59. }
  60. },
  61. failure: {self.output?.setError(with:$0)}
  62. )
  63. }
  64. }