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.

69 lines
2.2 KiB

  1. //
  2. // autoRefundService.swift
  3. // GME Remit
  4. //
  5. // Created by Mac on 11/21/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. protocol FetchAutoRefundInfo: ApiServiceType {
  11. func fetchAutoRefundInfo(username: String, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ())
  12. }
  13. extension FetchAutoRefundInfo {
  14. func fetchAutoRefundInfo(username: String, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ()) {
  15. let url = baseUrl + "refund/\(username)"
  16. auth.request(method: .get, url: url, params: nil, encoding: URLEncoding.default, success: { (response: AutoRefundContainer) in
  17. if let model = response.data {
  18. success(model)
  19. }else {
  20. let error = NSError.init(domain: "FetchAutoRefundInfo", code: 0, userInfo: [NSLocalizedDescriptionKey : "Could not parse json"])
  21. }
  22. }) { (error) in
  23. failure(error)
  24. }
  25. }
  26. }
  27. protocol RefundService: ApiServiceType {
  28. func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (SuccessMessage?) -> (), failure: @escaping (Error) -> ())
  29. }
  30. extension RefundService {
  31. func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (SuccessMessage?) -> (), failure: @escaping (Error) -> ()) {
  32. let url = baseUrl + "refund/proceed"
  33. let params = [
  34. "Username": userName,
  35. "Amount": amount,
  36. "ChargeAmount": chargeAmount,
  37. "UserId": userId
  38. ]
  39. auth.request(method: .post, url: url, params: params, success: { (response: SuccessMessageContainer) in
  40. if (response.errorCode ?? "") == "1" {
  41. let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
  42. failure(error)
  43. }else {
  44. success(response.data)
  45. }
  46. }) { (error) in
  47. failure(error)
  48. }
  49. }
  50. }
  51. //{
  52. // "Username":"demo.gme@gmeremit.com",
  53. // "Amount":"11000",
  54. // "ChargeAmount":"1000",
  55. // "UserId":"39442"
  56. //}