public ActionResult Rendering()
        {
            var paymentPickerViewModel = new PaymentPickerViewModel();

            var basket          = _transactionLibrary.GetBasket();
            var shippingCountry = basket.GetShippingAddress(Constants.DefaultShipmentAddressName).Country;

            paymentPickerViewModel.ShippingCountry = shippingCountry.Name;

            var availablePaymentMethods = _transactionLibrary.GetPaymentMethods(shippingCountry);

            var existingPayment = basket.Payments.FirstOrDefault();

            paymentPickerViewModel.SelectedPaymentMethodId = existingPayment != null
                                ? existingPayment.PaymentMethod.PaymentMethodId
                                : -1;

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                var     option       = new SelectListItem();
                decimal feePercent   = availablePaymentMethod.FeePercent;
                var     fee          = availablePaymentMethod.GetFeeForCurrency(basket.BillingCurrency);
                var     formattedFee = new Money((fee == null ? 0 : fee.Fee), basket.BillingCurrency.ISOCode);

                option.Text = String.Format(" {0} ({1} + {2}%)", availablePaymentMethod.Name, formattedFee,
                                            feePercent.ToString("0.00"));
                option.Value    = availablePaymentMethod.PaymentMethodId.ToString();
                option.Selected = availablePaymentMethod.PaymentMethodId == paymentPickerViewModel.SelectedPaymentMethodId;

                paymentPickerViewModel.AvailablePaymentMethods.Add(option);
            }

            return(View(paymentPickerViewModel));
        }
Example #2
0
        public void Rendering_Returns_View_With_Valid_Model()
        {
            // Arrange
            var purchaseOrder = Substitute.For <PurchaseOrder>();

            purchaseOrder.GetShippingAddress(Constants.DefaultShipmentAddressName).Returns(new OrderAddress()
            {
                Country = new Country()
                {
                    Name = "Denmark"
                }
            });

            var paymentMethods = new List <PaymentMethod>();

            paymentMethods.Add(new PaymentMethod()
            {
                Name = "PayPal"
            });

            _transactionLibraryInternal.GetPaymentMethods(
                purchaseOrder.GetShippingAddress(Constants.DefaultShipmentAddressName).Country)
            .ReturnsForAnyArgs(paymentMethods);


            var basket = Substitute.For <PurchaseOrder>();

            basket.BillingCurrency.ISOCode = "EUR";
            _transactionLibraryInternal.GetBasket().Returns(basket);

            // Act
            var result = _controller.Rendering();

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as PaymentPickerViewModel : null;

            Assert.NotNull(model);
            Assert.NotNull(viewResult);
            Assert.NotNull(model.SelectedPaymentMethodId);
            Assert.True(model.AvailablePaymentMethods.Count == 1);
        }