예제 #1
0
        /// <summary>
        /// Validates the mobile phone number.
        /// </summary>
        /// <param name="phoneNumber">The phone number.</param>
        /// <param name="code">The code.</param>
        /// <returns></returns>
        public InfoAccumulator ValidateMobilePhoneNumber(string phoneNumber, string code)
        {
            InfoAccumulator errors = new InfoAccumulator();

            if (string.IsNullOrEmpty(phoneNumber))
            {
                String errorMsg = "got empty phone number";
                Log.Error(errorMsg);
                errors.AddError(errorMsg);
                return(errors);
            }

            if (string.IsNullOrEmpty(code))
            {
                String errorMsg = "got empty code";
                Log.Error(errorMsg);
                errors.AddError(errorMsg);
                return(errors);
            }

            if (!MobilePhoneQueries.ValidateMobilePhoneNumber(phoneNumber, code))
            {
                String errorMsg = String.Format("failed to validate phone number: {0} and code: {1}", phoneNumber, code);
                Log.Warn(errorMsg);
                errors.AddInfo(errorMsg);
            }

            return(errors);
        }
        /// <summary>
        /// Handles the specified response.
        /// </summary>
        /// <param name="response">The response.</param>
        public void Handle(YodleeGetUserAccountsCommandResponse response)
        {
            if (response.IsFailed)
            {
                ReplyToOrigin(response);
                return;
            }

            var existingContentServicesIds = YodleeQueries.GetUserContentServicesIds(response.CustomerId)
                                             .ToLookup(o => o);

            List <YodleeContentServiceAccount> newAccounts = response.Accounts.Where(o => !existingContentServicesIds.Contains(o.ContentServiceId))
                                                             .ToList();

            if (newAccounts.Count > 0)
            {
                InfoAccumulator info = new InfoAccumulator();
                info.AddInfo("customer " + response.CustomerId + "added " + newAccounts.Count + " accounts");
                SaveAccounts(newAccounts, response.UserName, response.UserPassword);
                SendTransactionsRequestCommand(newAccounts, response.UserName, response.UserPassword);
                SendReply(info, response);
            }
            else
            {
                InfoAccumulator info = new InfoAccumulator();
                info.AddError("could not find added account for customer: " + response.CustomerId);
                SendReply(info, response);
            }
        }
예제 #3
0
        /// <summary>
        /// Sends the SMS and if sent saves it in DB.
        /// </summary>
        /// <param name="phoneNumber">The phone number.</param>
        /// <param name="message">The message.</param>
        /// <param name="country">The country.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private async Task <bool> SendSmsAndSave(string phoneNumber, string message, CountryName country, InfoAccumulator errors)
        {
            //validate phone number
            if (string.IsNullOrEmpty(phoneNumber))
            {
                String errorMessage = "attempt to send sms to an empty phone number";
                Log.Error(errorMessage);
                errors.AddError(errorMessage);
                return(false);
            }

            //validate debug mode
            if (IsInDebugMode(phoneNumber))
            {
                return(true);
            }

            string toPhoneNumber = NormalizePhoneNumber(phoneNumber, country);

            //validate message
            if (string.IsNullOrEmpty(message))
            {
                errors.AddInfo("not sending empty message");
                Log.Warn("attempt to send empty message to phone number: " + toPhoneNumber + " . SMS was not send");
                return(false);
            }

            Log.InfoFormat("Sending sms to phone number: {0}, message: {1}", toPhoneNumber, message);

            //send sms
            TwilioSendSmsCommandResponse twilioResponse = await TwilioSmsSender.SendAsync(ThirdPartyService.Address, new TwilioSendSmsCommand {
                Message     = message,
                PhoneNumber = toPhoneNumber
            });

            if (twilioResponse.Sms == null)
            {
                return(false);
            }

            //save sms in DB
            if (!MobilePhoneQueries.SaveTwilioSms(twilioResponse.Sms))
            {
                string errorMsg = String.Format("Failed to save Twilio SMS response to DB: {0}", message);
                Log.Error(errorMsg);
                errors.AddError(errorMsg);
                return(false);
            }

            return(true);
        }