private ChargeAccountValidationResult ValidateChargeAccountIfNecessary(string companyKey, CreateOrderRequest request, Guid orderId, AccountDetail account, bool isFutureBooking, bool isFromWebApp, decimal bookingFees, CreateReportOrder createReportOrder) { string[] prompts = null; int?[] promptsLength = null; string chargeTypeOverride = null; var isChargeAccountPaymentWithCardOnFile = false; if (request.Settings.ChargeTypeId.HasValue && request.Settings.ChargeTypeId.Value == ChargeTypes.Account.Id) { var accountChargeDetail = _accountChargeDao.FindByAccountNumber(request.Settings.AccountNumber); if (accountChargeDetail.UseCardOnFileForPayment) { if (isFromWebApp) { // Charge account cannot support prepaid orders ThrowAndLogException(createReportOrder, ErrorCode.CreateOrder_RuleDisable, _resources.Get("CannotCreateOrderChargeAccountNotSupportedOnWeb", request.ClientLanguageCode)); } if (_paymentService.IsPayPal(account.Id)) { chargeTypeOverride = ChargeTypes.PayPal.Display; request.Settings.ChargeTypeId = ChargeTypes.PayPal.Id; } else { chargeTypeOverride = ChargeTypes.CardOnFile.Display; request.Settings.ChargeTypeId = ChargeTypes.CardOnFile.Id; } isChargeAccountPaymentWithCardOnFile = true; } ValidateChargeAccountAnswers(request.Settings.AccountNumber, request.Settings.CustomerNumber, request.QuestionsAndAnswers, request.ClientLanguageCode, createReportOrder); if (isChargeAccountPaymentWithCardOnFile) { ValidatePayment(companyKey, request, orderId, account, isFutureBooking, request.Estimate.Price, bookingFees, false, createReportOrder); } prompts = request.QuestionsAndAnswers.Select(q => q.Answer).ToArray(); promptsLength = request.QuestionsAndAnswers.Select(q => q.MaxLength).ToArray(); } return(new ChargeAccountValidationResult { Prompts = prompts, PromptsLength = promptsLength, ChargeTypeKeyOverride = chargeTypeOverride, IsChargeAccountPaymentWithCardOnFile = isChargeAccountPaymentWithCardOnFile }); }
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); } }