diff --git a/SendMail/API/ThirdPartyAPI.cs b/SendMail/API/ThirdPartyAPI.cs new file mode 100644 index 0000000..caa530e --- /dev/null +++ b/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 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(); + } + else + { + //_log.Debug("ThirdPartyApiGetDataOnly | RESPONSE: " + resp.ToString()); + ErrorJosn errorJson = JsonConvert.DeserializeObject(resultData); + APIJsonResponse jsonResponseData = JsonConvert.DeserializeObject(errorJson.Message); + List data = JsonConvert.DeserializeObject>(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; + } + } +} diff --git a/SendMail/Business/TxnPush.cs b/SendMail/Business/TxnPush.cs index ca65d31..e286042 100644 --- a/SendMail/Business/TxnPush.cs +++ b/SendMail/Business/TxnPush.cs @@ -1,6 +1,8 @@ using JMETxnPushScheduler.API; using JMETxnPushScheduler.Common; using JMETxnPushScheduler.DAO; +using Newtonsoft.Json; +using Swift.API.Common.Enum; using System; using System.Collections.Generic; using System.Data; @@ -9,9 +11,10 @@ namespace JMETxnPushScheduler.Business { public class TxnPush { + TxnPushDAO _txnPush = new TxnPushDAO(); public void TxnSyncMain() { - TxnPushDAO _txnPush = new TxnPushDAO(); + DataTable txnData = _txnPush.GetTxnDataForApprove(); if (txnData.Rows.Count == 0 || null == txnData) { @@ -24,107 +27,166 @@ namespace JMETxnPushScheduler.Business CommonResponse _dbRes = _txnPush.GetTxnApproveData("schedular", item["ID"].ToString()); 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 exclude = new List() { "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") + { + _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()); + 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 exclude = new List() { "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 bodyMappings = new List(); + + 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() + { + 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() + { + new RecipientViewModel() + { + NotificationContent = new NotificationDTO() { + Body = JsonConvert.SerializeObject(bodyMappings), + //Title will be set by mapping json + }, + Address= cd.email + } + } + }; + } + + } + + public void TxnReleaseMain() { try diff --git a/SendMail/Common/APIJsonResponse.cs b/SendMail/Common/APIJsonResponse.cs new file mode 100644 index 0000000..338b92c --- /dev/null +++ b/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; + } + } +} diff --git a/SendMail/Common/Enums.cs b/SendMail/Common/Enums.cs new file mode 100644 index 0000000..428e4da --- /dev/null +++ b/SendMail/Common/Enums.cs @@ -0,0 +1,12 @@ +using System; + +namespace Swift.API.Common.Enum +{ + [Flags] + public enum NOTIFICATION_TYPE + { + SMS, + EMAIL, + PUSH_NOTIFICATION + } +} diff --git a/SendMail/Common/Notification.cs b/SendMail/Common/Notification.cs new file mode 100644 index 0000000..74314f2 --- /dev/null +++ b/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, + + } +} diff --git a/SendMail/Common/SendNotificationRequest.cs b/SendMail/Common/SendNotificationRequest.cs new file mode 100644 index 0000000..54143d1 --- /dev/null +++ b/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 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 Attachments { get; set; } + + public List 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 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; } + } +} diff --git a/SendMail/Common/TxnDetails.cs b/SendMail/Common/TxnDetails.cs new file mode 100644 index 0000000..10f06db --- /dev/null +++ b/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; } + } +} diff --git a/SendMail/DAO/TxnPushDAO.cs b/SendMail/DAO/TxnPushDAO.cs index 7bcafc9..327c2bc 100644 --- a/SendMail/DAO/TxnPushDAO.cs +++ b/SendMail/DAO/TxnPushDAO.cs @@ -45,6 +45,19 @@ namespace JMETxnPushScheduler.DAO return ParseDbResultWithSql(sql); } + public TxnDetails GetTxnDetails(string tranId) + { + string sql = "EXEC GetUserInfo @FLAG = 'txn-details'"; + sql += ", @tranId = " + FilterString(tranId); + + return ParseDbResult(sql); + } + + private T ParseDbResult(string sql) + { + throw new NotImplementedException(); + } + public void SyncTxnAsComment(string provider, string tranId, string ControlNo, string status, string msg) { string sql = "EXEC PROC_TP_TXN_PUSH @flag='add-api-comment'"; diff --git a/SendMail/JMETxnPushScheduler.csproj b/SendMail/JMETxnPushScheduler.csproj index 1739f5d..7391f62 100644 --- a/SendMail/JMETxnPushScheduler.csproj +++ b/SendMail/JMETxnPushScheduler.csproj @@ -63,6 +63,9 @@ false + + ..\..\WEB_CORE\packages\log4net.2.0.13\lib\net40\log4net.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -80,12 +83,18 @@ + + + + + +