/// <summary>
        /// Fictitious method for creating a payment response information and paying the order.
        /// </summary>
        /// <param name="orderID">ID of the paid order.</param>
        public ActionResult Index(int orderID)
        {
            // Gets the order
            OrderInfo order = orderInfo.Get(orderID);

            // Validates the retrieved order
            if (order?.OrderSiteID != siteService.CurrentSite.SiteID)
            {
                // Redirects back to the order review step if validation fails
                return(RedirectToAction("PreviewAndPay", "Checkout"));
            }

            // Creates a fictitious response
            ResponseViewModel response = new ResponseViewModel()
            {
                InvoiceNo     = order.OrderID,
                Message       = "Successfully paid",
                Completed     = true,
                TransactionID = new Random().Next(100000, 200000).ToString(),
                Amount        = order.OrderTotalPrice,
                ResponseCode  = "",
                Approved      = true
            };

            // Validates the response and pays the order
            Validate(response);

            // Redirects to the thank-you page
            return(RedirectToAction("ThankYou", "Checkout", new { OrderID = orderID }));
        }
Пример #2
0
        /// <summary>
        /// Returns the order based on the entered order ID.
        /// </summary>
        /// <param name="textOrderID">String containing the user-entered order ID</param>
        /// <returns>Order object of the order</returns>
        private OrderInfo GetOrder(string textOrderID)
        {
            Int32.TryParse(textOrderID, out int orderID);

            // If the text value is not a number, returns null
            if (orderID <= 0)
            {
                return(null);
            }

            // Gets the order based on the order ID
            OrderInfo order = orderInfoProvider.Get(orderID);

            // Gets the current customer
            CustomerInfo customer = shoppingService.GetCurrentCustomer();

            var currentSiteID = siteService.CurrentSite.SiteID;

            // Validates that the order was created on the current site and that it belongs to the current customer
            if ((order?.OrderSiteID != currentSiteID) || (order?.OrderCustomerID != customer?.CustomerID))
            {
                order = null;
            }

            return(order);
        }
Пример #3
0
        /// <summary>
        /// Returns an order with the specified identifier.
        /// </summary>
        /// <param name="orderId">Order's identifier.</param>
        /// <returns><see cref="OrderInfo"/> object representing an order with the specified identifier. Returns <c>null</c> if not found.</returns>
        public OrderInfo GetById(int orderId)
        {
            return(repositoryCacheHelper.CacheObject(() =>
            {
                var orderInfo = orderInfoProvider.Get(orderId);

                if (orderInfo == null || orderInfo.OrderSiteID != SiteContext.CurrentSiteID)
                {
                    return null;
                }

                return orderInfo;
            }, $"{nameof(OrderRepository)}|{nameof(GetById)}|{orderId}"));
        }