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.

72 lines
1.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // SendMoneyReceiptService.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 04/09/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class SendMoneyReceiptService: SendMoneyReceiptServiceType {
  10. func fetch(
  11. type: ReceiptType,
  12. transactionId: String,
  13. success: @escaping (SendMoneyReciept) -> Void,
  14. failure: @escaping (Error) -> Void
  15. ) {
  16. switch type {
  17. case .overseas:
  18. overseaReciept(transactionId, success: success, failure: failure)
  19. case .domestic:
  20. domesticReciept(transactionId, success: success, failure: failure)
  21. }
  22. }
  23. private func overseaReciept(
  24. _ transactionId: String,
  25. success: @escaping (SendMoneyReciept) -> Void,
  26. failure: @escaping (Error) -> Void
  27. ) {
  28. let url = baseUrl + "/mobile/receipt/" + transactionId
  29. self.auth.request(
  30. method: .post,
  31. url: url,
  32. params: nil,
  33. success: { (response: SendMoneyRecieptContainer) in
  34. if (response.errorCode ?? "") == "1" {
  35. let error = NSError(
  36. domain: "Network",
  37. code: 0,
  38. userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]
  39. )
  40. failure(error)
  41. } else {
  42. guard let model = response.data else {
  43. let error = NSError(
  44. domain: "Network",
  45. code: 0,
  46. userInfo: [NSLocalizedDescriptionKey : "Data is nil"]
  47. )
  48. failure(error)
  49. return
  50. }
  51. success(model)
  52. }
  53. },
  54. failure: { (error) in
  55. failure(error)
  56. }
  57. )
  58. }
  59. private func domesticReciept(
  60. _ transactionId: String,
  61. success: @escaping (SendMoneyReciept) -> Void,
  62. failure: @escaping (Error) -> Void
  63. ) {
  64. APIRouter.domesticReceipt(transactionID: transactionId).json(success: success, failure: failure)
  65. }
  66. }