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.
 
 
 
 

112 lines
4.4 KiB

//
// SendMoneyVerificationInteractor.swift
// GMERemittance
//
// Created by gme_2 on 28/08/2018.
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
class SendMoneyVerificationInteractor {
// MARK: Properties
weak var output: SendMoneyVerificationInteractorOutput?
private let service: SendMoneyVerificationServiceType
// MARK: Initialization
init(service: SendMoneyVerificationServiceType) {
self.service = service
}
// MARK: Converting entities
}
// MARK: SendMoneyVerification interactor input interface
extension SendMoneyVerificationInteractor: SendMoneyVerificationInteractorInput {
func submit(model: SendMoneyRequestModel, reciepient: Recipient) {
let params = self.getParams(model: model, reciepient: reciepient)
self.service.submit(params: params, success: { (response) in
// UPDATE BALANCE
let balance = response?.data?.extra ?? ""
let userInfo = [SideMenuNavigationNotifications.availableBalance : balance]
UserDefaults.standard.set(balance, forKey: UserKeys.availableBalance)
NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo)
// UPDATE YEARLY LIMIT
let limit = response?.data?.remainingLimit ?? ""
let userInfo2 = [AppConstants.yearlyLimitNotification : limit]
NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo2)
// SHOW
self.output?.show(model: response)
}) { (error) in
self.output?.show(error: error)
}
}
func getAvailableBalanceNotificationName() -> Notification.Name {
return Notification.Name.init(rawValue: SideMenuNavigationNotifications.availableBalance)
}
@objc private func getYearlyLimitNotificationName() -> Notification.Name {
return Notification.Name.init(AppConstants.yearlyLimitNotification)
}
func getParams(model: SendMoneyRequestModel, reciepient: Recipient) -> [String: String] {
let _default = UserDefaults.standard
guard let username = _default.value(forKey: UserKeys.userId) as? String else {return [:]}
let senderId = _default.value(forKey: UserKeys.senderId) as? String
let recieverId = reciepient.recipientId
let params: [String: String] =
[
"user": username,
"senderId": senderId ?? "",
"receiverId": recieverId ?? "",
"deliveryMethodId": model.paymemtMode?.id ?? "",
"pBranch": model.branch?.id ?? "",
"pAgent": model.bank?.id ?? "",
"payOutPartner": model.paymemtMode?.payoutPartner ?? "",
"paymentType": model.autoDebitAccount?.type ?? "",
"pCurr": model.exchangeRateDetail?.reciepientCurrency ?? "",
"collCurr": "KRW",
"collAmt": model.exchangeRateDetail?.senderAmount ?? "",
"payoutAmt": model.exchangeRateDetail?.recipientAmount ?? "",
"transferAmt": model.exchangeRateDetail?.transferAmount ?? "",
"serviceCharge": model.exchangeRateDetail?.transferFee ?? "",
"discount": "",
"exRate": model.exchangeRateDetail?.apiExchangeRate ?? "",
"calBy": model.exchangeRateDetail?.calcBy ?? "",
"tpExRate": model.exchangeRateDetail?.apiExchangeRate ?? "",
"tpPCurr": model.exchangeRateDetail?.reciepientCurrency ?? "",
"foreX_SESSION_ID": model.exchangeRateDetail?.forexId ?? "",
"purposeOfRemittance": reciepient.reasonId ?? "",
"sourceOfFund": "128",
"relWithSender": reciepient.relationId ?? "",
"occupation": "",
"ipAddress": "",
"rState": "",
"rLocation": "",
"isAgreed": "TRUE",
"txnPassword": model.transactionPassword ?? "",
"ReceiverAccountNo": model.paymemtMode?.accountNumber ?? "",
"KftcLogId": model.autoDebitAccount?.kftcLogId ?? "",
]
return params
}
}