public List <string> FetchMarketingSourceByZip(string guid, string text) { var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid); var model = new OnlineSchedulingCustomerInfoEditModel { RequestValidationModel = onlineRequestValidationModel }; var tempCart = onlineRequestValidationModel.TempCart; string zip = ""; var customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null; if (customer != null) { zip = customer.Address.ZipCode.Zip; } return(_marketingSourceService.FetchMarketingSourceByZip(zip, true).Where(x => x.ToLower().StartsWith(text.ToLower())).ToList()); }
public OnlineSchedulingCustomerInfoEditModel SavePaymentInfo(OnlineSchedulingCustomerInfoEditModel model) { OnlineSchedulingProcessAndCartViewModel cartModel = model.ProcessAndCartViewModel; SourceCodeApplyEditModel sourceCodeModel = model.SourceCodeApplyEditModel; PaymentEditModel paymentModel = model.PaymentEditModel; var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(cartModel.CartGuid); model.RequestValidationModel = onlineRequestValidationModel; if (onlineRequestValidationModel.RequestStatus != OnlineRequestStatus.Valid) { return(model); } var tempCart = onlineRequestValidationModel.TempCart; if (tempCart.EventId.HasValue) { var summarymodel = _eventSchedulerService.GetEventCustomerOrderSummaryModel(tempCart); var couponAmount = sourceCodeModel != null ? sourceCodeModel.DiscountApplied : 0; if ((summarymodel.TotalPrice != null && summarymodel.TotalPrice.Value != (paymentModel.Amount + couponAmount)) || (summarymodel.TotalPrice == null && paymentModel.Amount > 0)) { throw new Exception("Seems like you changed your order. Please go back to the Package screen, and confirm!"); } var result = ValidatePaymentModel(paymentModel); if (!result) { throw new Exception("Payment error - Please re-enter your payment information or contact our customer care line at " + _settings.PhoneTollFree); } var isAppointmentTemporarilyBooked = _slotService.IsSlotTemporarilyBooked(tempCart.InChainAppointmentSlotIds); if (!isAppointmentTemporarilyBooked) { //throw new Exception("The appointment time selected by you is no longer temporarliy booked for you. Please go back to appointment page to choose the time slot"); model.PaymentEditModel.IsTemporaryBookedSlotExpired = true; return(model); } var isAppointmentBooked = _slotService.IsSlotBooked(tempCart.InChainAppointmentSlotIds); if (isAppointmentBooked) { throw new Exception("The appointment slot selected by you seems to have exhausted. Please re-select another slot!"); } } bool? paymentSucceded = null; Customer customer; try { using (var scope = new TransactionScope()) { customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null; var address = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress); address = _addressService.SaveAfterSanitizing(address, true); if (customer == null) { throw new Exception("System Failure! Data not saved. Please try again."); } var customerAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress); customerAddress = _addressService.SaveAfterSanitizing(customerAddress, true); customer.Address = customerAddress; customer.RequestForNewsLetter = model.RequestForNewsLetter; if (paymentModel.Payments != null && paymentModel.Payments.Where(p => p.PaymentType != PaymentType.Onsite_Value && p.PaymentType != PaymentType.GiftCertificate.PersistenceLayerId).Count() > 0) { if (paymentModel.ExistingBillingAddress != null) { if (customer.BillingAddress != null && customer.BillingAddress.Id > 0) { paymentModel.ExistingBillingAddress.Id = customer.BillingAddress.Id; } var billingAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingBillingAddress); billingAddress = _addressService.SaveAfterSanitizing(billingAddress, true); customer.BillingAddress = billingAddress; } } else { var billingAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress); billingAddress = _addressService.SaveAfterSanitizing(billingAddress, true); customer.BillingAddress = billingAddress; } _customerService.SaveCustomer(customer, customer.CustomerId); tempCart.SourceCodeId = sourceCodeModel == null || sourceCodeModel.SourceCodeId < 1 ? null : (long?)sourceCodeModel.SourceCodeId; tempCart.ShippingAddressId = address.Id; tempCart.ScreenResolution = cartModel.ScreenResolution; if (paymentModel.Payments != null) { tempCart.PaymentMode = ""; if (paymentModel.Payments.Any(p => p.ChargeCard != null)) { tempCart.PaymentMode += PaymentType.CreditCard.Name + ","; } if (paymentModel.Payments.Any(p => p.ECheck != null)) { tempCart.PaymentMode += PaymentType.ElectronicCheck.Name + ","; } if (paymentModel.Payments.Any(p => p.GiftCertificate != null)) { tempCart.PaymentMode += PaymentType.GiftCertificate.Name + ","; } if (paymentModel.Payments.Any(p => p.PaymentType == (int)PaymentType.Onsite_Value)) { tempCart.PaymentMode += PaymentType.PayLater_Text + ","; } tempCart.PaymentMode = tempCart.PaymentMode.Substring(0, tempCart.PaymentMode.LastIndexOf(",")); } tempCart.PaymentAmount = paymentModel.Amount; try { _eventSchedulerService.CreateOrder(tempCart, paymentModel); paymentSucceded = true; } catch (Exception ex) { _paymentController.VoidCreditCardGatewayRequests(paymentModel); paymentSucceded = false; throw new Exception("\nOnline Payment. Message: " + ex.Message + ". \n\t Stack Trace: " + ex.StackTrace); } tempCart.IsPaymentSuccessful = true; tempCart.IsCompleted = true; _tempcartService.SaveTempCart(tempCart); UpdateProspectCustomer(tempCart, customer); scope.Complete(); } try { var account = _corporateAccountRepository.GetbyEventId(tempCart.EventId.Value); if (account == null || account.SendWelcomeEmail) { var welcomeEmailViewModel = _emailNotificationModelsFactory.GetWelcomeWithUserNameNotificationModel(customer.UserLogin.UserName, customer.Name.FullName, customer.DateCreated); _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.CustomerWelcomeEmailWithUsername, EmailTemplateAlias.CustomerWelcomeEmailWithUsername, welcomeEmailViewModel, customer.Id, customer.CustomerId, Request.RequestUri.OriginalString); } var eventData = _eventRepository.GetById(tempCart.EventId.Value); _customerRegistrationService.SendAppointmentConfirmationMail(customer, eventData, customer.CustomerId, Request.RequestUri.OriginalString, account); //If somebody registered within 24 hours of the event Date then send notification. if (eventData.EventDate.AddDays(-1).Date <= DateTime.Now.Date) { var appointmentBookedInTwentyFourHoursNotificationModel = _emailNotificationModelsFactory.GetAppointmentBookedInTwentyFourHoursModel(tempCart.EventId.Value, tempCart.CustomerId.Value); _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.AppointmentBookedInTwentyFourHours, EmailTemplateAlias.AppointmentBookedInTwentyFourHours, appointmentBookedInTwentyFourHoursNotificationModel, 0, customer.CustomerId, Request.RequestUri.OriginalString); } _callQueueCustomerRepository.UpdateOtherCustomerStatus(customer.CustomerId, tempCart.ProspectCustomerId.HasValue ? tempCart.ProspectCustomerId.Value : 0, CallQueueStatus.Completed, customer.CustomerId); _eventSchedulingSlotService.SendEventFillingNotification(tempCart.EventId.Value, customer.CustomerId); } catch (Exception) { //throw new Exception("\nOnline Payment. Exception caused while sending notification. Message: " + ex.Message); } } catch (InvalidAddressException ex) { throw new Exception("Address provided by you is not a valid address. " + ex.Message); } catch (Exception) { if (paymentSucceded != null && paymentSucceded == false) { tempCart.IsPaymentSuccessful = false; tempCart.IsCompleted = false; tempCart.PaymentMode = ""; tempCart.SourceCodeId = 0; tempCart.ShippingAddressId = null; _tempcartService.SaveTempCart(tempCart); throw new Exception("OOPS! Payment could not be settled. Please try again or Call our Care Agent at " + _settings.PhoneTollFree); } throw new Exception("OOPS! Some error while generating the Order. Please try again or Call our Care Agent at " + _settings.PhoneTollFree); } return(model); }
public OnlineSchedulingCustomerInfoEditModel GetPaymentInfo(string guid) { var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid); if (onlineRequestValidationModel.RequestStatus != OnlineRequestStatus.Valid) { return new OnlineSchedulingCustomerInfoEditModel { RequestValidationModel = onlineRequestValidationModel } } ; var tempCart = onlineRequestValidationModel.TempCart; var model = new OnlineSchedulingCustomerInfoEditModel { ProcessAndCartViewModel = _eventSchedulerService.GetOnlineCart(tempCart), EventCustomerOrderSummaryModel = _eventSchedulerService.GetEventCustomerOrderSummaryModel(guid), CustomerEditModel = new SchedulingCustomerEditModel { EnableTexting = _enableTexting }, SourceCodeApplyEditModel = _eventSchedulerService.GetSourceCodeApplied(tempCart), RequestValidationModel = onlineRequestValidationModel }; var newsletterprompt = Convert.ToBoolean(_configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.EnableNewsletterPrompt)); if (newsletterprompt && model.EventCustomerOrderSummaryModel != null && model.EventCustomerOrderSummaryModel.EventType == EventType.Retail) { model.RequestForNewsLetterDescription = _toolTipRepository.GetToolTipContentByTag(ToolTipType.OnlineNewsletterDescription); model.ShowNewsLetterPrompt = true; } model.EventCustomerOrderSummaryModel = _eventSchedulerService.GetEventCustomerOrderSummaryModel(guid); model.StateList = _stateRepository.GetAllStates().ToList().Select(x => new OrderedPair <long, string>(x.Id, x.Name)); var customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null; if (customer == null && tempCart.ProspectCustomerId.HasValue && tempCart.ProspectCustomerId.Value > 0) { model.CustomerEditModel = _prospectCustomerService.GetforProspectCustomerId(tempCart.ProspectCustomerId.Value); } else if (customer != null) { model.CustomerEditModel = Mapper.Map <Customer, SchedulingCustomerEditModel>(customer); model.CustomerEditModel.ShippingAddress = Mapper.Map <Address, AddressEditModel>(customer.Address); model.CustomerEditModel.ConfirmationToEnablTexting = customer.EnableTexting; //model.CustomerEditModel.ShippingAddress.Id = tempCart.ShippingAddressId.HasValue ? tempCart.ShippingAddressId.Value : 0; } //payment if (model.PaymentEditModel == null) { model.PaymentEditModel = new PaymentEditModel { PaymentFlow = PaymentFlow.In, Amount = model.EventCustomerOrderSummaryModel.AmountDue.HasValue ? model.EventCustomerOrderSummaryModel.AmountDue.Value : 0, ShippingAddressSameAsBillingAddress = true }; } if (customer != null && ((customer.BillingAddress != null && customer.BillingAddress.StreetAddressLine1 != OnlineAddress1) || (customer.Address != null && customer.Address.StreetAddressLine1 != OnlineAddress1))) { model.PaymentEditModel.ExistingBillingAddress = Mapper.Map <Address, AddressEditModel>(customer.BillingAddress ?? customer.Address); model.PaymentEditModel.ExistingBillingAddress.Id = customer.BillingAddress != null ? customer.BillingAddress.Id : 0; model.PaymentEditModel.ExistingShippingAddress = Mapper.Map <Address, AddressEditModel>(customer.BillingAddress ?? customer.Address); model.PaymentEditModel.ExistingShippingAddress.Id = customer.Address != null ? customer.Address.Id : 0; } model.RequestForNewsLetter = model.EventCustomerOrderSummaryModel != null && model.EventCustomerOrderSummaryModel.EventType == EventType.Retail; model.PaymentEditModel.AllowedPaymentTypes = new[] { new OrderedPair <long, string>(PaymentType.CreditCard.PersistenceLayerId, PaymentType.CreditCard.Name), new OrderedPair <long, string>(PaymentType.ElectronicCheck.PersistenceLayerId, PaymentType.ElectronicCheck.Name), new OrderedPair <long, string>(PaymentType.GiftCertificate.PersistenceLayerId, PaymentType.GiftCertificate.Name) }; var payLaterOnlineRegistration = Convert.ToBoolean(_configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.PayLaterOnlineRegistration)); if (payLaterOnlineRegistration) { var payLaterOption = new[] { new OrderedPair <long, string>(PaymentType.Onsite_Value, PaymentType.PayLater_Text) }; model.PaymentEditModel.AllowedPaymentTypes = model.PaymentEditModel.AllowedPaymentTypes.Concat(payLaterOption); } var eventId = model.EventCustomerOrderSummaryModel.EventId.HasValue ? model.EventCustomerOrderSummaryModel.EventId.Value : 0; var packageId = model.SourceCodeApplyEditModel.Package != null ? model.SourceCodeApplyEditModel.Package.FirstValue : 0; var addOnTestIds = model.SourceCodeApplyEditModel.SelectedTests != null?model.SourceCodeApplyEditModel.SelectedTests.Select(st => st.FirstValue).ToArray() : null; var testCoveredByInsurance = _eligibilityService.CheckTestCoveredByinsurance(eventId, packageId, addOnTestIds); if (testCoveredByInsurance) { var insurancePaymentOption = new[] { new OrderedPair <long, string>(PaymentType.Insurance.PersistenceLayerId, PaymentType.Insurance.Name) }; model.PaymentEditModel.AllowedPaymentTypes = model.PaymentEditModel.AllowedPaymentTypes.Concat(insurancePaymentOption); } if (model.EventCustomerOrderSummaryModel.AmountDue != null && model.EventCustomerOrderSummaryModel.AmountDue > 0) { if (payLaterOnlineRegistration) { model.PaymentEditModel.Payments = new[] { new PaymentInstrumentEditModel { Amount = model.EventCustomerOrderSummaryModel.AmountDue.Value, PaymentType = Convert.ToInt32(PaymentType.Onsite_Value) } }; } else { model.PaymentEditModel.Payments = new[] { new PaymentInstrumentEditModel { Amount = model.EventCustomerOrderSummaryModel.AmountDue.Value, ChargeCard = new ChargeCardPaymentEditModel() { ChargeCard = (tempCart.ChargeCardId.HasValue && tempCart.ChargeCardId.Value > 0) ?_chargeCardRepository.GetById(tempCart.ChargeCardId.Value) :new ChargeCard() } } }; if (testCoveredByInsurance && tempCart.EligibilityId.HasValue && tempCart.EligibilityId.Value > 0 && tempCart.ChargeCardId.HasValue && tempCart.ChargeCardId.Value > 0) { var insurancePayment = new[] { new PaymentInstrumentEditModel { Insurance = new InsurancePaymentEditModel { EligibilityId = tempCart.EligibilityId.Value, ChargeCardId = tempCart.ChargeCardId.Value } } }; model.PaymentEditModel.Payments = model.PaymentEditModel.Payments.Concat(insurancePayment); } } } else { model.PaymentEditModel.ShippingAddressSameAsBillingAddress = false; } return(model); }