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.

92 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // SetupRecipientService.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 SetupRecipientService: SetupRecipientServiceType {
  10. func fetchCountriesAndServiceTypes(
  11. success: @escaping ([CountryAndServiceModel]) -> Void,
  12. failure: @escaping (Error) -> Void
  13. ) {
  14. let name = GMEDB.shared.user.string(.userId) ?? ""
  15. APIRouter.fetchCountriesAndServiceTypes(username: name)
  16. .json(success: success, failure: failure)
  17. }
  18. func fetchDynamicReceiverFields(
  19. of countryID: String,
  20. paymentModeID: String,
  21. success: @escaping (DynamicFieldModel) -> Void,
  22. failure: @escaping (Error) -> Void
  23. ) {
  24. let username = GMEDB.shared.user.string(.userId) ?? ""
  25. APIRouter.dynamicReceiver(
  26. username: username,
  27. countryID: countryID,
  28. serviceTypeID: paymentModeID
  29. ).json(success: success, failure: failure)
  30. }
  31. func addRecipient(
  32. at recipient: Recipient,
  33. success: @escaping (ResponseContainerObject<Recipient>) -> Void,
  34. failure: @escaping (Error) -> Void
  35. ) {
  36. let id = GMEDB.shared.user.string(.senderId) ?? ""
  37. APIRouter.addRecipient(senderID: id, recipient: recipient)
  38. .request(
  39. success: {(response: ResponseContainerObject<Recipient>) in
  40. if response.errorCode != "0" {
  41. let error = NSError(
  42. domain: "Network",
  43. code: 0,
  44. message: response.message ?? "Failed Add Recipient"
  45. )
  46. failure(error)
  47. }
  48. success(response)
  49. },
  50. failure: failure
  51. )
  52. }
  53. func editRecipient(
  54. at recipient: Recipient,
  55. success: @escaping (ResponseContainerObject<Recipient>) -> Void,
  56. failure: @escaping (Error) -> Void
  57. ) {
  58. let id = GMEDB.shared.user.string(.senderId) ?? ""
  59. APIRouter.editRecipient(senderID: id, recipient: recipient)
  60. .request(
  61. success: {(response: ResponseContainerObject<Recipient>) in
  62. if response.errorCode != "0" {
  63. let error = NSError(
  64. domain: "Network",
  65. code: 0,
  66. message: response.message ?? "Failed Edit Recipient"
  67. )
  68. failure(error)
  69. }
  70. success(response)
  71. },
  72. failure: failure
  73. )
  74. }
  75. func validateAccount(
  76. of model: ValidateAccountRequest,
  77. success: @escaping () -> Void,
  78. failure: @escaping (Error) -> Void
  79. ) {
  80. APIRouter.validateAccount(validateModel: model)
  81. .json(success: success, failure: failure)
  82. }
  83. }