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.

49 lines
1.9 KiB

  1. using CustomerOnlineRemit.Common.Model;
  2. using CustomerOnlineRemit.Common.Model.Transaction;
  3. using Newtonsoft.Json;
  4. using System.Text;
  5. namespace CustomerOnlineRemit.Business.TPApiHelper
  6. {
  7. public class APIHelper : IAPIHelper
  8. {
  9. public async Task<ExrateResponse> GetExRate(ExrateCalculateRequestModel _request)
  10. {
  11. ExrateResponse _response = new ExrateResponse();
  12. TPResponse _responseTP = new TPResponse();
  13. using (HttpClient client = new HttpClient())
  14. {
  15. try
  16. {
  17. var content = new StringContent(JsonConvert.SerializeObject(_request), Encoding.UTF8, "application/json");
  18. // Send the POST request
  19. HttpResponseMessage response = await client.PostAsync("http://77.68.15.91:1083/api/v1/TP/ExRate", content);
  20. // Check if the response is successful
  21. if (response.IsSuccessStatusCode)
  22. {
  23. string responseContent = await response.Content.ReadAsStringAsync();
  24. _responseTP = JsonConvert.DeserializeObject<TPResponse>(responseContent);
  25. if (_responseTP.ResponseCode == "0")
  26. {
  27. _response = JsonConvert.DeserializeObject<ExrateResponse>(JsonConvert.SerializeObject(_responseTP.Data));
  28. _response.ResponseCode = ResponseHelper.SUCCESS;
  29. _response.ResponseMessage = ResponseMessageHelper.SUCCESS;
  30. }
  31. }
  32. else
  33. {
  34. Console.WriteLine("Error: " + response.ReasonPhrase);
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. Console.WriteLine("Error: " + ex.Message);
  40. }
  41. }
  42. return _response;
  43. }
  44. }
  45. }