From 4f858396bd069389cbb08375fb3043ca5a5a1ef8 Mon Sep 17 00:00:00 2001 From: Leeza Baidar Date: Fri, 15 Sep 2023 16:19:41 +0545 Subject: [PATCH] #17825 updated --- Business/Mobile/MobileServices.cs | 78 +++++++++++++++++++------------ Common/Common.csproj | 2 + 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Business/Mobile/MobileServices.cs b/Business/Mobile/MobileServices.cs index 8e4d65d..ed4111c 100644 --- a/Business/Mobile/MobileServices.cs +++ b/Business/Mobile/MobileServices.cs @@ -144,49 +144,61 @@ namespace Business.Mobile { var lang = Convert.ToString(CallContext.GetData(Constants.Language)); JsonRxResponse jsonRx = new JsonRxResponse(); + try { - requestOTPModel.OTP = Utilities.GenerateOTP(); //implement the logic to send OTP SMS in customers mobile. + requestOTPModel.OTP = Utilities.GenerateOTP(); jsonRx = _requestServices.RequestOTP(requestOTPModel); Log.Debug("GenerateOTP | RESPONSE : " + JsonConvert.SerializeObject(jsonRx)); if (jsonRx.ErrorCode == "0") { - // string msgBody = "Dear Customer, your OTP code is: " + requestOTPModel.OTP + " (Valid for " + jsonRx.Extra + " mins)."; + bool emailSent = false; + bool smsSent = false; if (requestOTPModel.userId.IsValidEmail()) { - if (!string.IsNullOrEmpty(jsonRx.Extra2) && jsonRx.Extra2.Equals("100")) { List bodyMappings = new List(); - //bodyMappings.Add(new Notify.Mapping() { SValue = "CustomerName", SText = requestOTPModel.customerName }); + bodyMappings.Add(new Notify.Mapping() { SValue = "CustomerName", SText = requestOTPModel.customerName }); bodyMappings.Add(new Notify.Mapping() { SValue = "OTP_CODE", SText = requestOTPModel.OTP }); bodyMappings.Add(new Notify.Mapping() { SValue = "TYPE", SText = requestOTPModel.requestFor.Equals("REGISTER") ? "customer" : "receiver" }); - - SendNotificationRequest request = new SendNotificationRequest() + try { - IsBulkNotification = false, - UserName = requestOTPModel.userId, - ControlNo = requestOTPModel.receiverId, - ProviderId = "RequestOTP", - Template = Common.Model.Enum.NotifyTemplate.OTP_EMAIL, - Recipients = new List() - { - new RecipientViewModel() + SendNotificationRequest request = new SendNotificationRequest() + { + IsBulkNotification = false, + UserName = requestOTPModel.userId, + ControlNo = requestOTPModel.receiverId, + ProviderId = "RequestOTP", + Template = Common.Model.Enum.NotifyTemplate.OTP_EMAIL, + Recipients = new List() { - NotificationContent = new NotificationDTO() - { - Body = JsonConvert.SerializeObject(bodyMappings), - //Title will be set by mapping json - }, - Address= requestOTPModel.userId, - DeviceType = requestOTPModel.DeviceType, + new RecipientViewModel() + { + NotificationContent = new NotificationDTO() + { + Body = JsonConvert.SerializeObject(bodyMappings), + //Title will be set by mapping json + }, + Address= requestOTPModel.userId, + DeviceType = requestOTPModel.DeviceType, + } } + }; + jsonRx = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL); + emailSent = true; } - }; + catch (Exception emailException) + { + Log.Error("Error sending email", emailException); + } + } + + try + { string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":sendSms"; SendSMSApiService _sendAPI = new SendSMSApiService(); - //GetSMSTextForTxn SMSRequestModel _req = new SMSRequestModel { ProviderId = "onewaysms", @@ -199,23 +211,28 @@ namespace Business.Mobile ControlNo = "", // GetControlNo() }; APIJsonResponse _resp = _sendAPI.SMSTPApi(_req); - jsonRx = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL); + smsSent = true; + } + catch (Exception smsException) + { + Log.Error("Error sending SMS", smsException); + } + if (emailSent || smsSent) + { + jsonRx.ErrorCode = "0"; + jsonRx.SetResponse("0", "OTP has been verified."); + return jsonRx; } - else - Log.Debug("RequestOTP | 103 : " + JsonConvert.SerializeObject(jsonRx)); - } else { jsonRx.ErrorCode = "1"; var map = Utilities.GetLanguageMapping(RESPONSE_MSG.OLD_USER_REGISTER_FAIL_11.ToString(), lang); return new JsonRxResponse { ErrorCode = jsonRx.ErrorCode, Msg = map.Message }; - - ; } } - jsonRx.ErrorCode = jsonRx.ErrorCode == "103" ? "0" : jsonRx.ErrorCode;//103 = previous OTP was not expired so same was used + jsonRx.ErrorCode = jsonRx.ErrorCode == "103" ? "0" : jsonRx.ErrorCode; // 103 = previous OTP was not expired, so the same was used return jsonRx; } catch (Exception ex) @@ -224,6 +241,7 @@ namespace Business.Mobile jsonRx.SetResponse("1", "Error occurred while calling RequestOTP."); return jsonRx; } + } diff --git a/Common/Common.csproj b/Common/Common.csproj index e714da9..efbeaff 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -105,6 +105,7 @@ + @@ -140,6 +141,7 @@ +