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.
230 lines
11 KiB
230 lines
11 KiB
using CustomerOnlineV2.Common.Models;
|
|
using CustomerOnlineV2.Common.Models.TransactionModel;
|
|
using CustomerOnlineV2.Common.Models.RegisterModel;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using static CustomerOnlineV2.Common.Models.CommonResponse;
|
|
using CustomerOnlineV2.Common.Models.Notification;
|
|
using Microsoft.Extensions.Configuration;
|
|
using CustomerOnlineV2.Common.Helper;
|
|
|
|
namespace CustomerOnlineV2.Api.API.TPApi
|
|
{
|
|
public class TPApiService : ITPApiService
|
|
{
|
|
private readonly ILogger<TPApiService> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
public TPApiService(ILogger<TPApiService> logger, IConfiguration configuration)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
}
|
|
public string tp_base_url = Utilities.ReadFromAppSettings("tp_base_url");
|
|
|
|
public async Task<ExrateResponse> GetExRate(ExrateCalculateRequestModel _request)
|
|
{
|
|
ExrateResponse _response = new ExrateResponse();
|
|
TPResponse _responseTP = new TPResponse();
|
|
using (HttpClient client = new HttpClient())
|
|
{
|
|
try
|
|
{
|
|
var content = new StringContent(JsonConvert.SerializeObject(_request), Encoding.UTF8, "application/json");
|
|
|
|
_logger.LogDebug("TPAPISERVICE | GETEXRATE | CALLING TPAPI | " + JsonConvert.SerializeObject(_request));
|
|
// Send the POST request
|
|
string url = $"{tp_base_url}Tp/ExRate";
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
_logger.LogDebug($"TPAPISERVICE | GETEXRATE | API RESPONSE | RESPONSE CODE: {response.StatusCode}| RESPONSE: {JsonConvert.SerializeObject(response.Content.ReadAsStringAsync())}");
|
|
// Check if the response is successful
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string responseContent = await response.Content.ReadAsStringAsync();
|
|
_responseTP = JsonConvert.DeserializeObject<TPResponse>(responseContent);
|
|
|
|
_response.ResponseCode = Convert.ToInt16(_responseTP.ResponseCode);
|
|
_response.ResponseMessage = _responseTP.Msg;
|
|
|
|
if (_response.ResponseCode == ResponseHelper.SUCCESS)
|
|
{
|
|
_response = JsonConvert.DeserializeObject<ExrateResponse>(JsonConvert.SerializeObject(_responseTP.Data));
|
|
|
|
_response.ResponseCode = ResponseHelper.SUCCESS;
|
|
_response.ResponseMessage = ResponseMessageHelper.SUCCESS;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_response.ResponseCode = ResponseHelper.FAILED;
|
|
_response.ResponseMessage = "Error occured while calling getting exrate from TPAPI: ";
|
|
|
|
_logger.LogError("TRANSACTIONREPOSITORY | GETEXRATE | ERROR | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_response.ResponseCode = ResponseHelper.EXCEPTION;
|
|
_response.ResponseMessage = "Exception occured: " + ex.Message;
|
|
|
|
_logger.LogError("TRANSACTIONREPOSITORY | GETEXRATE | EXCEPTION | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
return _response;
|
|
}
|
|
|
|
public async Task<SendMoneyResponse> SendMoney(SendMoneyRequestModel _request)
|
|
{
|
|
SendMoneyResponse _response = new SendMoneyResponse();
|
|
TPResponse _responseTP = new TPResponse();
|
|
using (HttpClient client = new HttpClient())
|
|
{
|
|
try
|
|
{
|
|
var content = new StringContent(JsonConvert.SerializeObject(_request), Encoding.UTF8, "application/json");
|
|
|
|
_logger.LogDebug("TPAPISERVICE | SENDMONEY | CALLING TPAPI | " + JsonConvert.SerializeObject(_request));
|
|
// Send the POST request
|
|
string url = $"{tp_base_url}TP/mobileSendTxn";
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
_logger.LogDebug($"TPAPISERVICE | SENDMONEY | API RESPONSE | RESPONSE CODE: {response.StatusCode}| RESPONSE: {JsonConvert.SerializeObject(response.Content.ReadAsStringAsync())}");
|
|
// Check if the response is successful
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string responseContent = await response.Content.ReadAsStringAsync();
|
|
_responseTP = JsonConvert.DeserializeObject<TPResponse>(responseContent);
|
|
|
|
_response.ResponseCode = Convert.ToInt16(_responseTP.ResponseCode);
|
|
_response.ResponseMessage = _responseTP.Msg;
|
|
|
|
if (_response.ResponseCode == ResponseHelper.SUCCESS)
|
|
{
|
|
_response.ResponseCode = ResponseHelper.SUCCESS;
|
|
_response.ResponseMessage = _responseTP.Msg;
|
|
_response.ControlNo = _responseTP.Extra;
|
|
_response.TransactionId = _responseTP.Id;
|
|
_response.Extra2 = _responseTP.Extra2;
|
|
_response.Extra3 = _responseTP.Extra3;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_response.ResponseCode = ResponseHelper.FAILED;
|
|
_response.ResponseMessage = "Error occured while calling getting exrate from TPAPI: ";
|
|
|
|
_logger.LogError("TRANSACTIONREPOSITORY | SENDMONEY | ERROR | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_response.ResponseCode = ResponseHelper.EXCEPTION;
|
|
_response.ResponseMessage = "Exception occured: " + ex.Message;
|
|
|
|
_logger.LogError("TRANSACTIONREPOSITORY | SENDMONEY | EXCEPTION | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
return _response;
|
|
}
|
|
public async Task<AddressListResponse> GetAddressList(AddressRequest _request)
|
|
{
|
|
AddressListResponse _response = new AddressListResponse();
|
|
TPResponse _responseTP = new TPResponse();
|
|
using (HttpClient client = new HttpClient())
|
|
{
|
|
try
|
|
{
|
|
var content = new StringContent(JsonConvert.SerializeObject(_request), Encoding.UTF8, "application/json");
|
|
_logger.LogDebug("TPAPISERVICE | GETADDRESSLIST | CALLING TPAPI | " + JsonConvert.SerializeObject(_request));
|
|
string url = $"{tp_base_url}TP/addressList";
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
_logger.LogDebug($"TPAPISERVICE | GETADDRESSLIST | API RESPONSE | RESPONSE CODE: {response.StatusCode} | RESPONSE: {JsonConvert.SerializeObject(response.Content.ReadAsStringAsync())}");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string responseContent = await response.Content.ReadAsStringAsync();
|
|
_responseTP = JsonConvert.DeserializeObject<TPResponse>(responseContent);
|
|
_response.ResponseCode = Convert.ToInt16(_responseTP.ResponseCode);
|
|
_response.Msg = _responseTP.Msg;
|
|
if (_response.ResponseCode == ResponseHelper.SUCCESS)
|
|
{
|
|
_response.ResponseCode = ResponseHelper.SUCCESS;
|
|
_response.Msg = _responseTP.Msg;
|
|
_response.Data = _responseTP.Data;
|
|
_response.Extra1 = _responseTP.Extra;
|
|
_response.Extra2 = _responseTP.Extra2;
|
|
}
|
|
else
|
|
{
|
|
_response.ResponseCode = ResponseHelper.FAILED;
|
|
_response.Msg = "Error occured while calling getting exrate from TPAPI: ";
|
|
_logger.LogError("ADDRESSlISTRESPONSE | GETADDRESSLIST | ERROR | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_response.ResponseCode = ResponseHelper.EXCEPTION;
|
|
_response.Msg = "Exception occured: " + ex.Message;
|
|
_logger.LogError("ADDRESSlISTRESPONSE | GETADDRESSLIST | ERROR | " + JsonConvert.SerializeObject(_response));
|
|
}
|
|
}
|
|
return _response;
|
|
}
|
|
|
|
|
|
public async Task<CommonResponse> SendNotification(SendNotificationRequest request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION)
|
|
{
|
|
CommonResponse jsonResponse = new CommonResponse();
|
|
using (HttpClient client = new HttpClient())
|
|
{
|
|
|
|
|
|
var obj = JsonConvert.SerializeObject(request);
|
|
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
|
|
try
|
|
{
|
|
string URL = $"{tp_base_url}NotificationAPI";
|
|
|
|
HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result;
|
|
string resultData = resp.Content.ReadAsStringAsync().Result;
|
|
if (resp.IsSuccessStatusCode)
|
|
{
|
|
jsonResponse = JsonConvert.DeserializeObject<CommonResponse>(resultData);
|
|
var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject<CommonResponse>(jsonResponse.Data.ToString()) : null);
|
|
jsonResponse.Data = a;
|
|
|
|
return jsonResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorJson = JsonConvert.DeserializeObject<CommonResponse.ErrorJosn>(resultData);
|
|
var jsonResponseData = JsonConvert.DeserializeObject<CommonResponse>(errorJson.Message);
|
|
|
|
jsonResponse.Id = jsonResponseData.Id;
|
|
jsonResponse.ResponseCode = jsonResponseData.ResponseCode;
|
|
jsonResponse.Msg = jsonResponseData.Msg;
|
|
jsonResponse.Extra = jsonResponseData.Extra;
|
|
jsonResponse.Extra1 = jsonResponseData.Extra1;
|
|
return jsonResponse;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new CommonResponse()
|
|
{
|
|
ResponseCode = 1,
|
|
Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message)
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|