Browse Source

#17825 changes of email template

master
Leeza Baidar 1 year ago
parent
commit
4edba7f018
  1. 92
      SendMail/API/ThirdPartyAPI.cs
  2. 212
      SendMail/Business/TxnPush.cs
  3. 26
      SendMail/Common/APIJsonResponse.cs
  4. 12
      SendMail/Common/Enums.cs
  5. 29
      SendMail/Common/Notification.cs
  6. 96
      SendMail/Common/SendNotificationRequest.cs
  7. 26
      SendMail/Common/TxnDetails.cs
  8. 13
      SendMail/DAO/TxnPushDAO.cs
  9. 9
      SendMail/JMETxnPushScheduler.csproj

92
SendMail/API/ThirdPartyAPI.cs

@ -0,0 +1,92 @@
using Common;
using JMETxnPushScheduler.Business;
using JMETxnPushScheduler.Common;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace JMETxnPushScheduler.API
{
public class ThirdPartyAPI
{
private static int timeOut = 100;
private string tp_base_url = GetStatic.ReadWebConfig("ThirdParty_Base_Url", "");
private string apiAccessKey = GetStatic.ReadWebConfig("apiAccessKey", "");
//private readonly ILog _log = LogManager.GetLogger(typeof(ThirdPartyApi));
public ResponseModel ThirdPartyApiGetDataOnly<RequestModel, ResponseModel>(RequestModel model, string api_url, out APIJsonResponse jsonResponse, string MethodType = "post")
{
ResponseModel _responseModel = default(ResponseModel);
using (HttpClient httpClient = new HttpClient())
{
try
{
httpClient.BaseAddress = new Uri(tp_base_url);
httpClient.DefaultRequestHeaders.Add("apiAccessKey", apiAccessKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.Timeout = new TimeSpan(0, 0, timeOut);
HttpResponseMessage resp = new HttpResponseMessage();
if (MethodType.ToLower().Equals("get"))
resp = httpClient.GetAsync(api_url).Result;
if (MethodType.ToLower().Equals("put"))
{
StringContent jbdContent = new StringContent(JsonConvert.SerializeObject(model).ToString(), Encoding.UTF8, "application/json");
resp = httpClient.PutAsync(api_url, jbdContent).Result;
}
if (MethodType.ToLower().Equals("post"))
{
var jsonData = JsonConvert.SerializeObject(model).ToString();
StringContent jbdContent = new StringContent(jsonData, Encoding.UTF8, "application/json");
resp = httpClient.PostAsync(api_url, jbdContent).Result;
}
string resultData = resp.Content.ReadAsStringAsync().Result;
if (resp.IsSuccessStatusCode)
{
var result = resp.Content.ReadAsStringAsync().Result;
JObject a = JObject.Parse(result);
_responseModel = a.ToObject<ResponseModel>();
}
else
{
//_log.Debug("ThirdPartyApiGetDataOnly | RESPONSE: " + resp.ToString());
ErrorJosn errorJson = JsonConvert.DeserializeObject<ErrorJosn>(resultData);
APIJsonResponse jsonResponseData = JsonConvert.DeserializeObject<APIJsonResponse>(errorJson.Message);
List<Data> data = JsonConvert.DeserializeObject<List<Data>>(jsonResponseData.Data.ToString());
jsonResponse = new APIJsonResponse()
{
Id = jsonResponseData.Id,
Msg = jsonResponseData.Msg,
Data = data,
Extra = jsonResponseData.Extra,
Extra1 = jsonResponseData.Extra1
};
}
}
catch (HttpRequestException ex)
{
jsonResponse = new APIJsonResponse()
{
ResponseCode = "999",
Msg = ex.Message,
Data = ex.Data,
};
_responseModel = default(ResponseModel);
}
};
jsonResponse = new APIJsonResponse()
{
ResponseCode = "0",
Msg = "Api Calling process successfully!"
};
return _responseModel;
}
}
}

212
SendMail/Business/TxnPush.cs

@ -1,6 +1,8 @@
using JMETxnPushScheduler.API; using JMETxnPushScheduler.API;
using JMETxnPushScheduler.Common; using JMETxnPushScheduler.Common;
using JMETxnPushScheduler.DAO; using JMETxnPushScheduler.DAO;
using Newtonsoft.Json;
using Swift.API.Common.Enum;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@ -9,9 +11,10 @@ namespace JMETxnPushScheduler.Business
{ {
public class TxnPush public class TxnPush
{ {
TxnPushDAO _txnPush = new TxnPushDAO();
public void TxnSyncMain() public void TxnSyncMain()
{ {
TxnPushDAO _txnPush = new TxnPushDAO();
DataTable txnData = _txnPush.GetTxnDataForApprove(); DataTable txnData = _txnPush.GetTxnDataForApprove();
if (txnData.Rows.Count == 0 || null == txnData) if (txnData.Rows.Count == 0 || null == txnData)
{ {
@ -24,107 +27,166 @@ namespace JMETxnPushScheduler.Business
CommonResponse _dbRes = _txnPush.GetTxnApproveData("schedular", item["ID"].ToString()); CommonResponse _dbRes = _txnPush.GetTxnApproveData("schedular", item["ID"].ToString());
if (_dbRes.ResponseCode == "0") if (_dbRes.ResponseCode == "0")
{ {
if (_dbRes.Extra == "True")//is realtime
Console.WriteLine("Send txn started: " + item["CONTROLNO"].ToString());
string newSession = Guid.NewGuid().ToString().Replace("-", "");
var result = _txnPush.GetHoldedTxnForApprovedByAdmin("scheduler", item["ID"].ToString(), newSession);
Console.WriteLine("Send txn completed with response msg: " + result.Msg);
List<string> exclude = new List<string>() { "7000", "100" };
if (result.ResponseCode != null && result.ResponseCode != "0")
{ {
Console.WriteLine("Release txn started: " + item["CONTROLNO"].ToString());
SendTransactionServices _tpSend = new SendTransactionServices();
var result = _tpSend.ReleaseTransaction(new TFReleaseTxnRequest()
{
TfPin = _dbRes.Id,
RequestBy = "scheduler",
UserName = "scheduler",
ProviderId = _dbRes.Msg
});
if (!exclude.Contains(result.ResponseCode) || !result.Msg.Contains("task was canceled"))
_txnPush.SyncTxnAsComment(_dbRes.Msg, item["ID"].ToString(), item["CONTROLNO"].ToString(), !string.IsNullOrEmpty(result.Extra) ? result.Extra : result.ResponseCode, result.Msg);
else
Console.WriteLine("SyncTxnAsComment exclude Code: " + result.ResponseCode);
}
Console.WriteLine("Release txn completed with response msg: " + result.Msg);
if (_dbRes.Msg == "394397")
{
if (result.ResponseCode == "0") if (result.ResponseCode == "0")
{
_txnPush.UpdateTxnInstantPaid(item["ID"].ToString());
}
else if (result.ResponseCode == "100")//Transaction has been processed for Bank Deposit.
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
}
else if (result.ResponseCode == "7000" && result.Msg.Contains("ALREADY USED"))
{ {
_txnPush.UpdateTxnPost(item["ID"].ToString()); _txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
} }
else
else if (_dbRes.Msg == "394132")
{ {
Console.WriteLine("Send txn started: " + item["CONTROLNO"].ToString());
string newSession = Guid.NewGuid().ToString().Replace("-", "");
var result = _txnPush.GetHoldedTxnForApprovedByAdmin("scheduler", item["ID"].ToString(), newSession);
Console.WriteLine("Send txn completed with response msg: " + result.Msg);
List<string> exclude = new List<string>() { "7000", "100" };
if (result.ResponseCode != null && result.ResponseCode != "0")
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("0006"))) //Duplicate records
{ {
if (!exclude.Contains(result.ResponseCode) || !result.Msg.Contains("task was canceled"))
_txnPush.SyncTxnAsComment(_dbRes.Msg, item["ID"].ToString(), item["CONTROLNO"].ToString(), !string.IsNullOrEmpty(result.Extra) ? result.Extra : result.ResponseCode, result.Msg);
else
Console.WriteLine("SyncTxnAsComment exclude Code: " + result.ResponseCode);
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
if (_dbRes.Msg == "394397")
}
else if (_dbRes.Msg == "394414") //brac
{
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Msg) && result.Msg.Equals("DuplicateTTNumber"))) //004- Duplicate records
{ {
if (result.ResponseCode == "0")
{
_txnPush.UpdateTxnInstantPaid(item["ID"].ToString());
}
else if (result.ResponseCode == "100")//Transaction has been processed for Bank Deposit.
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
else if (result.ResponseCode == "7000" && result.Msg.Contains("ALREADY USED"))
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
else if (_dbRes.Msg == "394132")
}
else if (_dbRes.Msg == "394428") //Cebuana
{
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("05"))) // Control Number Already In Use
{ {
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("0006"))) //Duplicate records
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
else if (_dbRes.Msg == "394414") //brac
else if (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("19")) //"RTA Internal Error-Reference Number Already Exists
{ {
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Msg) && result.Msg.Equals("DuplicateTTNumber"))) //004- Duplicate records
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
else if (_dbRes.Msg == "394428") //Cebuana
}
else if (_dbRes.Msg == "394434") //wings
{
if (result.ResponseCode == "0")
{ {
if (result.ResponseCode == "0" || (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("05"))) // Control Number Already In Use
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
else if (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("19")) //"RTA Internal Error-Reference Number Already Exists
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
else if (_dbRes.Msg == "394434") //wings
else if (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("200")) //" Txn found in wings system.
{ {
if (result.ResponseCode == "0")
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
else if (!string.IsNullOrEmpty(result.Extra) && result.Extra.Equals("200")) //" Txn found in wings system.
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
else
}
else
{
if (result.ResponseCode == "0")
{ {
if (result.ResponseCode == "0")
{
_txnPush.UpdateTxnPost(item["ID"].ToString());
}
_txnPush.UpdateTxnPost(item["ID"].ToString());
GetTxnDetails(item["ID"].ToString());
} }
} }
} }
} }
} }
public void GetTxnDetails(string tranId)
{
TxnDetails cd = _txnPush.GetTxnDetails(tranId);
List<Mapping> bodyMappings = new List<Mapping>();
bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = cd.senderName });
bodyMappings.Add(new Mapping() { SValue = "TxnDate", SText = cd.TranDate });
bodyMappings.Add(new Mapping() { SValue = "RefNum", SText = cd.controlNo });
bodyMappings.Add(new Mapping() { SValue = "TxnDate", SText = cd.TranDate });
bodyMappings.Add(new Mapping() { SValue = "PayoutCountry", SText = cd.PayoutCountry });
bodyMappings.Add(new Mapping() { SValue = "BankName", SText = cd.BankName });
bodyMappings.Add(new Mapping() { SValue = "BankBranch", SText = cd.BankBranch });
bodyMappings.Add(new Mapping() { SValue = "AccNum", SText = cd.AccountNo });
bodyMappings.Add(new Mapping() { SValue = "BeneName", SText = cd.BeneficiaryName });
bodyMappings.Add(new Mapping() { SValue = "PayoutAmt", SText = cd.PayoutAmount });
bodyMappings.Add(new Mapping() { SValue = "TransferAmt", SText = cd.TransferAmount });
bodyMappings.Add(new Mapping() { SValue = "Fee", SText = cd.serviceCharge });
bodyMappings.Add(new Mapping() { SValue = "TotalAmt", SText = cd.TotalAmount });
if(cd.paymentMethod.ToUpper() == "BANK DEPOSIT")
{
SendNotificationRequestMobile request = new SendNotificationRequestMobile()
{
IsBulkNotification = false,
UserName = cd.email,
ProcessId = "BankTxnPushedToAPI",
ProviderId = NotifyTemplate.BANK_TXN_POST.ToString(),
NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
Template = NotifyTemplate.BANK_TXN_POST,
Recipients = new List<RecipientViewModel>()
{
new RecipientViewModel()
{
NotificationContent = new NotificationDTO() {
Body = JsonConvert.SerializeObject(bodyMappings),
//Title will be set by mapping json
},
Address= cd.email
}
}
};
}
else if(cd.paymentMethod.ToUpper() == "CASH PAYMENT")
{
SendNotificationRequestMobile request = new SendNotificationRequestMobile()
{
IsBulkNotification = false,
UserName = cd.email,
ProcessId = "CashTxnPushedToAPI",
ProviderId = NotifyTemplate.CASH_TXN_POST.ToString(),
NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
Template = NotifyTemplate.CASH_TXN_POST,
Recipients = new List<RecipientViewModel>()
{
new RecipientViewModel()
{
NotificationContent = new NotificationDTO() {
Body = JsonConvert.SerializeObject(bodyMappings),
//Title will be set by mapping json
},
Address= cd.email
}
}
};
}
}
public void TxnReleaseMain() public void TxnReleaseMain()
{ {
try try

26
SendMail/Common/APIJsonResponse.cs

@ -0,0 +1,26 @@

namespace Common
{
public class APIJsonResponse
{
public string ResponseCode { get; set; }
public string Msg { get; set; }
public string Id { get; set; }
public object Data { get; set; }
public string Extra { get; set; }
public string Extra1 { get; set; }
public string Extra3 { get; set; }
public string FootNoteMessage { get; set; }
public void SetResponse(string responseCode, string msg, string id = null, string extra = null, string extra1 = null, string extra3 = null, string footNoteMessage = "")
{
ResponseCode = responseCode;
Msg = msg;
Id = id;
Extra = extra;
Extra1 = extra1;
Extra3 = extra3;
FootNoteMessage = footNoteMessage;
}
}
}

12
SendMail/Common/Enums.cs

@ -0,0 +1,12 @@
using System;
namespace Swift.API.Common.Enum
{
[Flags]
public enum NOTIFICATION_TYPE
{
SMS,
EMAIL,
PUSH_NOTIFICATION
}
}

29
SendMail/Common/Notification.cs

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JMETxnPushScheduler.Common
{
[DefaultValue(NONE)]
public enum NotifyTemplate
{
NONE,
[Description("Email to customer txn is created for bank transfer")]
BANK_TRANSFER_TXN_PENDING = 1,
[Description("Email to customer after txn payment is cleared by IME London")]
BANK_TRANSFER_TXN_CLEARED = 2,
[Description("Email to customer after txn is accepted by Pay-out partner")]
BANK_TXN_POST = 3,
[Description("Email to customer after txn has been accepted by Pay-out partner (Cash Collection)")]
CASH_TXN_POST = 4,
}
}

96
SendMail/Common/SendNotificationRequest.cs

@ -0,0 +1,96 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JMETxnPushScheduler.Common
{
public class SendNotificationRequest : CommonRequest
{
public string NotificationTypeId { get; set; }
public bool IsBulkNotification { get; set; }
public string ControlNo { get; set; }
public List<RecipientViewModel> Recipients { get; set; }
}
public class DisplayMailAddress
{
public string FromEmail { get; set; }
public string AliasName { get; set; }
}
public class AttachmentModel
{
public string FileName { get; set; }
public string FilePath { get; set; }
public string FileType { get; set; }
public string Byte64String { get; set; }
}
public class RecipientViewModel
{
public string Address { get; set; }
public string CcAddress { get; set; }
public string BccAddress { get; set; }
public string DeviceType { get; set; }
public DisplayMailAddress MailAddress { get; set; }
public NotificationDTO NotificationContent { get; set; }
}
public class NotificationDTO
{
[JsonProperty("body")]
public string Body { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("image")]
public string Image { get; set; }
public string ClickActivity { get; set; }
public string MessageType { get; set; }
public string NavigateURL { get; set; }
public List<AttachmentModel> Attachments { get; set; }
public List<AttachmentModel> EmbeddedResources { get; set; }
}
public class Mapping
{
public string SValue { get; set; }
public string SText { get; set; }
public string DValue { get; set; }
public string DText { get; set; }
}
public class SendNotificationRequestMobile : CommonRequest
{
public string NotificationTypeId { get; set; }
public bool IsBulkNotification { get; set; }
public string ControlNo { get; set; }
public List<RecipientViewModel> Recipients { get; set; }
public NotifyTemplate Template { get; set; }
public string Language { get; set; }
}
public class CommonRequest
{
public string ProcessId { get; set; }
public string UserName { get; set; }
public string ProviderId { get; set; }
public string SessionId { get; set; }
}
}

26
SendMail/Common/TxnDetails.cs

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JMETxnPushScheduler.Common
{
public class TxnDetails
{
public string senderName { get; set; }
public string controlNo { get; set; }
public string TranDate { get; set; }
public string PayoutCountry { get; set; }
public string BankName { get; set; }
public string BankBranch { get; set; }
public string AccountNo { get; set; }
public string BeneficiaryName { get; set; }
public string PayoutAmount { get; set; }
public string TransferAmount { get; set; }
public string serviceCharge { get; set; }
public string TotalAmount { get; set; }
public string paymentMethod { get; set; }
public string email { get; set; }
}
}

13
SendMail/DAO/TxnPushDAO.cs

@ -45,6 +45,19 @@ namespace JMETxnPushScheduler.DAO
return ParseDbResultWithSql(sql); return ParseDbResultWithSql(sql);
} }
public TxnDetails GetTxnDetails(string tranId)
{
string sql = "EXEC GetUserInfo @FLAG = 'txn-details'";
sql += ", @tranId = " + FilterString(tranId);
return ParseDbResult<TxnDetails>(sql);
}
private T ParseDbResult<T>(string sql)
{
throw new NotImplementedException();
}
public void SyncTxnAsComment(string provider, string tranId, string ControlNo, string status, string msg) public void SyncTxnAsComment(string provider, string tranId, string ControlNo, string status, string msg)
{ {
string sql = "EXEC PROC_TP_TXN_PUSH @flag='add-api-comment'"; string sql = "EXEC PROC_TP_TXN_PUSH @flag='add-api-comment'";

9
SendMail/JMETxnPushScheduler.csproj

@ -63,6 +63,9 @@
<SignAssembly>false</SignAssembly> <SignAssembly>false</SignAssembly>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\WEB_CORE\packages\log4net.2.0.13\lib\net40\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
@ -80,12 +83,18 @@
<ItemGroup> <ItemGroup>
<Compile Include="API\RestApiClient.cs" /> <Compile Include="API\RestApiClient.cs" />
<Compile Include="API\SendTransactionServices.cs" /> <Compile Include="API\SendTransactionServices.cs" />
<Compile Include="API\ThirdPartyAPI.cs" />
<Compile Include="Business\GetStatic.cs" /> <Compile Include="Business\GetStatic.cs" />
<Compile Include="Business\SendEmail.cs" /> <Compile Include="Business\SendEmail.cs" />
<Compile Include="Business\SmtpMailSetting.cs" /> <Compile Include="Business\SmtpMailSetting.cs" />
<Compile Include="Business\TxnPush.cs" /> <Compile Include="Business\TxnPush.cs" />
<Compile Include="Common\APIJsonResponse.cs" />
<Compile Include="Common\CommonResponse.cs" /> <Compile Include="Common\CommonResponse.cs" />
<Compile Include="Common\Enums.cs" />
<Compile Include="Common\Notification.cs" />
<Compile Include="Common\SendNotificationRequest.cs" />
<Compile Include="Common\SendTransactionRequest.cs" /> <Compile Include="Common\SendTransactionRequest.cs" />
<Compile Include="Common\TxnDetails.cs" />
<Compile Include="DAO\SwiftDao.cs" /> <Compile Include="DAO\SwiftDao.cs" />
<Compile Include="DAO\TxnPushDAO.cs" /> <Compile Include="DAO\TxnPushDAO.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />

Loading…
Cancel
Save