Guest User

Untitled

a guest
Nov 8th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. func apiCall2(anyBaseUrl: String = "", apiFunction: ApiName, method m: HTTPMethod = .get,
  2. parameters: [String: Any]? = nil, isJsonEncoding: Bool = false,
  3. completion: @escaping (Bool, Any?, Error?) -> Void) {
  4.  
  5. var requestUrl = "(ActiveBaseURL())(apiFunction.rawValue)"
  6.  
  7. if anyBaseUrl != "" {
  8. requestUrl = "(anyBaseUrl)(apiFunction.rawValue)"
  9. }
  10.  
  11. var param = [String: Any]()
  12.  
  13. if let p = parameters {
  14. param = p
  15. }
  16.  
  17. Alamofire.request(requestUrl, method: m, parameters: param, encoding: isJsonEncoding ? JSONEncoding.default: URLEncoding.default)
  18. .authenticate(user: ApiUserName, password: ApiPassword)
  19. .responseJSON(options: .allowFragments) { response in
  20. print("request body: (response.request?.httpBody)")
  21. if response.result.isSuccess {
  22. }
  23. print(response.result.error?.localizedDescription)
  24. completion(false, nil, response.result.error)
  25. }
  26. }
  27.  
  28. var parms: Parameters {
  29.  
  30. return [
  31. "uid": "3592",
  32. "product": [
  33. ["id": 104,"type":"countryPlan", "qty": 1]
  34. ],
  35. "shipping": ["name":"Test", "mobile": "89464633", "address1": "testevhsd",
  36. "address2": "testfhd", "city": "test city", "state": "sel",
  37. "postal": "672673", "shipment_code": "YES", "country_id": "129"],
  38. "discount_code": "",
  39. "dt":"2018-11-15",
  40. "giftcard_code": "",
  41. "iccid": ""]
  42. }
  43.  
  44. Service.shared.apiCall2(apiFunction: .CheckOut, method: .post, parameters: parms, isJsonEncoding: true) { (success, data, _) in
Add Comment
Please, Sign In to add comment