Пример #1
0
        public ActionResult Edit(RefundRequestResultEditModel model, IEnumerable <PaymentInstrumentEditModel> payments)
        {
            var request = ((IRefundRequestRepository)_repository).Get(model.RequestId);

            try
            {
                model.PaymentEditModel.Payments = payments;

                model.PreviousProcessingNotes = request.RefundRequestResult != null ? request.RefundRequestResult.Notes : string.Empty;

                if (!IsModelValid(model, payments))
                {
                    CompleteEditModel(model, model.CustomerId);
                    model.RequestedRefundAmount = request.RequestedRefundAmount;
                    return(View(model));
                }
                var notesToSave = PrepareProcessorNotesHtml(model.Notes, model.PreviousProcessingNotes);

                var requestResult = Mapper.Map <RefundRequestResultEditModel, RefundRequestResult>(model);
                requestResult.Notes       = notesToSave;
                requestResult.ProcessedOn = DateTime.Now;
                requestResult.ProcessedByOrgRoleUserId =
                    _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId;
                request.RefundRequestResult = requestResult;
                request.RequestStatus       = (long)RequestStatus.Resolved;

                var currentOrgRole = _sessionContext.UserSession.CurrentOrganizationRole;

                ManagePaymentsbeforeDataSave(model);

                bool    isPaymentRefunded = false;
                decimal amountRefunded    = 0;

                if (model.RefundAmount > 0)
                {
                    isPaymentRefunded = true;
                    amountRefunded    = model.RefundAmount;
                }

                using (var scope = new TransactionScope())
                {
                    long paymentId = 0;
                    switch (model.RequestResultType)
                    {
                    case RequestResultType.AdjustOrder:     // Can't do it for Cancelled appointment Record
                        ((IRefundRequestRepository)_repository).SaveProcessorNotes(model.RequestId, notesToSave);
                        scope.Complete();
                        var guid = Guid.NewGuid();
                        if (currentOrgRole.CheckRole((long)Roles.FranchisorAdmin))
                        {
                            Response.RedirectUser("/App/Common/ChangePackage.aspx?" + RefundRequest.ProcessRequestId + "=" + model.RequestId + "&EventId=" + request.EventId + "&CustomerId=" + request.CustomerId + "&" + RefundRequest.ProcessRequest + "=true&guid=" + guid);
                        }
                        else
                        {
                            Response.RedirectUser("/App/CallCenter/CallCenterRep/CallCenterRepChangePackage.aspx?Call=No&" + RefundRequest.ProcessRequestId + "=" + model.RequestId + "&EventId=" + request.EventId + "&CustomerId=" + request.CustomerId + "&" + RefundRequest.ProcessRequest + "=true");
                        }
                        return(null);

                    case RequestResultType.RescheduleAppointment:
                        ((IRefundRequestRepository)_repository).SaveProcessorNotes(model.RequestId, notesToSave);
                        scope.Complete();

                        if (currentOrgRole.CheckRole((long)Roles.FranchisorAdmin))
                        {
                            Response.RedirectUser("/App/Franchisor/FranchisorRescheduleCustomerAppointment.aspx?resolve=true&" + RefundRequest.ProcessRequestId + "=" + model.RequestId + "&EventId=" + request.EventId + "&CustomerId=" + request.CustomerId + "&" + RefundRequest.ProcessRequest + "=true");
                        }
                        else
                        {
                            Response.RedirectUser("/App/CallCenter/CallCenterRep/CallCenterRepRescheduleCustomerAppointment.aspx?resolve=true&Call=No&" + RefundRequest.ProcessRequestId + "=" + model.RequestId + "&EventID=" + request.EventId + "&CustomerID=" + request.CustomerId + "&" + RefundRequest.ProcessRequest + "=true");
                        }
                        return(null);

                    case RequestResultType.IssueRefund:

                        if (model.RefundType == RefundRequestType.CustomerCancellation)
                        {
                            var eventCustomerRepository = IoC.Resolve <IEventCustomerRepository>();
                            var eventCustomer           = eventCustomerRepository.GetCancelledEventForUser(request.CustomerId, request.EventId);
                            var customerService         = IoC.Resolve <ICustomerService>();
                            customerService.UnMarkProspectCustomerConverted(eventCustomer.Id, ProspectCustomerTag.Cancellation);
                            _eventCustomerService.CancelAppointment(request.EventId, request.CustomerId, model.PaymentEditModel, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, model.ChargeCancellationFee);
                        }
                        else
                        {
                            paymentId = _paymentController.SavePayment(model.PaymentEditModel, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                            _orderRepository.ApplyPaymentToOrder(model.OrderId, paymentId);
                        }
                        break;

                    case RequestResultType.OfferFreeAddonsAndDiscounts:
                        _orderController.ManageOrderforRefundRequestwithFreeDiscountandProduct(model, model.OrderId, request.CustomerId, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                        paymentId = _paymentController.SavePayment(model.PaymentEditModel, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
                        _orderRepository.ApplyPaymentToOrder(model.OrderId, paymentId);
                        break;

                    case RequestResultType.IssueGiftCertificate:
                        Session[RefundRequest.ProcessRequestId] = request.Id;
                        ((IRefundRequestRepository)_repository).SaveProcessorNotes(model.RequestId, notesToSave);
                        scope.Complete();
                        Response.RedirectUser("/App/CallCenter/CallCenterRep/GiftCertificate/Details.aspx?Call=No&Amount=" + model.RequestedRefundAmount);
                        return(null);
                    }

                    _repository.Save(request);

                    scope.Complete();
                }

                try
                {
                    if (isPaymentRefunded)
                    {
                        SendRefundNotification(model.CustomerId, amountRefunded);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Refund Request: Failed to send notification. Message:" + ex.Message + "\n\tStackTrace:" + ex.StackTrace);
                }
                Response.RedirectUser("/Finance/RefundRequest");
                return(null);
            }
            catch (Exception ex)
            {
                _logger.Error("Refund Request: Message:" + ex.Message + "\n\tStackTrace:" + ex.StackTrace);
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("System Failure while Processing Request. Message : " + ex.Message);
                _paymentController.VoidCreditCardGatewayRequests(model.PaymentEditModel);
                CompleteEditModel(model, model.CustomerId);
                model.RequestedRefundAmount = request.RequestedRefundAmount;
            }
            return(View(model));
        }
Пример #2
0
        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);
        }