Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder;

            Country shippingCountry = TransactionLibrary.GetShippingInformation().Country;

            var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry);

            var existingPayment = basket.Payments.FirstOrDefault();

            var selectedPaymentMethodId = existingPayment != null
                ? existingPayment.PaymentMethod.PaymentMethodId
                : -1;

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                var option = new ListItem();
                option.Text     = availablePaymentMethod.Name;
                option.Value    = availablePaymentMethod.PaymentMethodId.ToString();
                option.Selected = availablePaymentMethod.PaymentMethodId == selectedPaymentMethodId;

                AvailablePaymentMethods.Items.Add(option);
            }
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            var paymentViewModel = new PaymentViewModel();

            PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder;

            Country shippingCountry = TransactionLibrary.GetShippingInformation().Country;

            var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry);

            var existingPayment = basket.Payments.FirstOrDefault();

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

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                var option = new SelectListItem();
                option.Text     = availablePaymentMethod.Name;
                option.Value    = availablePaymentMethod.PaymentMethodId.ToString();
                option.Selected = availablePaymentMethod.PaymentMethodId == paymentViewModel.SelectedPaymentMethodId;

                paymentViewModel.AvailablePaymentMethods.Add(option);
            }

            return(View("/Views/mc/Payment.cshtml", paymentViewModel));
        }
        private ReadOnlyCollection <global::Sitecore.Commerce.Entities.Payments.PaymentMethod> GetCommerceConnectPaymentMethods(Country country)
        {
            var mapper = ObjectFactory.Instance.Resolve <IMapping <PaymentMethod, global::Sitecore.Commerce.Entities.Payments.PaymentMethod> >("PaymentMethodToPaymentMethod");

            var paymentMethods = country == null?TransactionLibrary.GetPaymentMethods() : TransactionLibrary.GetPaymentMethods(country);

            IList <global::Sitecore.Commerce.Entities.Payments.PaymentMethod> cCpaymentMethods = paymentMethods.Select(paymentMethod => mapper.Map(paymentMethod)).ToList();

            return(new ReadOnlyCollection <global::Sitecore.Commerce.Entities.Payments.PaymentMethod>(cCpaymentMethods));
        }
Esempio n. 4
0
    private List <PaymentMethod> GetPaymentMethods()
    {
        List <PaymentMethod> availablePaymentMethods;
        bool showForCurrentCountry = ValidationHelper.GetBoolean(GetValue("ShowForCurrentCountry"), true);

        if (showForCurrentCountry)
        {
            availablePaymentMethods = TransactionLibrary.GetPaymentMethods().ToList();
        }
        else
        {
            var paymentMethods = ObjectFactory.Instance.Resolve <IRepository <PaymentMethod> >();
            availablePaymentMethods = paymentMethods.Select(x => !x.Deleted).ToList();
        }
        return(availablePaymentMethods);
    }
        public override ActionResult Index(ContentModel model)
        {
            var paymentViewModel = new PaymentViewModel();

            paymentViewModel.AvailablePaymentMethods = new List <SelectListItem>();

            PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder;

            Country shippingCountry = TransactionLibrary.GetShippingInformation().Country;

            var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry);

            var existingPayment = basket.Payments.FirstOrDefault();

            paymentViewModel.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);

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

                paymentViewModel.AvailablePaymentMethods.Add(option);
            }

            if (paymentViewModel.AvailablePaymentMethods.Any() && paymentViewModel.AvailablePaymentMethods.All(x => !x.Selected))
            {
                // Always make sure, that one payment method is selected.
                paymentViewModel.AvailablePaymentMethods.First().Selected = true;
            }

            paymentViewModel.ShippingCountry = shippingCountry.Name;

            return(View("/Views/Payment.cshtml", paymentViewModel));
        }
        public ActionResult Index()
        {
            var paymentModel = new PaymentViewModel();

            paymentModel.AvailablePaymentMethods = new List <SelectListItem>();

            var shippingCountry = TransactionLibrary.GetShippingInformation().Country;
            var payment         = TransactionLibrary.GetBasket(false).PurchaseOrder.Payments.FirstOrDefault();

            var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry);

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                paymentModel.AvailablePaymentMethods.Add(new SelectListItem()
                {
                    Selected = payment != null && payment.PaymentMethod.PaymentMethodId ==
                               availablePaymentMethod.PaymentMethodId,
                    Text  = availablePaymentMethod.Name,
                    Value = availablePaymentMethod.PaymentMethodId.ToString()
                });
            }

            return(View("/Views/Payment.cshtml", paymentModel));
        }