public IbsChargeAccount Get(IbsChargeAccountRequest request) { var accountFromIbs = _ibsServiceProvider.ChargeAccount().GetIbsAccount(request.AccountNumber, request.CustomerNumber); var account = new IbsChargeAccount(); Mapper.Map(accountFromIbs, account); return(account); }
private void ValidateChargeAccountAnswers(string accountNumber, string customerNumber, IEnumerable <AccountChargeQuestion> userQuestionsDetails, string clientLanguageCode, CreateReportOrder createReportOrder) { var accountChargeDetail = _accountChargeDao.FindByAccountNumber(accountNumber); if (accountChargeDetail == null) { ThrowAndLogException(createReportOrder, ErrorCode.AccountCharge_InvalidAccountNumber, GetCreateOrderServiceErrorMessage(ErrorCode.AccountCharge_InvalidAccountNumber, clientLanguageCode)); } var answers = userQuestionsDetails.Select(x => x.Answer) .Where(x => x.HasValueTrimmed()); var validation = _ibsServiceProvider.ChargeAccount().ValidateIbsChargeAccount(answers, accountNumber, customerNumber); if (validation.Valid) { return; } if (validation.ValidResponse != null) { var firstError = validation.ValidResponse.IndexOf(false); string errorMessage = null; if (accountChargeDetail != null) { errorMessage = accountChargeDetail.Questions[firstError].ErrorMessage; } ThrowAndLogException(createReportOrder, ErrorCode.AccountCharge_InvalidAnswer, errorMessage); } ThrowAndLogException(createReportOrder, ErrorCode.AccountCharge_InvalidAccountNumber, validation.Message); }
private IbsChargeAccountImportReport ImportAccounts() { var accountsFromIbs = _ibsServiceProvider.ChargeAccount().GetAllAccount(); var ibsAccounts = new List <IbsChargeAccount>(); Mapper.Map(accountsFromIbs, ibsAccounts); var chargeAccountsToImport = GetNewChargeAccounts(ibsAccounts).ToList(); var existingAccounts = ibsAccounts .Where(x => chargeAccountsToImport.All(y => y.AccountNumber != x.AccountNumber)) .ToList(); var chargeAccounNumbers = chargeAccountsToImport .Select(x => x.AccountNumber) .Distinct(); var report = new IbsChargeAccountImportReport(); var importedTaxiHailChargeAccounts = new List <Common.Entity.AccountCharge>(); chargeAccounNumbers.ForEach(ibsChargeAccount => { var questions = chargeAccountsToImport .Where(x => x.AccountNumber == ibsChargeAccount) .SelectMany(x => x.Prompts.Where(p => !string.IsNullOrWhiteSpace(p.Caption))); var taxiHailQuestions = new List <AccountChargeQuestion>(); var questionIndex = 0; var accountId = Guid.NewGuid(); questions.DistinctBy(p => p.Caption).ForEach(ibsQuestion => { var caption = ibsQuestion.Caption; var length = ibsQuestion.Length; var toBeValidated = ibsQuestion.ToBeValidated; taxiHailQuestions.Add(new AccountChargeQuestion { IsCaseSensitive = false, ErrorMessage = "Wrong answer", IsRequired = toBeValidated, MaxLength = length, Question = caption, Id = questionIndex++, Answer = "", AccountId = accountId }); }); // Needed for now: Add empty questions to obtain 8 var count = taxiHailQuestions.Count; for (int i = 0; i < 8 - count; i++) { taxiHailQuestions.Add(new AccountChargeQuestion { Id = questionIndex++, IsRequired = false, IsCaseSensitive = false, AccountId = accountId }); } importedTaxiHailChargeAccounts.Add(new Common.Entity.AccountCharge { AccountChargeId = accountId, Name = ibsChargeAccount, Number = ibsChargeAccount, Questions = taxiHailQuestions.ToArray() }); var line = new KeyValuePair <string, string>("new", ibsChargeAccount); report.ReportLines.Add(line); }); _commandBus.Send(new ImportAccountCharge { AccountCharges = importedTaxiHailChargeAccounts.ToArray(), CompanyId = AppConstants.CompanyId }); existingAccounts.ForEach(existing => { var existingLine = new KeyValuePair <string, string>("existing", string.Format("{0} (Customer {1}) Already Existing", existing.AccountNumber, existing.CustomerNumber)); report.ReportLines.Add(existingLine); }); return(report); }
public object Put(AccountUpdateRequest accountUpdateRequest) { Guid accountId = accountUpdateRequest.AccountId; var request = accountUpdateRequest.BookingSettingsRequest; AccountDetail existingEmailAccountDetail = _accountDao.FindByEmail(request.Email); AccountDetail currentAccountDetail = _accountDao.FindById(accountId); if (currentAccountDetail.Email != request.Email && currentAccountDetail.FacebookId.HasValue()) { throw new HttpError(HttpStatusCode.BadRequest, _resources.Get("EmailChangeWithFacebookAccountErrorMessage")); } if (existingEmailAccountDetail != null && existingEmailAccountDetail.Email == request.Email && existingEmailAccountDetail.Id != accountId) { throw new HttpError(HttpStatusCode.BadRequest, ErrorCode.EmailAlreadyUsed.ToString(), _resources.Get("EmailUsedMessage")); } CountryCode countryCode = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode(request.Country)); if (PhoneHelper.IsPossibleNumber(countryCode, request.Phone)) { request.Phone = PhoneHelper.GetDigitsFromPhoneNumber(request.Phone); } else { throw new HttpError(string.Format(_resources.Get("PhoneNumberFormat"), countryCode.GetPhoneExample())); } var isChargeAccountEnabled = _serverSettings.GetPaymentSettings().IsChargeAccountPaymentEnabled; // Validate account number if charge account is enabled and account number is set. if (isChargeAccountEnabled && !string.IsNullOrWhiteSpace(request.AccountNumber)) { if (!request.CustomerNumber.HasValue()) { throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString()); } // Validate locally that the account exists var account = _accountChargeDao.FindByAccountNumber(request.AccountNumber); if (account == null) { throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString()); } // Validate with IBS to make sure the account/customer is still active var ibsChargeAccount = _ibsServiceProvider.ChargeAccount().GetIbsAccount(request.AccountNumber, request.CustomerNumber); if (!ibsChargeAccount.IsValid()) { throw new HttpError(HttpStatusCode.Forbidden, ErrorCode.AccountCharge_InvalidAccountNumber.ToString()); } } var command = new UpdateBookingSettings(); Mapper.Map(request, command); command.AccountId = accountId; _commandBus.Send(command); return(new HttpResult(HttpStatusCode.OK)); }
public object Get(AccountChargeRequest request) { var isAdmin = SessionAs <AuthUserSession>().HasPermission(RoleName.Admin); if (!request.AccountNumber.HasValue()) { var allAccounts = _dao.GetAll(); if (request.HideAnswers || !isAdmin) { foreach (var account in allAccounts) { HideAnswers(account.Questions); } } return(allAccounts .Select(acc => new { acc.Name, AccountNumber = acc.Number, acc.Questions, acc.Id, acc.UseCardOnFileForPayment }) .ToArray()); } else { // Validate locally that the account exists var account = _dao.FindByAccountNumber(request.AccountNumber); if (account == null) { throw new HttpError(HttpStatusCode.NotFound, "Account Not Found"); } // Validate with IBS to make sure the account/customer is still active var ibsChargeAccount = _ibsServiceProvider.ChargeAccount().GetIbsAccount(request.AccountNumber, request.CustomerNumber ?? "0"); if (ibsChargeAccount == null || !ibsChargeAccount.IsValid()) { throw new HttpError(HttpStatusCode.NotFound, "Account Not Found"); } var customerSpecificQuestions = ibsChargeAccount.Prompts.ToArray(); var questionsToRemove = account.Questions.Where(question => question.Question.HasValueTrimmed() && customerSpecificQuestions.None(prompt => question.Question == prompt.Caption)) .ToArray(); account.Questions.Remove(p => questionsToRemove.Contains(p)); if (questionsToRemove.Any()) { foreach (var t in questionsToRemove) { account.Questions.Add(new AccountChargeQuestion { Id = t.Id, IsRequired = false, IsCaseSensitive = false, AccountId = account.Id }); } } if (request.HideAnswers || !isAdmin) { HideAnswers(account.Questions); } var currentUser = new Guid(this.GetSession().UserAuthId); LoadCustomerAnswers(account.Questions, currentUser); return(account); } }