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.

894 lines
30 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // APIRouter.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. import Alamofire
  10. import Localize_Swift
  11. import ObjectMapper
  12. import RxSwift
  13. class APIManager {
  14. static let shared = APIManager()
  15. let manager: SessionManager
  16. init() {
  17. let configure = URLSessionConfiguration.default
  18. configure.timeoutIntervalForRequest = 300.0
  19. configure.timeoutIntervalForResource = 300.0
  20. manager = Alamofire.SessionManager(configuration: configure)
  21. }
  22. }
  23. enum APIRouter {
  24. // MARK: - Login
  25. case accesscode(username: String, password: String)
  26. case customerProfile(firebaseToken: String)
  27. // MARK: - Register
  28. case customerRegister(registerModel: RegisterRequestModel, firebaseToken: String)
  29. case passwordReset(userName: String)
  30. case validation(userName: String, idNumber: String, idType: String)
  31. case countriesServices
  32. case calculateDefExRate(model: ExchangeRateRequestModel)
  33. // MARK: - KFTC
  34. case getKFTCParamers(username: String)
  35. case deleteAutoDebitAccount(username: String, kftcLogID: String)
  36. case renewalToken(username: String)
  37. case fetchBankList
  38. case checkRealName(model: VerifyAccountRequestModel)
  39. case fetchKFTCURL(url: String)
  40. case domesticRemitStart
  41. case getRecentHistories(from: String, to: String)
  42. case fetchBalace(type: String, fintechUseNumber: String)
  43. case fetchRecipientName(bankCode: String, accountNumber: String)
  44. case sendDomesticRemit(model: DomesticRemitRequestModel)
  45. // MARK: - Receiver
  46. case fetchRecipients(senderID: String)
  47. case dynamicReceiver(username: String, countryID: String, serviceTypeID: String)
  48. case fetchCountriesAndServiceTypes(username: String)
  49. case addRecipient(senderID: String, recipient: Recipient)
  50. case editRecipient(senderID: String, recipient: Recipient)
  51. case deleteRecipient(senderID: String, recipientID: String)
  52. case fetchBranches(countryCode: String, bankID: String, branchName: String)
  53. case validateAccount(validateModel: ValidateAccountRequest)
  54. case domesticTransactionHistory(from: String, to: String)
  55. case domesticReceipt(transactionID: String)
  56. // MARK: - Recharge Prepiad Phone
  57. case fetchCardList(type: String, mobile: String)
  58. case verificationAndBuy(model: RechargeModel)
  59. case fetchRechargeHistory(from: String, to: String)
  60. // MARK: - Inbound
  61. case penneyTestStart(model: PenneyTestRequest, isResend: String)
  62. case penneyTestCertified(model: PenneyTestVerify)
  63. case fetchInboundAccounts
  64. case fetchInboundTransactionHistory(from: String, to: String)
  65. case deleteInboundAccount(model: InboundAccount)
  66. // MARK: - New Registration
  67. case loadKYCInformation
  68. case saveKYCInformation(model: KYCSave)
  69. }
  70. // MARK: - Request
  71. extension APIRouter: ApiServiceType {
  72. private var manager: SessionManager {
  73. return APIManager.shared.manager
  74. }
  75. private var uuid: String {
  76. guard let uuid = GMEDB.shared.app.string(.uuid) else {
  77. let uuid = UUID().uuidString
  78. GMEDB.shared.app.set(uuid, .uuid)
  79. return uuid
  80. }
  81. return uuid
  82. }
  83. private var beforeLoginHeader: [String: String] {
  84. let currentLanguage = Localize.currentLanguage()
  85. let lang = Utility.getLanguageHeader(for: currentLanguage)
  86. let authValue = "172017F9EC11222E8107142733:QRK2UM0Q:\(uuid)".toBase64()
  87. return [
  88. "Authorization": "Basic \(authValue)",
  89. "GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru",
  90. "Content-Type": "application/json",
  91. "lang" : lang
  92. ]
  93. }
  94. private var afterLoginHeader: [String: String] {
  95. let accessCode = GMEDB.shared.user.string(.accessCode) ?? ""
  96. let currentLanguage = Localize.currentLanguage()
  97. let lang = Utility.getLanguageHeader(for: currentLanguage)
  98. return [
  99. "Authorization": "Bearer " + accessCode,
  100. "GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru",
  101. "Content-Type": "application/json",
  102. "clientId": Utility.getMyKftcClientId(),
  103. "lang" : lang
  104. ]
  105. }
  106. func json(
  107. encoding: ParameterEncoding = JSONEncoding.default,
  108. needsAuthorization: Bool = true,
  109. success: @escaping () -> Void,
  110. failure: @escaping (Error) -> Void
  111. ) {
  112. guard
  113. let isReachable = NetworkReachabilityManager()?.isReachable,
  114. isReachable else {
  115. let error = NSError(
  116. domain: "NETWORK_REACHABILITY_DOMAIN",
  117. code: -99,
  118. message: "No Internet connection found. Check your connection."
  119. )
  120. return failure(error)
  121. }
  122. manager.request(
  123. self.endpoint,
  124. method: self.method,
  125. parameters: self.parameters,
  126. encoding: encoding,
  127. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader
  128. ).handle(
  129. success: { (response: ResponseContainer<Void>) in
  130. if (response.errorCode ?? "") != "0" {
  131. let code = Int(response.errorCode ?? "1") ?? 1
  132. let error = NSError(domain: "Network", code: code, message: response.message ?? "")
  133. failure(error)
  134. } else {
  135. success()
  136. }
  137. },
  138. failure: failure
  139. )
  140. }
  141. func json<Element>(
  142. encoding: ParameterEncoding = JSONEncoding.default,
  143. needsAuthorization: Bool = true,
  144. success: @escaping (Element) -> Void,
  145. failure: @escaping (Error) -> Void
  146. ) {
  147. guard
  148. let isReachable = NetworkReachabilityManager()?.isReachable,
  149. isReachable else {
  150. let error = NSError(
  151. domain: "NETWORK_REACHABILITY_DOMAIN",
  152. code: -99,
  153. message: "No Internet connection found. Check your connection."
  154. )
  155. return failure(error)
  156. }
  157. manager.request(
  158. self.endpoint,
  159. method: self.method,
  160. parameters: self.parameters,
  161. encoding: encoding,
  162. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader
  163. ).handle(
  164. success: { (response: ResponseContainer<Element>) in
  165. if (response.errorCode ?? "") != "0" {
  166. let code = Int(response.errorCode ?? "1") ?? 1
  167. let error = NSError(domain: "Network", code: code, message: response.message ?? "")
  168. failure(error)
  169. } else {
  170. guard let data = response.data else {
  171. let error = NSError(domain: "Network", code: 0, message: "Data is nil")
  172. failure(error)
  173. return
  174. }
  175. success(data)
  176. }
  177. },
  178. failure: failure
  179. )
  180. }
  181. func json<Element: Mappable>(
  182. encoding: ParameterEncoding = JSONEncoding.default,
  183. needsAuthorization: Bool = true,
  184. success: @escaping (Element) -> Void,
  185. failure: @escaping (Error) -> Void
  186. ) {
  187. guard
  188. let isReachable = NetworkReachabilityManager()?.isReachable,
  189. isReachable else {
  190. let error = NSError(
  191. domain: "NETWORK_REACHABILITY_DOMAIN",
  192. code: -99,
  193. message: "No Internet connection found. Check your connection."
  194. )
  195. return failure(error)
  196. }
  197. manager.request(
  198. self.endpoint,
  199. method: self.method,
  200. parameters: self.parameters,
  201. encoding: encoding,
  202. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader
  203. )
  204. .handle(
  205. success: { (response: ResponseContainerObject<Element>) in
  206. if (response.errorCode ?? "") != "0" {
  207. let code = Int(response.errorCode ?? "1") ?? 1
  208. let error = NSError(domain: "Network", code: code, message: response.message ?? "")
  209. failure(error)
  210. } else {
  211. guard let data = response.data else {
  212. let error = NSError(domain: "Network", code: 0, message: "Data is nil")
  213. failure(error)
  214. return
  215. }
  216. success(data)
  217. }
  218. },
  219. failure: failure
  220. )
  221. }
  222. func json<Element: Mappable>(
  223. encoding: ParameterEncoding = JSONEncoding.default,
  224. needsAuthorization: Bool = true,
  225. success: @escaping ([Element]) -> Void,
  226. failure: @escaping (Error) -> Void
  227. ) {
  228. guard
  229. let isReachable = NetworkReachabilityManager()?.isReachable,
  230. isReachable else {
  231. let error = NSError(
  232. domain: "NETWORK_REACHABILITY_DOMAIN",
  233. code: -99,
  234. message: "No Internet connection found. Check your connection."
  235. )
  236. return failure(error)
  237. }
  238. manager.request(
  239. self.endpoint,
  240. method: self.method,
  241. parameters: self.parameters,
  242. encoding: encoding,
  243. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader
  244. )
  245. .handle(
  246. success: { (response: ResponseContainerArray<Element>) in
  247. if (response.errorCode ?? "") != "0" {
  248. let code = Int(response.errorCode ?? "1") ?? 1
  249. let error = NSError(domain: "Network", code: code, message: response.message ?? "")
  250. failure(error)
  251. } else {
  252. guard let data = response.data else {
  253. let error = NSError(domain: "Network", code: 0, message: "Data is nil")
  254. failure(error)
  255. return
  256. }
  257. success(data)
  258. }
  259. },
  260. failure: failure
  261. )
  262. }
  263. func request<T: Mappable>(
  264. encoding: ParameterEncoding = JSONEncoding.default,
  265. needsAuthorization: Bool = true,
  266. success: @escaping (T) -> Void,
  267. failure: @escaping (Error) -> Void
  268. ) {
  269. guard
  270. let isReachable = NetworkReachabilityManager()?.isReachable,
  271. isReachable else {
  272. let error = NSError(
  273. domain: "NETWORK_REACHABILITY_DOMAIN",
  274. code: -99,
  275. message: "No Internet connection found. Check your connection."
  276. )
  277. return failure(error)
  278. }
  279. manager.request(
  280. self.endpoint,
  281. method: self.method,
  282. parameters: self.parameters,
  283. encoding: encoding,
  284. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader
  285. ).handle(success: success, failure: failure)
  286. }
  287. func kftcRequest<T: Mappable>(
  288. header: [String: String],
  289. encoding: ParameterEncoding = JSONEncoding.default,
  290. success: @escaping (T) -> Void,
  291. failure: @escaping (Error) -> Void
  292. ) {
  293. guard
  294. let isReachable = NetworkReachabilityManager()?.isReachable,
  295. isReachable else {
  296. let error = NSError(
  297. domain: "NETWORK_REACHABILITY_DOMAIN",
  298. code: -99,
  299. message: "No Internet connection found. Check your connection."
  300. )
  301. return failure(error)
  302. }
  303. manager.request(
  304. self.endpoint,
  305. method: self.method,
  306. parameters: self.parameters,
  307. encoding: encoding,
  308. headers: header
  309. ).handle(success: success, failure: failure)
  310. }
  311. func requestMultipart<T: Mappable>(
  312. method: HTTPMethod,
  313. _ URLString: URLConvertible,
  314. parameters: [String: String]? = nil,
  315. images: [String: Data],
  316. encoding: Alamofire.ParameterEncoding = URLEncoding.default,
  317. needsAuthorization: Bool = true,
  318. success: @escaping (T) -> Void,
  319. failure: @escaping (Error) -> Void
  320. ) {
  321. guard
  322. let isReachable = NetworkReachabilityManager()?.isReachable,
  323. isReachable else {
  324. let error = NSError(
  325. domain: "NETWORK_REACHABILITY_DOMAIN",
  326. code: -99,
  327. message: "No Internet connection found. Check your connection."
  328. )
  329. return failure(error)
  330. }
  331. manager.upload(
  332. multipartFormData: { multipartFormData in
  333. if !images.isEmpty {
  334. images.forEach({ (data) in
  335. multipartFormData.append(
  336. data.value,
  337. withName: data.key,
  338. fileName: data.key + ".jpeg",
  339. mimeType: "image/jpeg"
  340. )
  341. })
  342. }
  343. parameters?.forEach { (params) in
  344. multipartFormData.append(
  345. params.value.data(
  346. using: String.Encoding.utf8,
  347. allowLossyConversion: false
  348. )!,
  349. withName: params.key
  350. )
  351. }
  352. },
  353. to: URLString,
  354. method: method,
  355. headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader,
  356. encodingCompletion: { encodingResult in
  357. switch encodingResult {
  358. case .success(let upload, _, _):
  359. upload.handle(success: success, failure: failure)
  360. case .failure:
  361. let error = NSError(
  362. domain: "NETWORK_REACHABILITY_DOMAIN",
  363. code: -99,
  364. message: "No Internet connection found. Check your connection."
  365. )
  366. failure(error)
  367. }
  368. }
  369. )
  370. }
  371. }
  372. // MARK: - Endpoint
  373. extension APIRouter {
  374. private var endpoint: String {
  375. switch self {
  376. case .accesscode:
  377. return "\(baseUrl)/users/access-code"
  378. case .customerProfile:
  379. return "\(baseUrl)/mobile/CustomerProfile"
  380. case .customerRegister:
  381. return "\(baseUrlWithoutVersion)/v3/mobile/customerRegister"
  382. case .passwordReset:
  383. return "\(baseUrl)/mobile/passwordReset"
  384. case .validation:
  385. return "\(baseUrlWithoutVersion)/v3/validation"
  386. case .countriesServices:
  387. return "\(baseUrl)/mobile/countriesServices"
  388. case .calculateDefExRate:
  389. return "\(baseUrl)/mobile/calculateDefExRate"
  390. case .dynamicReceiver(let username, let countryID, let serviceType):
  391. let path = "\(username)/dynamicField?countryId=\(countryID)&serviceType=\(serviceType)"
  392. return "\(baseUrlWithoutVersion)v3/mobile/receiver/\(path)"
  393. case .getKFTCParamers(let username):
  394. return "\(baseUrl)/kftc/GetKftcParameters/\(username)"
  395. case .deleteAutoDebitAccount(let username, _):
  396. return "\(baseUrl)/kftc/DeleteAccount/\(username)"
  397. case .renewalToken(let username):
  398. return "\(baseUrl)/kftc/CheckKFTCAccounts/\(username)"
  399. case .fetchBankList:
  400. return "\(baseUrl)/kftc/KFTCBankList"
  401. case .checkRealName:
  402. return "\(baseUrl)/kftc/CheckRealName"
  403. case .fetchKFTCURL(let url):
  404. return url
  405. case .fetchRecipients(let senderID):
  406. return "\(baseUrlWithoutVersion)v3/mobile/\(senderID)/receiverinfo"
  407. case .fetchCountriesAndServiceTypes(let username):
  408. return "\(baseUrlWithoutVersion)v3/mobile/\(username)/FetchCountriesAndServiceTypes"
  409. case .addRecipient(let senderID, _):
  410. return "\(baseUrlWithoutVersion)v3/mobile/\(senderID)/receiverinfo/add"
  411. case .editRecipient(let senderID, let recipient):
  412. let recipientID = recipient.receiverID ?? ""
  413. return "\(baseUrlWithoutVersion)/v3/mobile/\(senderID)/receiverinfo/modify/\(recipientID)"
  414. case .deleteRecipient(let senderID, let recipientID):
  415. return "\(baseUrlWithoutVersion)/v3/mobile/\(senderID)/receiverinfo/remove/\(recipientID)"
  416. case .fetchBranches(let countryCode, let bankID, let branchName):
  417. return "\(baseUrl)/mobile/sendmoney/load/branch/\(countryCode)/\(bankID)/?search=\(branchName)"
  418. case .validateAccount:
  419. return "\(baseUrl)/mobile/sendmoney/validation/account"
  420. case .domesticRemitStart:
  421. return "\(baseUrl)/kftc/DomeRemitStart"
  422. case .getRecentHistories:
  423. return "\(baseUrl)/kftc/GetRecentHistories"
  424. case .fetchBalace:
  425. return "\(baseUrl)/kftc/CheckBalance"
  426. case .fetchRecipientName:
  427. return "\(baseUrl)/kftc/GetRecipientInfo"
  428. case .sendDomesticRemit:
  429. return "\(baseUrl)/kftc/SendDomeRimit"
  430. case .domesticTransactionHistory:
  431. let userID = GMEDB.shared.user.string(.userId) ?? ""
  432. return "\(baseUrl)/mobile/DomestricTranhistory/\(userID)"
  433. case .domesticReceipt(let transactionID):
  434. return "\(baseUrl)/mobile/DomesticReceipt/\(transactionID)"
  435. case .fetchCardList:
  436. return "\(baseUrl)/powerCall/GetCardList/"
  437. case .verificationAndBuy:
  438. return "\(baseUrl)/powerCall/VerificationAndBuy/"
  439. case .fetchRechargeHistory:
  440. return "\(baseUrl)/powerCall/GetChargeHistory/"
  441. case .penneyTestStart(_, let isResend):
  442. let senderId = GMEDB.shared.user.string(.senderId) ?? ""
  443. return "\(baseUrl)/inbound/mobile/pennytest/start/\(senderId)?reSendCode=\(isResend)"
  444. case .penneyTestCertified:
  445. return "\(baseUrl)/inbound/mobile/pennytest/getcertified"
  446. case .fetchInboundAccounts:
  447. let senderId = GMEDB.shared.user.string(.senderId) ?? ""
  448. return "\(baseUrl)/inbound/mobile/bankaccounts/\(senderId)"
  449. case .fetchInboundTransactionHistory:
  450. let senderId = GMEDB.shared.user.string(.senderId) ?? ""
  451. return "\(baseUrl)/inbound/mobile/tranHistory/\(senderId)"
  452. case .deleteInboundAccount(let model):
  453. let senderId = GMEDB.shared.user.string(.senderId) ?? ""
  454. return "\(baseUrl)/inbound/mobile/deleteInboundAccount/\(senderId)/\(model.id ?? "")"
  455. case .loadKYCInformation:
  456. let userID = GMEDB.shared.user.string(.userId) ?? ""
  457. return "\(baseUrlWithoutVersion)/v4/Mobile/loadform/\(userID)/kyc"
  458. case .saveKYCInformation:
  459. return "\(baseUrlWithoutVersion)/v4/mobile/RegisterKyc"
  460. }
  461. }
  462. }
  463. // MARK: - Method
  464. extension APIRouter {
  465. private var method: HTTPMethod {
  466. switch self {
  467. case .accesscode:
  468. return .post
  469. case .customerProfile:
  470. return .post
  471. case .customerRegister:
  472. return .post
  473. case .passwordReset:
  474. return .post
  475. case .validation:
  476. return .post
  477. case .countriesServices:
  478. return .get
  479. case .calculateDefExRate:
  480. return .post
  481. case .dynamicReceiver:
  482. return .post
  483. case .getKFTCParamers:
  484. return .get
  485. case .deleteAutoDebitAccount:
  486. return .post
  487. case .renewalToken:
  488. return .get
  489. case .fetchBankList:
  490. return .get
  491. case .checkRealName:
  492. return .post
  493. case .fetchKFTCURL:
  494. return .get
  495. case .fetchRecipients:
  496. return .get
  497. case .fetchCountriesAndServiceTypes:
  498. return .get
  499. case .addRecipient:
  500. return .post
  501. case .editRecipient:
  502. return .post
  503. case .deleteRecipient:
  504. return .post
  505. case .fetchBranches:
  506. return .post
  507. case .validateAccount:
  508. return .post
  509. case .domesticRemitStart:
  510. return .post
  511. case .getRecentHistories:
  512. return .post
  513. case .fetchBalace:
  514. return .post
  515. case .fetchRecipientName:
  516. return .post
  517. case .sendDomesticRemit:
  518. return .post
  519. case .domesticTransactionHistory:
  520. return .post
  521. case .domesticReceipt:
  522. return .post
  523. case .fetchCardList:
  524. return .post
  525. case .verificationAndBuy:
  526. return .post
  527. case .fetchRechargeHistory:
  528. return .post
  529. case .penneyTestStart:
  530. return .post
  531. case .penneyTestCertified:
  532. return .post
  533. case .fetchInboundAccounts:
  534. return .post
  535. case .fetchInboundTransactionHistory:
  536. return .post
  537. case .deleteInboundAccount:
  538. return .post
  539. case .loadKYCInformation:
  540. return .get
  541. case .saveKYCInformation:
  542. return .post
  543. }
  544. }
  545. }
  546. // MARK: - Parameter
  547. extension APIRouter {
  548. private var parameters: Parameters? {
  549. switch self.method {
  550. case .post:
  551. switch self {
  552. case .accesscode(let username, let password):
  553. return [
  554. "userId": username,
  555. "password": password
  556. ]
  557. case .customerProfile(let firebaseToken):
  558. return [
  559. "userId" : Utility.getMyUserName(),
  560. "uuid": self.uuid,
  561. "appVersion": Utility.getAppVersion() ?? "",
  562. "phoneBrand": UIDevice.modelName,
  563. "phoneOs": Utility.getPhoneOs(),
  564. "fcmId": firebaseToken,
  565. "osVersion": Utility.getOsVersion()
  566. ]
  567. case .customerRegister(let registerModel, let firebaseToken):
  568. return [
  569. "username": registerModel.username ?? "",
  570. "password": registerModel.encryptedPassword ?? "",
  571. "nativecountry": registerModel.nativeCountry ?? "",
  572. "mobilenumber": registerModel.mobileNumber ?? "",
  573. "clientId": Utility.getCliendId(),
  574. "uuid": self.uuid,
  575. "appVersion": Utility.getAppVersion() ?? "",
  576. "phoneBrand": UIDevice.modelName,
  577. "phoneOs": Utility.getPhoneOs(),
  578. "fcmId": firebaseToken,
  579. "osVersion": Utility.getOsVersion()
  580. ]
  581. case .passwordReset(let userName):
  582. return ["username": userName]
  583. case .validation(let userName, let idNumber, let idType):
  584. return [
  585. "Username": userName,
  586. "IdNumber": idNumber,
  587. "IdType": idType
  588. ]
  589. case .calculateDefExRate(let model):
  590. return model.serialize()
  591. case .deleteAutoDebitAccount(_, let kftcLogID):
  592. return [
  593. "KftcLogId" : kftcLogID
  594. ]
  595. case .checkRealName(let model):
  596. return [
  597. "CustomerId": model.customerID,
  598. "BankCode": model.bankCode,
  599. "AccountNumber": model.accountNumber
  600. ]
  601. case .dynamicReceiver:
  602. return nil
  603. case .addRecipient(_, let recipient):
  604. let paymentMethod = [
  605. "id": recipient.paymentMethod?.id ?? "",
  606. "name": recipient.paymentMethod?.name ?? "",
  607. "currency": recipient.paymentMethod?.currency ?? [],
  608. "localizedName": recipient.paymentMethod?.localizedName ?? ""
  609. ] as [String : Any]
  610. let branch = [
  611. "id": recipient.agent?.branch?.id ?? "",
  612. "name": recipient.agent?.branch?.name ?? "",
  613. "localizedName": recipient.agent?.branch?.name ?? ""
  614. ]
  615. let agent = [
  616. "id": recipient.agent?.id ?? "",
  617. "name": recipient.agent?.name ?? "",
  618. "currency": recipient.agent?.currency ?? [],
  619. "localizedName": recipient.agent?.localizedName ?? "",
  620. "branch": branch,
  621. "accountNo": recipient.agent?.accountNumber ?? ""
  622. ] as [String : Any]
  623. return [
  624. "firstName": recipient.firstName ?? "",
  625. "middleName": recipient.middleName ?? "",
  626. "lastName": recipient.lastName ?? "",
  627. "localFirstName": recipient.localFirstName ?? "",
  628. "localMiddleName": recipient.localMiddleName ?? "",
  629. "localLastName": recipient.localLastName ?? "",
  630. "localFullName": recipient.localFullName ?? "",
  631. "paymentMethod": paymentMethod,
  632. "agent": agent,
  633. "receiverId": recipient.receiverID ?? "",
  634. "country": recipient.country ?? "",
  635. "countryId": recipient.countryID ?? "",
  636. "countryCode": recipient.countryCode ?? "",
  637. "address": recipient.address ?? "",
  638. "state": recipient.state ?? "",
  639. "stateId": recipient.stateID ?? "",
  640. "city": recipient.city ?? "",
  641. "email": recipient.email ?? "",
  642. "mobile": recipient.mobile ?? "",
  643. "relationship": recipient.relationship ?? "",
  644. "relationshipId": recipient.relationshipID ?? "",
  645. "district": recipient.district ?? "",
  646. "districtId": recipient.districtID ?? "",
  647. "purposeOfRemit": recipient.purposeOfRemit ?? "",
  648. "purposeOfRemitId": recipient.purposeOfRemitID ?? "",
  649. "fullName": recipient.fullName ?? "",
  650. "idType": recipient.idType ?? "",
  651. "idNumber": recipient.idNumber ?? "",
  652. "nativeCountry": recipient.nativeCountry ?? "",
  653. "nativeCountryID": recipient.nativeCountryID ?? "",
  654. "nativeCountryCode": recipient.nativeCountryCode ?? ""
  655. ]
  656. case .editRecipient(let senderID, let recipient):
  657. return APIRouter.addRecipient(senderID: senderID, recipient: recipient).parameters
  658. case .validateAccount(let validateModel):
  659. return [
  660. "IdType" : "1",
  661. "IdNumber": "",
  662. "CustomerFirstName": "",
  663. "CustomerLastName": "",
  664. "ReceiverFirstName": validateModel.firstName,
  665. "ReceiverLastName": validateModel.lastName,
  666. "Country": validateModel.country?.countryCode ?? "",
  667. "AccountType": validateModel.accountType,
  668. "IssuerCode": validateModel.bank?.code ?? "",
  669. "AccountNo": validateModel.accountNumber,
  670. "BankCode": validateModel.bank?.code ?? "",
  671. "Amount": validateModel.amount,
  672. "PayoutPartner": validateModel.payoutPartner,
  673. "ProcessId": "",
  674. "BankId": validateModel.bank?.id ?? "",
  675. "ReceiverCountryId": validateModel.country?.countryId ?? "",
  676. "deliveryMethodId": validateModel.paymentMethod?.id ?? ""
  677. ]
  678. case .domesticRemitStart:
  679. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  680. return ["CustomerId": senderID]
  681. case .getRecentHistories(let from, let to):
  682. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  683. return [
  684. "CustomerId": senderID,
  685. "FromDate": from,
  686. "ToDate": to
  687. ]
  688. case .fetchBalace(let type, let fintechUseNumber):
  689. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  690. return [
  691. "CustomerId": senderID,
  692. "type": type,
  693. "FintechUseNo": fintechUseNumber
  694. ]
  695. case .fetchRecipientName(let bankCode, let accountNumber):
  696. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  697. return [
  698. "CustomerId": senderID,
  699. "BankCode": bankCode,
  700. "AccountNumber": accountNumber
  701. ]
  702. case .sendDomesticRemit(let model):
  703. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  704. let userID = GMEDB.shared.user.string(.userId) ?? ""
  705. return [
  706. "CustomerId": senderID,
  707. "userId": userID,
  708. "FintechUseNo": model.fintechID,
  709. "SentAmount": model.sendAmount,
  710. "RecipientBankCode": model.bankCode,
  711. "RecipientAccountNo": model.accountNumber,
  712. "RecipientName": model.name,
  713. "RecipientPhone": model.mobile,
  714. "isUseBiometric": model.isUseBiometric,
  715. "txnPassword": model.password,
  716. "KftcAccountId" : model.accountID,
  717. "type": model.type
  718. ]
  719. case .domesticTransactionHistory(let from, let to):
  720. return [
  721. "FromDate": from,
  722. "ToDate": to
  723. ]
  724. case .fetchCardList(let type, let mobile):
  725. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  726. return [
  727. "CustomerId" : senderID,
  728. "getcardType": type,
  729. "phoneNo": mobile
  730. ]
  731. case .verificationAndBuy(let model):
  732. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  733. // let now = Date()
  734. // let timestamp = "\(Int64(now.timeIntervalSince1970 * 1000))"
  735. return [
  736. "BuyType" : model.type,
  737. "CustomerId" : senderID,
  738. "ReceiptId" : model.receiptID ?? "",
  739. // "OrderNo" : model.orderNo ?? timestamp,
  740. "ChargeType": model.chargeType,
  741. "CardName": model.cardName,
  742. "PhoneNo" : model.mobile,
  743. "ProductPrice" : model.productPrice ?? "",
  744. "UseBalancePrice" : model.useBalancePrice ?? "",
  745. "PassWord": model.password ?? ""
  746. ]
  747. case .fetchRechargeHistory(let from, let to):
  748. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  749. return [
  750. "CustomerId": senderID,
  751. "FromDate" : from,
  752. "ToDate": to
  753. ]
  754. case .penneyTestStart(let model, _):
  755. return [
  756. "accountID": model.accountID ?? "",
  757. "accountType": model.accountType ?? "",
  758. "BankCode": model.bank.bankCode ?? "",
  759. "AccountNo": model.account
  760. ]
  761. case .penneyTestCertified(let model):
  762. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  763. return [
  764. "CustomerId": senderID,
  765. "BankCode": model.bankCode,
  766. "AccountNo": model.accountNo,
  767. "CertNumber": model.verifyNo,
  768. "accountID": model.accountID ?? "",
  769. "accountType": model.accountType ?? ""
  770. ]
  771. case .fetchInboundTransactionHistory(let from, let to):
  772. return [
  773. "FromDate": from,
  774. "ToDate": to,
  775. "tranId": ""
  776. ]
  777. case .saveKYCInformation(let model):
  778. let userID = GMEDB.shared.user.string(.userId) ?? ""
  779. var personalInformation: [String: Any]?
  780. if model.personalInformation != nil {
  781. personalInformation = [
  782. "fullName": model.personalInformation?.fullName ?? "",
  783. "gender": model.personalInformation?.gender ?? "",
  784. "dob": model.personalInformation?.dob ?? "",
  785. "email": model.personalInformation?.email ?? "",
  786. "city": model.personalInformation?.city ?? "",
  787. "address": model.personalInformation?.address ?? ""
  788. ]
  789. }
  790. var primaryInformation: [String: Any]?
  791. if model.primaryInformation != nil {
  792. primaryInformation = [
  793. "bankId": model.primaryInformation?.bankID ?? "",
  794. "bankAccount": model.primaryInformation?.bankAccount ?? "",
  795. "passportNumber": model.primaryInformation?.passportNumber ?? "",
  796. "passportIssueDate": model.primaryInformation?.passportIssueDate ?? "",
  797. "passportExpiryDate": model.primaryInformation?.passportExpiryDate ?? "",
  798. "anotherIDTypeId": model.primaryInformation?.anotherIDType ?? "",
  799. "anotherIDNumber": model.primaryInformation?.anotherIDNumber ?? "",
  800. "anotherIDIssueDate": model.primaryInformation?.anotherIDIssueDate ?? "",
  801. "anotherIDExpiryDate": model.primaryInformation?.anotherIDExpiryDate ?? "",
  802. "branchId": model.primaryInformation?.branchID ?? "",
  803. "refferalCode": model.primaryInformation?.refferalCode ?? ""
  804. ]
  805. }
  806. var pictureInformation: [String: Any]?
  807. if model.pictures != nil {
  808. pictureInformation = [
  809. "passportPicture": model.pictures?.passportPicture ?? "",
  810. "anotherIDPicture": model.pictures?.anotherIDPicture ?? ""
  811. ]
  812. }
  813. return [
  814. "userId" : userID,
  815. "type": model.type,
  816. "personalInformation": personalInformation as Any,
  817. "pictures": pictureInformation as Any,
  818. "primaryInformation": primaryInformation as Any
  819. ]
  820. default: return nil
  821. }
  822. default : return nil
  823. }
  824. }
  825. }