Ejemplo n.º 1
0
        public ActionResult PreviewAndPay(PreviewAndPayViewModel model)
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // Validates the shopping cart
            ShoppingCartCheckResult checkResult = cart.ValidateContent();

            // Gets the selected payment method and assigns it to the shopping cart
            cart.PaymentMethod = paymentRepository.GetById(model.PaymentMethod.PaymentMethodID);

            // Evaluates the shopping cart
            cart.Evaluate();

            // If the validation was not successful, displays the preview step again
            if (checkResult.CheckFailed || !IsPaymentMethodValid(model.PaymentMethod.PaymentMethodID))
            {
                // Prepares a model from the preview step
                PreviewAndPayViewModel viewModel = PreparePreviewViewModel();

                // Displays the preview step again
                return(View("PreviewAndPay", viewModel));
            }

            // Creates an order from the shopping cart
            Order order = shoppingService.CreateOrder(cart);

            // Deletes the shopping cart from the database
            shoppingService.DeleteShoppingCart(cart);

            // Redirects to the payment gateway
            return(RedirectToAction("Index", "Payment", new { orderID = order.OrderID }));
        }
        protected internal override void ConstraintValidation(Financial financial, out Financial financial2)
        {
            PaymentMethod paymentMethod = null;

            //Validates the payment method
            if (!financial.PaymentMethod.IsNull())
            {
                paymentMethod = _paymentMethodRepository.GetById(financial.PaymentMethod.Id);

                if (paymentMethod == null)
                {
                    _bus.RaiseEvent(new DomainNotification("Payment method invalid", "The payment method is not valid"));
                    financial2 = null;
                    return;
                }
            }

            financial.PaymentMethod = paymentMethod;
            financial2 = financial;
        }
Ejemplo n.º 3
0
        public PaymentMethod GetById(int id)
        {
            var sbKey = new StringBuilder();

            sbKey.AppendFormat(CachePaymentMethodKey, "GetBySeoUrl");
            sbKey.AppendFormat("-{0}", id);

            var key           = sbKey.ToString();
            var paymentMethod = _cacheManager.Get <PaymentMethod>(key);

            if (paymentMethod != null)
            {
                return(paymentMethod);
            }

            paymentMethod = _paymentMethodRepository.GetById(id);
            _cacheManager.Put(key, paymentMethod);

            return(paymentMethod);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets payment method with required ID.
 /// </summary>
 /// <param name="paymentMethodId">ID of payment method which should be returned.</param>
 public PaymentOptionInfo GetPaymentMethod(int paymentMethodId)
 {
     return(mPaymentMethodRepository.GetById(paymentMethodId));
 }
Ejemplo n.º 5
0
 public PaymentMethodViewModel Get(Guid id)
 {
     return(Mapper.Map <PaymentMethodViewModel>(_paymentMethodRepository.GetById(id)));
 }