/// <summary>
    /// Ensures that only applicable payment options are displayed in selector.
    /// </summary>
    /// <param name="ds">Dataset with payment options.</param>
    protected override DataSet OnAfterRetrieveData(DataSet ds)
    {
        if (DataHelper.IsEmpty(ds) || (ShoppingCart == null))
        {
            return(ds);
        }

        foreach (DataRow paymentRow in ds.Tables[0].Select())
        {
            PaymentOptionInfo paymentOptionInfo;

            if (UseNameForSelection)
            {
                var paymentName = DataHelper.GetStringValue(paymentRow, "PaymentOptionName");
                paymentOptionInfo = PaymentOptionInfoProvider.GetPaymentOptionInfo(paymentName, ShoppingCart.SiteName);
            }
            else
            {
                var paymentID = DataHelper.GetIntValue(paymentRow, "PaymentOptionID");
                paymentOptionInfo = PaymentOptionInfoProvider.GetPaymentOptionInfo(paymentID);
            }

            // Do not remove already selected item even if the option is not applicable anymore
            // The user would see a different value in UI as is actually stored in the database
            var canBeRemoved = !EnsureSelectedItem || (ShoppingCart.ShoppingCartPaymentOptionID != paymentOptionInfo.PaymentOptionID);
            if (canBeRemoved && !PaymentOptionInfoProvider.IsPaymentOptionApplicable(ShoppingCart, paymentOptionInfo))
            {
                // Remove not applicable payment methods from the selector
                ds.Tables[0].Rows.Remove(paymentRow);
            }
        }

        return(ds);
    }
        //EndDocSection:LoadingAddress


        //DocSection:PreparePayment
        /// <summary>
        /// Gets all applicable payment methods assigned to the current site.
        /// </summary>
        /// <param name="cart">Shopping cart of the site</param>
        /// <returns>Collection of applicable payment methods</returns>
        private IEnumerable <PaymentOptionInfo> GetApplicablePaymentMethods(ShoppingCartInfo cart)
        {
            // Gets all enabled payment methods from Kentico
            IEnumerable <PaymentOptionInfo> enabledPaymentMethods = PaymentOptionInfoProvider.GetPaymentOptions(SiteContext.CurrentSiteID, true).ToList();

            // Returns all applicable payment methods
            return(enabledPaymentMethods.Where(paymentMethod => PaymentOptionInfoProvider.IsPaymentOptionApplicable(cart, paymentMethod)));
        }
Ejemplo n.º 3
0
        //EndDocSection:LoadingAddress


        //DocSection:PreparePayment
        /// <summary>
        /// Gets all applicable payment methods assigned to the current site.
        /// </summary>
        /// <param name="cart">Shopping cart of the site</param>
        /// <returns>Collection of applicable payment methods</returns>
        private IEnumerable <PaymentOptionInfo> GetApplicablePaymentMethods(ShoppingCartInfo cart)
        {
            // Gets all enabled payment methods from Xperience
            IEnumerable <PaymentOptionInfo> enabledPaymentMethods = paymentOption.GetBySite(siteService.CurrentSite.SiteID, true).ToList();

            // Returns all applicable payment methods
            return(enabledPaymentMethods.Where(paymentMethod => PaymentOptionInfoProvider.IsPaymentOptionApplicable(cart, paymentMethod)));
        }
    /// <summary>
    /// Control initialization.
    /// </summary>
    public void SetupControl()
    {
        if (!StopProcessing)
        {
            // Set up empty record text. The macro ResourcePrefix + .empty represents empty record value.
            drpPayment.UniSelector.ResourcePrefix = "com.livesiteselector";

            var paymentOptions = PaymentOptionInfoProvider.GetPaymentOptions(ShoppingCart.ShoppingCartSiteID, true)
                                 .Column("PaymentOptionID")
                                 .OrderBy("PaymentOptionDisplayName");

            if (ShoppingCart.ShippingOption == null)
            {
                paymentOptions.WhereTrue("PaymentOptionAllowIfNoShipping");
            }

            IList <int> paymentIds = new List <int>();

            if (!DataHelper.DataSourceIsEmpty(paymentOptions))
            {
                paymentIds = DataHelper.GetIntegerValues(paymentOptions.Tables[0], "PaymentOptionID");
            }

            // If there is only one payment method set it.
            if (paymentIds.Count == 1)
            {
                ShoppingCart.ShoppingCartPaymentOptionID = paymentIds.FirstOrDefault();
                drpPayment.SelectedID = ShoppingCart.ShoppingCartPaymentOptionID;
            }

            // Set shopping cart to determine available payment options
            drpPayment.ShoppingCart = ShoppingCart;
            drpPayment.DisplayOnlyAllowedIfNoShipping = (ShoppingCart.ShoppingCartShippingOptionID <= 0);

            if ((ShoppingCart.ShoppingCartPaymentOptionID != 0) && !PaymentOptionInfoProvider.IsPaymentOptionApplicable(ShoppingCart, ShoppingCart.PaymentOption))
            {
                // Reset selector on shipping changed event if selected payment is not allowed for current shipping (zero shipping id is Please select state).
                ResetSelector();
            }

            // Update selection
            if (!RequestHelper.IsPostBack())
            {
                PreselectPaymentOption();
            }

            drpPayment.Reload();
        }
    }
Ejemplo n.º 5
0
 private IEnumerable <PaymentOptionInfo> GetApplicablePaymentMethods(ShoppingCartInfo cart)
 {
     return(mPaymentMethodRepository.GetAll().Where(paymentMethod => PaymentOptionInfoProvider.IsPaymentOptionApplicable(cart, paymentMethod)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Checks if the payment method is applicable for this shopping cart.
 /// </summary>
 /// <param name="paymentMethod">Payment method which is checked.</param>
 /// <returns>By default, returns always <c>true</c>. You can override the <see cref="PaymentOptionInfoProvider.IsPaymentOptionApplicable"/> method to change this behavior.</returns>
 public bool IsPaymentMethodApplicable(PaymentOptionInfo paymentMethod)
 => PaymentOptionInfoProvider.IsPaymentOptionApplicable(OriginalCart, paymentMethod);
    private void LoadControlData(bool forceReload = false)
    {
        var paymentOptions = PaymentOptionInfoProvider.GetPaymentOptions(ShoppingCart.ShoppingCartSiteID, true)
                             .Column("PaymentOptionID")
                             .OrderBy("PaymentOptionDisplayName");

        if (ShoppingCart.ShippingOption == null || !ShoppingCart.IsShippingNeeded)
        {
            paymentOptions.WhereTrue("PaymentOptionAllowIfNoShipping");
        }

        var paymentIds = paymentOptions.GetListResult <int>();

        // If there is only one payment method set it
        if (paymentIds.Count == 1)
        {
            var paymentOptionID = paymentIds.First();
            ShoppingService.SetPaymentOption(paymentOptionID);
            drpPayment.SelectedID = paymentOptionID;

            // Make sure that in-memory changes persist (unsaved address, etc.)
            Service.Resolve <ICurrentShoppingCartService>().SetCurrentShoppingCart(ShoppingCart);
        }

        drpPayment.DisplayOnlyAllowedIfNoShipping = (ShoppingCart.ShoppingCartShippingOptionID <= 0) || !ShoppingCart.IsShippingNeeded;

        if (!RequestHelper.IsPostBack() || forceReload || ((ShoppingCart.ShoppingCartPaymentOptionID != 0) && !PaymentOptionInfoProvider.IsPaymentOptionApplicable(ShoppingCart, ShoppingCart.PaymentOption)))
        {
            // Reset selector on shipping changed event if selected payment is not allowed for current shipping (zero shipping id is Please select state).
            drpPayment.Reload();
            drpPayment.SelectedID = ShoppingService.GetPaymentOption();
        }
    }