Beispiel #1
0
        // TODO: These private methods have to be removed from the service, probably pull out a seperate type for these actions.
        private void ApplyPaymentToRefund(IOrderRepository orderRepository, DomainObjectBase creatorOrganizationRoleUser,
                                          DomainObjectBase order, PaymentInstrument paymentInstrument)
        {
            long paymentId = _paymentController.SavePayment(paymentInstrument, "Payment", creatorOrganizationRoleUser.Id);

            orderRepository.ApplyPaymentToOrder(order.Id, paymentId);
        }
        public void SavePaymentSavesPaymentWithOnePaymentInstrument()
        {
            IPaymentController paymentController = IoC.Resolve <PaymentController>();

            var check = new Check
            {
                AccountNumber        = "asdfsadf",
                Amount               = 12.00m,
                BankName             = "Bank Yes",
                CheckDate            = DateTime.Now,
                CheckNumber          = "123",
                Memo                 = "Payment in full",
                PayableTo            = "ABC Company",
                DataRecorderMetaData =
                    new DataRecorderMetaData {
                    DataRecorderCreator = new OrganizationRoleUser(1), DateCreated = DateTime.Now
                }
            };

            var checkPayment = new CheckPayment()
            {
                Amount = check.Amount,
                Check  = check
            };

            var paymentInstruments = new List <PaymentInstrument> {
                checkPayment
            };

            long paymentId = paymentController.SavePayment(paymentInstruments, "should save", 1);

            Assert.Greater(paymentId, 0, "PaymentId must be >= 0");
        }
        public void SavePaymentThrowsExceptionWhenEmptyListProvided()
        {
            IPaymentController paymentController = IoC.Resolve <PaymentController>();
            var paymentInstruments = new List <PaymentInstrument>();

            paymentController.SavePayment(paymentInstruments, "shouldn't save", 1);
        }
        public void SavePaymentThrowsExceptionWhenNullListProvided()
        {
            IPaymentController             paymentController  = IoC.Resolve <PaymentController>();
            const List <PaymentInstrument> paymentInstruments = null;

            paymentController.SavePayment(paymentInstruments, "shouldn't save", 1);
        }
        public bool ProcessPayment(PaymentEditModel model)
        {
            var customer         = _customerRepository.GetCustomer(model.CustomerId);
            var eventCustomer    = _eventCustomerRepository.Get(model.EventId, model.CustomerId);
            var instruments      = new List <PaymentInstrumentEditModel>();
            var paymentEditModel = new PaymentModel();

            if (model.GcPayment != null && !string.IsNullOrEmpty(model.GcPayment.ClaimCode))
            {
                var giftCertificate = _giftCertificateService.GetGiftCertificatebyClaimCode(model.GcPayment.ClaimCode);

                instruments.Add(new PaymentInstrumentEditModel {
                    Amount = model.GcPayment.Amount, PaymentType = PaymentType.GiftCertificate.PersistenceLayerId, GiftCertificate = new GiftCertificatePaymentEditModel {
                        GiftCertificate = giftCertificate, GiftCertificatePayment = new GiftCertificatePayment {
                            GiftCertificateId = giftCertificate.Id, Amount = model.GcPayment.Amount
                        }
                    }
                });
            }
            if (model.Payments != null)
            {
                model.Payments.BillingAddress = model.BillingAddress;
                CreatePaymentModels(model);
                instruments.Add(model.Payments);
            }

            paymentEditModel.Amount                  = model.UnPaidAmount;
            paymentEditModel.IsModeMultiple          = false;
            paymentEditModel.PaymentFlow             = PaymentFlow.In;
            paymentEditModel.Payments                = instruments;
            paymentEditModel.ExistingBillingAddress  = model.BillingAddress;
            paymentEditModel.ExistingShippingAddress = model.BillingAddress;

            _eventSchedulerService.ProcessPayment(paymentEditModel, eventCustomer.Id, model.CustomerId, true);

            try
            {
                _order = _orderRepository.GetOrder(model.CustomerId, model.EventId);

                if (paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.ChargeCard != null || p.ECheck != null || p.GiftCertificate != null || p.Check != null || p.PaymentType == PaymentType.Cash.PersistenceLayerId))
                {
                    var paymentId = _paymentController.SavePayment(paymentEditModel, model.CustomerId);
                    _orderRepository.ApplyPaymentToOrder(_order.Id, paymentId);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("Some error occured while saving payment detail", exception);
            }



            return(true);
        }
Beispiel #6
0
        public void CancelAppointment(long eventId, long customerId, PaymentEditModel paymentEditModel, long dataRecorderOrgRoleUserId, bool chargeCancellation = true)
        {
            using (var scope = new TransactionScope())
            {
                //var eventCustomer = UpdateEventCustomerforCancelAppointment(eventId, customerId);
                //if (eventCustomer == null) return;

                var orderController = new OrderController();
                var order           = orderController.CancelOrder(eventId, customerId, dataRecorderOrgRoleUserId,
                                                                  chargeCancellation);
                if (order == null)
                {
                    return;
                }

                long paymentId = _paymentController.SavePayment(paymentEditModel, dataRecorderOrgRoleUserId);
                if (paymentId > 0)
                {
                    var orderRepository = new OrderRepository();
                    orderRepository.ApplyPaymentToOrder(order.Id, paymentId);
                }
                scope.Complete();
            }
        }
        public void CreateOrder(TempCart tempCart, PaymentEditModel paymentEditModel = null)
        {
            if (tempCart.EventId == null || tempCart.CustomerId == null || tempCart.AppointmentId == null || (tempCart.EventPackageId == null && string.IsNullOrEmpty(tempCart.TestId)))
            {
                return;
            }

            var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value);
            var inDb     = _eventCustomerRepository.Get(tempCart.EventId.Value, tempCart.CustomerId.Value);

            var eventCustomer = new EventCustomer
            {
                Id                   = inDb != null ? inDb.Id : 0,
                EventId              = tempCart.EventId.Value,
                CustomerId           = tempCart.CustomerId.Value,
                DataRecorderMetaData = new DataRecorderMetaData
                {
                    DataRecorderCreator = new OrganizationRoleUser(tempCart.CustomerId.Value),
                    DateCreated         = DateTime.Now
                },
                OnlinePayment   = true,
                MarketingSource = tempCart.MarketingSource,
                NoShow          = false,
                TestConducted   = false,
                HIPAAStatus     = RegulatoryState.Unknown,
                EnableTexting   = customer.EnableTexting
            };

            using (var scope = new TransactionScope())
            {
                var appointment = _eventAppointmentService.CreateAppointment(tempCart.InChainAppointmentSlotIds, tempCart.CustomerId.Value);
                eventCustomer.AppointmentId = appointment.Id;
                eventCustomer = _eventCustomerRepository.Save(eventCustomer);

                //Moved code into ProcessPayment to Extract Common Code for API and Service
                ProcessPayment(paymentEditModel, eventCustomer.Id, customer.CustomerId, false);

                var orderables = new List <IOrderable>();

                if (tempCart.EventPackageId.HasValue)
                {
                    orderables.Add(_eventPackageRepository.GetById(tempCart.EventPackageId.Value));
                }


                var testIds = new List <long>();
                if (!string.IsNullOrEmpty(tempCart.TestId))
                {
                    string[] testIdStrings = tempCart.TestId.Split(new[] { ',' });
                    foreach (var testIdString in testIdStrings)
                    {
                        int i = 0;
                        if (int.TryParse(testIdString, out i))
                        {
                            testIds.Add(i);
                        }
                    }
                }

                if (testIds.Count > 0)
                {
                    var eventTests = _eventTestRepository.GetbyIds(testIds);
                    if (tempCart.EventPackageId.HasValue)
                    {
                        foreach (var eventTest in eventTests)
                        {
                            eventTest.Price = eventTest.WithPackagePrice;
                        }
                    }
                    orderables.AddRange(eventTests);
                }

                IEnumerable <ElectronicProduct> products = null;
                var productIds = new List <long>();
                if (!string.IsNullOrEmpty(tempCart.ProductId))
                {
                    string[] productIdStrings = tempCart.ProductId.Split(new[] { ',' });
                    foreach (var productIdIdString in productIdStrings)
                    {
                        int i = 0;
                        if (int.TryParse(productIdIdString, out i))
                        {
                            productIds.Add(i);
                        }
                    }
                }

                if (productIds.Count > 0)
                {
                    products = _productRepository.GetByIds(productIds);
                    orderables.AddRange(products);
                }

                if (orderables.IsNullOrEmpty())
                {
                    return;
                }

                SourceCode sourceCode = null;
                if (tempCart.SourceCodeId.HasValue && tempCart.SourceCodeId.Value > 0)
                {
                    var sourceCodeModel = GetSourceCodeApplied(tempCart);
                    sourceCode = new SourceCode
                    {
                        Id          = sourceCodeModel.SourceCodeId,
                        CouponCode  = sourceCodeModel.SourceCode,
                        CouponValue = sourceCodeModel.DiscountApplied
                    };
                }

                var shippingAddress = tempCart.ShippingAddressId.HasValue
                                          ? _addressRepository.GetAddress(tempCart.ShippingAddressId.Value)
                                          : null;

                ShippingDetail shippingDetail = null;
                if (tempCart.ShippingId != null && tempCart.ShippingId.Value > 0)
                {
                    var shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value);
                    shippingDetail = new ShippingDetail
                    {
                        ShippingOption       = shippingOption,
                        ShippingAddress      = shippingAddress,
                        Status               = ShipmentStatus.Processing,
                        ActualPrice          = shippingOption.Price,
                        DataRecorderMetaData = new DataRecorderMetaData(tempCart.CustomerId.Value, DateTime.Now, null)
                    };
                    shippingDetail = _shippingController.OrderShipping(shippingDetail);
                }

                bool indentedLineItemsAdded = false;
                // TODO: applying hook to the system all the indented line items will be attached to the first order item.
                foreach (var orderable in orderables)
                {
                    if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem))
                    {
                        _orderController.AddItem(orderable, 1, tempCart.CustomerId.Value, tempCart.CustomerId.Value, sourceCode, eventCustomer, shippingDetail, OrderStatusState.FinalSuccess);
                        indentedLineItemsAdded = true;
                    }
                    else
                    {
                        _orderController.AddItem(orderable, 1, tempCart.CustomerId.Value, tempCart.CustomerId.Value, OrderStatusState.FinalSuccess);
                    }
                }
                var order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value);
                order = order == null?_orderController.PlaceOrder(OrderType.Retail, tempCart.CustomerId.Value) : _orderController.ActivateOrder(order);

                if (products != null && products.Count() > 0 && shippingDetail != null)
                {
                    foreach (var electronicProduct in products)
                    {
                        SaveProductShippingDetail(electronicProduct.Id, order, shippingAddress, customer.CustomerId);
                    }
                }

                if (paymentEditModel != null && paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.ChargeCard != null || p.ECheck != null || p.GiftCertificate != null))
                {
                    var paymentId = _paymentController.SavePayment(paymentEditModel, tempCart.CustomerId.Value);
                    _orderRepository.ApplyPaymentToOrder(order.Id, paymentId);
                }

                scope.Complete();
            }
        }
Beispiel #8
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));
        }
Beispiel #9
0
        public ActionResult RemoveProduct(ProductOrderItemEditModel model, PaymentEditModel paymentModel)
        {
            try
            {
                model.Order    = _orderRepository.GetOrder(model.CustomerId, model.EventId);
                model.Payments = paymentModel;
                var result = IsModelValid(model);
                if (!result)
                {
                    CompleteModel(model);
                    return(View(model));
                }

                if (_settings.IsRefundQueueEnabled)
                {
                    using (var scope = new TransactionScope())
                    {
                        SaveOrderforProductRemove(model);
                        CheckEventCustomerResultStateAndDeleteCdGenTrackRecord(model.EventId, model.CustomerId);
                        if (model.RefundRequest != null && model.RefundRequest.RequestedRefundAmount > 0)
                        {
                            _refundRequestService.SaveRequest(model.RefundRequest);
                        }

                        scope.Complete();
                    }
                }
                else
                {
                    if (paymentModel != null && paymentModel.Payments != null && paymentModel.Payments.Count() > 0)
                    {
                        try
                        {
                            _paymentController.ManagePayment(paymentModel, model.CustomerId, Request.UserHostAddress, "Product_Removal_" + model.CustomerId + "_" + model.ProductOrderDetailIds.FirstOrDefault());
                        }
                        catch (Exception)
                        {
                            model.FeedbackMessage =
                                FeedbackMessageModel.CreateFailureMessage(
                                    "System Failure! Payments were not processed for Customer: " + model.CustomerName + " [Id = " + model.CustomerId + "]. Please contact system administrator at " + _settings.SupportEmail);
                            return(View(model));
                        }
                    }
                    using (var scope = new TransactionScope())
                    {
                        SaveOrderforProductRemove(model);
                        if (paymentModel != null && paymentModel.Payments != null && paymentModel.Payments.Count() > 0)
                        {
                            var paymentId = _paymentController.SavePayment(paymentModel, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);

                            _orderRepository.ApplyPaymentToOrder(model.Order.Id, paymentId);
                        }
                        CheckEventCustomerResultStateAndDeleteCdGenTrackRecord(model.EventId, model.CustomerId);
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                model.Order = _orderRepository.GetOrder(model.CustomerId, model.EventId);
                CompleteModel(model);
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("System Failure! " + ex.Message);
                return(View(model));
            }

            model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Product removed from order successfully!");
            return(View(model));
        }