Example #1
0
 public void CleanUpWebhooksNotificationsFolder()
 {
     try
     {
         if (Directory.Exists(GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER))
         {
             Directory.Delete(GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER, true);
         }
     }
     catch (IOException ex)
     {
         LogInfo.Fatal(ex, $" {EnumExtensions.GetDescription(MPGSAPIResponse.WebhookNotificationFolderDeleteError) + " : "+GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER}");
     }
 }
Example #2
0
 public static void InitSNSNotificationsFolder()
 {
     try
     {
         if (!Directory.Exists(GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER))
         {
             Directory.CreateDirectory(GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER);
         }
     }
     catch (IOException ex)
     {
         LogInfo.Fatal(ex, $": {EnumExtensions.GetDescription(MPGSAPIResponse.WebhookNotificationFolderError) + " : " + GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER}");
     }
 }
Example #3
0
        public Publisher(string accessKey, string secretKey, string topicName)
        {
            try
            {
                var credentials = new BasicAWSCredentials(accessKey, secretKey);

                _snsClient = new AmazonSimpleNotificationServiceClient(credentials, Amazon.RegionEndpoint.APSoutheast1);
                _topicName = topicName;
            }
            catch (ArgumentNullException ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
            catch (WebException ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
            catch (Exception ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
        }
Example #4
0
        public Publisher(string connectionString, string topicName)
        {
            try
            {
                DatabaseResponse configResponse             = ConfigHelper.GetValue(ConfiType.AWS.ToString(), connectionString);
                List <Dictionary <string, string> > _result = ((List <Dictionary <string, string> >)configResponse.Results);
                var credentials = new BasicAWSCredentials(_result.Single(x => x["key"] == "AWSAccessKey")["value"], _result.Single(x => x["key"] == "AWSSecretKey")["value"]);

                _snsClient = new AmazonSimpleNotificationServiceClient(credentials, Amazon.RegionEndpoint.APSoutheast1);
                _topicName = topicName;
            }
            catch (ArgumentNullException ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
            catch (WebException ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
            catch (Exception ex)
            {
                LogInfo.Fatal(ex, "Error while publishing the message queue");
            }
        }
Example #5
0
        public async Task <string> SendSMSNotification(TextMessage _smsdata, IConfiguration _iconfiguration)
        {
            try
            {
                string _warningmsg = "";
                if (_smsdata.PhoneNumber.Length < 8)
                {
                    _warningmsg = "Phone number should be atleast 8 digit long.";
                    LogInfo.Warning(_warningmsg);
                    throw new Exception(_warningmsg);
                }
                else if (_smsdata.PhoneNumber.Length > 11)
                {
                    _warningmsg = "Phone number should not be longer than 11 digits.";
                    LogInfo.Warning(_warningmsg);
                    throw new Exception(_warningmsg);
                }

                long lPhoneNumber = 0;
                if (!long.TryParse(_smsdata.PhoneNumber, out lPhoneNumber))
                {
                    _warningmsg = "Alphabets are not allowed.";
                    LogInfo.Warning(_warningmsg);
                    throw new Exception(_warningmsg);
                }
                if (_smsdata.SMSText.Length > 4000)
                {
                    _warningmsg = "Maximum length of SMS text is 4000.";
                    LogInfo.Warning(_warningmsg);
                    throw new Exception(_warningmsg);
                }
                DatabaseResponse configResponse = ConfigHelper.GetValue("Nexmo", _iconfiguration);

                List <Dictionary <string, string> > _result = (List <Dictionary <string, string> >)configResponse.Results;

                string _nexmoApiKey        = _result.Single(x => x["key"] == "NexmoApiKey")["value"];
                string _nexmoSecret        = _result.Single(x => x["key"] == "NexmoSecret")["value"];
                string _nexmoSmsSignature  = _result.Single(x => x["key"] == "NexmoSmsSignature")["value"];
                string _nexmoWebRequestUrl = _result.Single(x => x["key"] == "NexmoWebRequestUrl")["value"];

                var client = new Client(creds: new Nexmo.Api.Request.Credentials
                {
                    ApiKey    = _nexmoApiKey,
                    ApiSecret = _nexmoSecret
                });

                //Remove + sign if present
                var checkForPlus = _smsdata.PhoneNumber.Substring(0, 1);
                if (checkForPlus == "+")
                {
                    _smsdata.PhoneNumber = _smsdata.PhoneNumber.Remove(0, 1);
                }

                //Append 65 country code if not present
                var checkForCountryCode = _smsdata.PhoneNumber.Substring(0, 2);
                if (checkForCountryCode != "65")
                {
                    _smsdata.PhoneNumber = "65" + _smsdata.PhoneNumber;
                }

                var results = client.SMS.Send(request: new SMS.SMSRequest
                {
                    from = _nexmoSmsSignature,
                    to   = _smsdata.PhoneNumber,
                    text = _smsdata.SMSText
                });

                return("success");
            }
            catch (Exception ex)
            {
                LogInfo.Fatal(ex, "SMS outbound exception");
                return("failure");
            }
        }