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.

111 lines
4.5 KiB

6 years ago
6 years ago
6 years ago
  1. //
  2. // SendMoneyVerificationInteractor.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class SendMoneyVerificationInteractor {
  10. // MARK: Properties
  11. weak var output: SendMoneyVerificationInteractorOutput?
  12. private let service: SendMoneyVerificationServiceType
  13. // MARK: Initialization
  14. init(service: SendMoneyVerificationServiceType) {
  15. self.service = service
  16. }
  17. // MARK: Converting entities
  18. }
  19. // MARK: SendMoneyVerification interactor input interface
  20. extension SendMoneyVerificationInteractor: SendMoneyVerificationInteractorInput {
  21. func submit(model: SendMoneyRequestModel, reciepient: Recipient) {
  22. let params = self.getParams(model: model, reciepient: reciepient)
  23. self.service.submit(params: params, success: { (response) in
  24. // UPDATE BALANCE
  25. let balance = response?.data?.extra ?? ""
  26. let userInfo = [SideMenuNavigationNotifications.availableBalance : balance]
  27. UserDefaults.standard.set(balance, forKey: UserKeys.availableBalance)
  28. NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo)
  29. // UPDATE YEARLY LIMIT
  30. let limit = response?.data?.remainingLimit ?? ""
  31. let userInfo2 = [AppConstants.yearlyLimitNotification : limit]
  32. NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo)
  33. NotificationCenter.default.post(name: self.getYearlyLimitNotificationName(), object: userInfo2)
  34. // SHOW
  35. self.output?.show(model: response)
  36. }) { (error) in
  37. self.output?.show(error: error)
  38. }
  39. }
  40. func getAvailableBalanceNotificationName() -> Notification.Name {
  41. return Notification.Name.init(rawValue: SideMenuNavigationNotifications.availableBalance)
  42. }
  43. @objc private func getYearlyLimitNotificationName() -> Notification.Name {
  44. return Notification.Name.init(AppConstants.yearlyLimitNotification)
  45. }
  46. func getParams(model: SendMoneyRequestModel, reciepient: Recipient) -> [String: String] {
  47. let _default = UserDefaults.standard
  48. guard let username = _default.value(forKey: UserKeys.userId) as? String else {return [:]}
  49. let senderId = _default.value(forKey: UserKeys.senderId) as? String
  50. let recieverId = reciepient.recipientId
  51. let params: [String: String] =
  52. [
  53. "user": username,
  54. "senderId": senderId ?? "",
  55. "receiverId": recieverId ?? "",
  56. "deliveryMethodId": model.paymemtMode?.id ?? "",
  57. "pBranch": model.branch?.id ?? "",
  58. "pAgent": model.bank?.id ?? "",
  59. "payOutPartner": model.paymemtMode?.payoutPartner ?? "",
  60. "paymentType": model.autoDebitAccount?.type ?? "",
  61. "pCurr": model.exchangeRateDetail?.reciepientCurrency ?? "",
  62. "collCurr": "KRW",
  63. "collAmt": model.exchangeRateDetail?.senderAmount ?? "",
  64. "payoutAmt": model.exchangeRateDetail?.recipientAmount ?? "",
  65. "transferAmt": model.exchangeRateDetail?.transferAmount ?? "",
  66. "serviceCharge": model.exchangeRateDetail?.transferFee ?? "",
  67. "discount": "",
  68. "exRate": model.exchangeRateDetail?.apiExchangeRate ?? "",
  69. "calBy": model.exchangeRateDetail?.calcBy ?? "",
  70. "tpExRate": model.exchangeRateDetail?.apiExchangeRate ?? "",
  71. "tpPCurr": model.exchangeRateDetail?.reciepientCurrency ?? "",
  72. "foreX_SESSION_ID": model.exchangeRateDetail?.forexId ?? "",
  73. "purposeOfRemittance": reciepient.reasonId ?? "",
  74. "sourceOfFund": "128",
  75. "relWithSender": reciepient.relationId ?? "",
  76. "occupation": "",
  77. "ipAddress": "",
  78. "rState": "",
  79. "rLocation": "",
  80. "isAgreed": "TRUE",
  81. "txnPassword": model.transactionPassword ?? "",
  82. "ReceiverAccountNo": model.paymemtMode?.accountNumber ?? "",
  83. "KftcLogId": model.autoDebitAccount?.kftcLogId ?? "",
  84. ]
  85. return params
  86. }
  87. }