Example #1
0
 public ProcessAuthorizationResponse(ProcessOrderResponse processOrderResponse)
 {
     ErrorMessage             = processOrderResponse.ErrorMessage;
     ProcessResponseErrorType = processOrderResponse.ProcessResponseErrorType;
     PurchaseOrder            = processOrderResponse.PurchaseOrder;
     PaymentType = processOrderResponse.PaymentType;
 }
        public virtual ProcessOrderResponse CreatePurchaseOrder(ICart cart)
        {
            ProcessOrderResponse result;

            try
            {
                if (_logger.IsInformationEnabled())
                {
                    _logger.Information($"Creating PurchaseOrder for orderId {cart.Properties[VippsConstants.VippsOrderIdField]}");
                }

                //Add your order validation here
                var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
                var purchaseOrder  = _orderRepository.Load <IPurchaseOrder>(orderReference.OrderGroupId);

                _orderRepository.Delete(cart.OrderLink);

                result = new ProcessOrderResponse
                {
                    PurchaseOrder = purchaseOrder
                };
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);

                result = new ProcessOrderResponse
                {
                    ErrorMessage             = ex.Message,
                    ProcessResponseErrorType = ProcessResponseErrorType.EXCEPTION,
                };
            }

            return(result);
        }
        private ProcessOrderResponse ProcessPayment(IVippsUserDetails vippsUserDetails, IVippsPaymentDetails paymentDetails, string orderId, ICart cart)
        {
            ProcessOrderResponse response;

            var payment = cart.GetFirstPayment(x =>
                                               x.IsVippsPayment() &&
                                               x.TransactionID == orderId &&
                                               x.TransactionType.Equals(nameof(TransactionType.Authorization)));

            if (TransactionSuccess(paymentDetails))
            {
                response = HandleSuccess(cart, payment, paymentDetails, vippsUserDetails, orderId);
            }
            else if (TransactionCancelled(paymentDetails))
            {
                response = HandleCancelled(cart, payment, paymentDetails, orderId);
            }
            else if (TransactionFailed(paymentDetails))
            {
                response = HandleFailed(cart, payment, paymentDetails, orderId);
            }
            else
            {
                response = new ProcessOrderResponse
                {
                    ProcessResponseErrorType = ProcessResponseErrorType.OTHER,
                    ErrorMessage             = $"No action taken on order id: {orderId}."
                };
            }

            return(EnsurePaymentType(response, cart));
        }
Example #4
0
        public void ProcessOrderTest(string orderdate, OrderActionType orderactionype, bool expectedSuccess, string expectedmessage)
        {
            OrderManager manager = OrderManagerFactory.Create();
            Order        order   = new Order
            {
                OrderNumber            = 1,
                CustomerName           = "Wise Edit",
                State                  = "OH",
                TaxRate                = 6.25M,
                ProductType            = "Wood",
                Area                   = 100.00M,
                CostPerSquareFoot      = 5.15M,
                LaborCostPerSquareFoot = 4.75M,
                MaterialCost           = 515.00M,
                LaborCost              = 475.00M,
                Tax   = 61.875M,
                Total = 1051.875M
            };
            ProcessOrderResponse processorderresponse = manager.ProcessOrder(order, orderdate, orderactionype);

            Assert.AreEqual(expectedSuccess, processorderresponse.Success);
            if (processorderresponse.Success == true)
            {
                Assert.AreEqual(order, processorderresponse.order);
            }
            else
            {
                Assert.AreEqual(expectedmessage, processorderresponse.Message);
            }
        }
Example #5
0
        static void CallViaInterface()
        {
            IOrderProcessing client = null;

            try
            {
                Console.WriteLine("About to invoke OrderProcessing service");

                WSHttpBinding binding = new WSHttpBinding(
                    "WSHttpBinding_IOrderProcessing");
                EndpointAddress epAddr = new EndpointAddress(
                    "http://*****:*****@foo.com";
                request.TotalAmount          = 75.00M;
                request.Items = new List <Item>
                {
                    new Item {
                        ItemId = 1234, Quantity = 1
                    },
                    new Item {
                        ItemId = 2345, Quantity = 3
                    },
                };

                ProcessOrderResponse poResponse = client.ProcessOrder(
                    new ProcessOrderRequest(request));

                OrderProcessingResponse response =
                    poResponse.OrderProcessingResponse;

                Console.WriteLine("Response IsSuccessful: {0}",
                                  response.IsSuccessful);
                Console.WriteLine("Response OrderId: {0}",
                                  response.OrderId);
                Console.WriteLine("Response ShipDate: {0:D}",
                                  response.ShipDate);
                Console.WriteLine("Response CreditAuthCode: {0}",
                                  response.CreditAuthCode);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unhandled exception: {0}", exception.Message);
            }
            finally
            {
                ((IChannel)client).Close();
            }
        }
        private static ProcessOrderResponse EnsurePaymentType(ProcessOrderResponse response, ICart cart)
        {
            if (response == null)
            {
                return(response);
            }
            if (response.PurchaseOrder != null)
            {
                return(response);
            }

            response.PaymentType = cart.GetVippsPaymentType();

            return(response);
        }
        private void EnsureCartNotProcessing(ProcessLockInformation lockInfo, ProcessOrderResponse response)
        {
            if (response.PurchaseOrder != null)
            {
                return;
            }

            ICart cart;

            if (lockInfo.OrderGroupId.HasValue)
            {
                cart = _orderRepository.Load <ICart>(lockInfo.OrderGroupId.Value);
            }
            else
            {
                cart = _vippsService.GetCartByContactId(lockInfo.ContactId.Value, lockInfo.MarketId, lockInfo.CartName);
            }

            SetCartNotProcessing(lockInfo.OrderId, cart);
        }
Example #8
0
        public async Task <CommandResponse> Handle(ProcessOrderRequest request, CancellationToken cancellationToken)
        {
            var order  = new Order();
            var result = await _unitOfWork.Orders.Add(order);

            // Consolida as notificações
            AddNotifications(order);

            // Return data
            if (order != null)
            {
                var data = new ProcessOrderResponse(result.Number, result.CreateDate, result.LastUpdateDate, result.Total, result.Notes, result.Status, 1);
                _logger.LogInformation("Order successfully registered");
                return(CreateResponse(data, "Order successfully registered"));
            }
            else
            {
                _logger.LogInformation("Error on create order, please try again");
                return(BadRequestResponse(null, "Error on create order, please try again"));
            }
        }
        private ProcessOrderResponse TryEnsureCartNotProcessing(ProcessLockInformation lockInfo, ProcessOrderResponse response)
        {
            try
            {
                EnsureCartNotProcessing(lockInfo, response);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
            }

            return(response);
        }
        public ProcessOrderResponse ProcessOrder(Order order, string orderdate, OrderActionType orderactiontype)
        {
            if (orderactiontype == OrderActionType.Add || orderactiontype == OrderActionType.Edit)
            {
                if (order.CustomerName.Contains(","))
                {
                    order.CustomerName = order.CustomerName.Replace(",", "|");
                }
            }
            ProcessOrderResponse  processorderresponse = new ProcessOrderResponse();
            OrderDateFileResponse orderdatefile        = _orderRepository.GetPath(orderdate);

            if (string.IsNullOrEmpty(orderdatefile.path))
            {
                processorderresponse.Success = false;
                processorderresponse.Message = $"File not found for Order date {orderdate} or some problem. Please contact IT.";
            }
            else
            {
                switch (orderactiontype)
                {
                case OrderActionType.Add:
                    processorderresponse.order = _orderRepository.AddOrderToExistingOrderDateFile(order, orderdatefile.path);
                    break;

                case OrderActionType.Edit:
                    processorderresponse.order = _orderRepository.EditOrder(order, orderdatefile.path);
                    break;

                case OrderActionType.Remove:
                    processorderresponse.order = _orderRepository.RemoveOrder(order, orderdatefile.path);
                    break;

                default:
                    throw new Exception("Order Action Type is not supported!");
                }
                if (processorderresponse.order == null)
                {
                    processorderresponse.Success = false;
                    processorderresponse.Message = "New order save (to existing order date file) unsuccessful.";
                }
                else
                {
                    processorderresponse.Success = true;
                }
            }

            if (orderactiontype == OrderActionType.Add && string.IsNullOrEmpty(orderdatefile.path))
            {
                OrderDateFileResponse neworderdatefile = _orderRepository.BuildPath(orderdate);
                if (string.IsNullOrEmpty(neworderdatefile.path))
                {
                    processorderresponse.Success = false;
                    processorderresponse.Message = $"Problem creating a new order date file for Order date {orderdate}. Please contact IT.";
                }
                else
                {
                    processorderresponse.order = _orderRepository.AddOrderToNewOrderDateFile(order, neworderdatefile.path);
                    if (processorderresponse.order == null)
                    {
                        processorderresponse.Success = false;
                        processorderresponse.Message = "New order save (to new order date file) unsuccessful.";
                    }
                    else
                    {
                        processorderresponse.Success = true;
                    }
                }
            }
            return(processorderresponse);
        }