protected void InitPaymentShipping()
    {
        if (currentSite != null)
        {
            // Get shipping option name
            ShippingOptionInfo shippingObj = ShoppingCart.ShippingOption;
            if (shippingObj != null)
            {
                mAddressCount++;
                tdShippingAddress.Visible   = true;
                plcShipping.Visible         = true;
                plcShippingOption.Visible   = true;
                lblShippingOptionValue.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(shippingObj.ShippingOptionDisplayName));
                lblShippingValue.Text       = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalShipping, ShoppingCart.Currency);
            }
            else
            {
                tdShippingAddress.Visible = false;
                plcShippingOption.Visible = false;
                plcShipping.Visible       = false;
            }
        }

        // Get payment method name
        PaymentOptionInfo paymentObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(ShoppingCart.ShoppingCartPaymentOptionID);

        if (paymentObj != null)
        {
            lblPaymentMethodValue.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(paymentObj.PaymentOptionDisplayName));
        }

        // Total price initialization
        lblTotalPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.GrandTotal, ShoppingCart.Currency);
        lblTotalTaxValue.Text   = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalTax, ShoppingCart.Currency);
    }
    /// <summary>
    /// Checks payment methods.
    /// </summary>
    private void CheckPaymentMethods()
    {
        if (PaymentMethodsCheck)
        {
            // Get all payment options
            DataSet ds = PaymentOptionInfoProvider.GetPaymentOptions("PaymentOptionEnabled = 1", "PaymentOptionID", 0, "PaymentOptionID", CMSContext.CurrentSiteID);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Build where condition
                StringBuilder sb = new StringBuilder();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    sb.Append(row["PaymentOptionID"] + ",");
                }
                sb.Remove(sb.Length - 1, 1);

                // Check if at least one is assigned to shipping method
                DataSet ds2 = PaymentShippingInfoProvider.GetPaymentShippings("PaymentOptionID IN (" + sb.ToString() + ")", null, 1, "PaymentOptionID");
                if (DataHelper.DataSourceIsEmpty(ds2))
                {
                    DisplayMessage("com.settingschecker.nopaymentoptionsshippingmethod");
                }
            }
            // If there is no Payment option, it shows error
            else
            {
                DisplayMessage("com.settingschecker.nopaymentoptions");
            }
        }
    }
    /// <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);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            var editElementName = IsMultiStoreConfiguration ? "edit.configuration.GlobalPaymentoption" : "edit.configuration.paymentoption";
            URLHelper.Redirect(UIContextHelper.GetElementUrl("cms.ecommerce", editElementName, false, ValidationHelper.GetInteger(actionArgument, 0)));
        }
        else if (actionName == "delete")
        {
            var paymentInfoObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(ValidationHelper.GetInteger(actionArgument, 0));

            // Nothing to delete
            if (paymentInfoObj == null)
            {
                return;
            }

            // Check permissions
            CheckConfigurationModification(paymentInfoObj.PaymentOptionSiteID);

            if (paymentInfoObj.Generalized.CheckDependencies())
            {
                // Show error message
                ShowError(ECommerceHelper.GetDependencyMessage(paymentInfoObj));

                return;
            }

            // Delete PaymentOptionInfo object from database
            PaymentOptionInfoProvider.DeletePaymentOptionInfo(paymentInfoObj);
        }
    }
    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();
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect("PaymentOption_Edit.aspx?paymentOptionId=" + Convert.ToString(actionArgument) + "&siteId=" + SelectSite.SiteID);
        }
        else if (actionName == "delete")
        {
            PaymentOptionInfo paymentInfoObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Nothing to delete
            if (paymentInfoObj == null)
            {
                return;
            }

            // Check permissions
            CheckConfigurationModification(paymentInfoObj.PaymentOptionSiteID);

            if (PaymentOptionInfoProvider.CheckDependencies(paymentInfoObj.PaymentOptionID))
            {
                // Show error message
                ShowError(GetString("Ecommerce.DeleteDisabled"));

                return;
            }

            // Delete PaymentOptionInfo object from database
            PaymentOptionInfoProvider.DeletePaymentOptionInfo(paymentInfoObj);
        }
    }
    private void HandleAutomaticSelections(ShoppingCartInfo currentShoppingCart)
    {
        if ((currentShoppingCart.ShippingOption == null) && currentShoppingCart.IsShippingNeeded)
        {
            // Try to select shipping option if there is only one in system
            var query = ShippingOptionInfoProvider.GetShippingOptions(currentShoppingCart.ShoppingCartSiteID, true).Column("ShippingOptionID");
            if (query.Count == 1)
            {
                currentShoppingCart.ShoppingCartShippingOptionID = DataHelper.GetIntegerValues(query.Tables[0], "ShippingOptionID").FirstOrDefault();
            }
        }

        if (currentShoppingCart.PaymentOption == null)
        {
            // Try to select payment option if there is only one in system
            var query = PaymentOptionInfoProvider.GetPaymentOptions(currentShoppingCart.ShoppingCartSiteID, true).Column("PaymentOptionID");
            if (query.Count == 1)
            {
                int paymentOptionId = DataHelper.GetIntegerValues(query.Tables[0], "PaymentOptionID").FirstOrDefault();
                // Check if payment is allowed for shipping, or shipping is not set
                if (CheckPaymentIsAllowedForShipping(currentShoppingCart, paymentOptionId))
                {
                    currentShoppingCart.ShoppingCartPaymentOptionID = paymentOptionId;
                }
            }
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Checks payment methods.
    /// </summary>
    private void CheckPaymentMethods()
    {
        if (PaymentMethodsCheck)
        {
            // Get all payment options
            DataSet ds = PaymentOptionInfoProvider.GetPaymentOptions(SiteContext.CurrentSiteID, true).Column("PaymentOptionID").OrderBy("PaymentOptionID");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Build where condition
                var paymentIds = DataHelper.GetIntegerValues(ds.Tables[0], "PaymentOptionID");

                // Check if at least one is assigned to shipping method
                DataSet ds2 = PaymentShippingInfoProvider.GetPaymentShippings().TopN(1).Column("PaymentOptionID").WhereIn("PaymentOptionID", paymentIds);
                if (DataHelper.DataSourceIsEmpty(ds2))
                {
                    DisplayMessage("com.settingschecker.nopaymentoptionsshippingmethod");
                }
            }
            // Show error if there is no payment option
            else
            {
                DisplayMessage("com.settingschecker.nopaymentoptions");
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        bool offerGlobalPaymentMethods = false;

        mShippingOptionId = QueryHelper.GetInteger("objectid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                int editedSiteId = mShippingOptionInfoObj.ShippingOptionSiteID;
                // Check object's site id
                CheckEditedObjectSiteID(editedSiteId);

                // Offer global payment methods when allowed
                offerGlobalPaymentMethods = ECommerceSettings.AllowGlobalPaymentMethods(editedSiteId);

                DataSet ds = PaymentOptionInfoProvider.GetPaymentOptionsForShipping(mShippingOptionId).OrderBy("PaymentOptionDisplayName");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "PaymentOptionID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.WhereCondition      = GetSelectorWhereCondition(offerGlobalPaymentMethods);
    }
Exemplo n.º 10
0
        public PaymentMethod GetPaymentMethod(int id)
        {
            var paymentInfo = PaymentOptionInfoProvider.GetPaymentOptionInfo(id);
            var method      = mapper.Map <PaymentMethod>(paymentInfo);

            method.Title = resources.ResolveMacroString(method.DisplayName);
            return(method);
        }
Exemplo n.º 11
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)));
        }
        //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)));
        }
 private static bool CheckPaymentIsAllowedForShipping(ShoppingCartInfo currentShoppingCart, int paymentOptionId)
 {
     return((currentShoppingCart.ShoppingCartShippingOptionID == 0) ||
            (PaymentOptionInfoProvider.GetPaymentOptionsForShipping(currentShoppingCart.ShoppingCartShippingOptionID, true)
             .Where("PaymentOptionID", QueryOperator.Equals, paymentOptionId)
             .TopN(1)
             .Any()));
 }
    private bool CheckPaymentIsGateway(string paymentID)
    {
        bool result               = false;
        int  paymentid            = int.Parse(paymentID);
        PaymentOptionInfo payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(paymentid);

        result = string.Equals(payment.PaymentOptionDescription, "PAYMENTGATEWAY");
        return(result);
    }
    /// <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";

            DataSet dsOptions;

            // Get correct payment options if shipping is set or not
            if (ShoppingCart.ShippingOption != null)
            {
                dsOptions = PaymentOptionInfoProvider.GetPaymentOptionsForShipping(ShoppingCart.ShippingOption.ShippingOptionID, true)
                            .Column("PaymentOptionID")
                            .OrderBy("PaymentOptionDisplayName");
            }
            else
            {
                dsOptions = PaymentOptionInfoProvider.GetPaymentOptions(ShoppingCart.ShoppingCartSiteID, true)
                            .Column("PaymentOptionID")
                            .WhereTrue("PaymentOptionAllowIfNoShipping")
                            .OrderBy("PaymentOptionDisplayName");
            }

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

            if (!DataHelper.DataSourceIsEmpty(dsOptions))
            {
                paymentIds = DataHelper.GetIntegerValues(dsOptions.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 selected shipping option to determine available payment options
            drpPayment.ShippingOptionID = ShoppingCart.ShoppingCartShippingOptionID;
            drpPayment.DisplayOnlyAllowedIfNoShipping = (drpPayment.ShippingOptionID <= 0);

            if ((ShoppingCart.ShoppingCartPaymentOptionID != 0) && !paymentIds.Contains(ShoppingCart.ShoppingCartPaymentOptionID))
            {
                // 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();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for CMS Desk -> Ecommerce
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "Configuration.ShippingOptions.PaymentMethods"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "Configuration.ShippingOptions.PaymentMethods");
        }

        bool offerGlobalPaymentMethods = false;

        lblAvialable.Text = GetString("com.shippingoption.payments");
        mShippingOptionId = QueryHelper.GetInteger("shippingoptionid", 0);
        if (mShippingOptionId > 0)
        {
            mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId);
            EditedObject           = mShippingOptionInfoObj;

            if (mShippingOptionInfoObj != null)
            {
                int editedSiteId = mShippingOptionInfoObj.ShippingOptionSiteID;
                // Check object's site id
                CheckEditedObjectSiteID(editedSiteId);

                // Offer global payment methods when allowed or configuring global shipping option
                if (editedSiteId != 0)
                {
                    SiteInfo si = SiteInfoProvider.GetSiteInfo(editedSiteId);
                    if (si != null)
                    {
                        offerGlobalPaymentMethods = ECommerceSettings.AllowGlobalPaymentMethods(si.SiteName);
                    }
                }
                // Configuring global shipping option
                else
                {
                    offerGlobalPaymentMethods = true;
                }

                DataSet ds = PaymentOptionInfoProvider.GetPaymentOptionsForShipping(mShippingOptionId, false);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    mCurrentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "PaymentOptionID"));
                }

                if (!RequestHelper.IsPostBack())
                {
                    uniSelector.Value = mCurrentValues;
                }
            }
        }

        uniSelector.IconPath            = GetObjectIconUrl("ecommerce.paymentoption", "object.png");
        uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged;
        uniSelector.WhereCondition      = GetSelectorWhereCondition(offerGlobalPaymentMethods);
    }
Exemplo n.º 17
0
        public PaymentMethod[] GetPaymentMethods()
        {
            var paymentOptionInfoCollection = PaymentOptionInfoProvider.GetPaymentOptions(SiteContext.CurrentSiteID).Where(p => p.PaymentOptionEnabled).ToArray();
            var methods = mapper.Map <PaymentMethod[]>(paymentOptionInfoCollection);

            foreach (var method in methods)
            {
                method.Title = resources.ResolveMacroString(method.DisplayName);
            }
            return(methods);
        }
    // Displays PaymentList
    private void ShowPaymentList()
    {
        DataSet ds = PaymentOptionInfoProvider.GetPaymentOptions(CurrentSite.SiteID, true);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            ddlPaymentOption.DataSource     = ds;
            ddlPaymentOption.DataTextField  = "PaymentOptionDisplayName";
            ddlPaymentOption.DataValueField = "PaymentOptionId";
            ddlPaymentOption.DataBind();
            ddlPaymentOption.SelectedValue = ValidationHelper.GetString(SessionHelper.GetValue("PaymentID"), string.Empty);
            ddlPaymentOption_SelectedIndexChanged(null, null);
        }
    }
        /// <summary>
        /// Returns a payment method with the specified identifier.
        /// </summary>
        /// <param name="paymentMethodId">Payment method's identifier.</param>
        /// <returns><see cref="PaymentOptionInfo"/> object representing a payment method with the specified identifier. Returns <c>null</c> if not found.</returns>
        public PaymentOptionInfo GetById(int paymentMethodId)
        {
            var paymentInfo = PaymentOptionInfoProvider.GetPaymentOptionInfo(paymentMethodId);

            if (paymentInfo?.PaymentOptionSiteID == SiteID)
            {
                return(paymentInfo);
            }

            if (paymentInfo?.PaymentOptionSiteID == 0 && ECommerceSettings.AllowGlobalPaymentMethods(SiteID))
            {
                return(paymentInfo);
            }

            return(null);
        }
    protected void InitPaymentShipping()
    {
        // shipping option and payment method
        lblShippingOption.Text = GetString("Ecommerce.CartContent.ShippingOption");
        lblPaymentMethod.Text  = GetString("Ecommerce.CartContent.PaymentMethod");
        lblShipping.Text       = GetString("Ecommerce.CartContent.Shipping");

        if (IsShippingNeeded && currentSite != null)
        {
            // get shipping option name
            ShippingOptionInfo shippingObj = ShoppingCart.ShippingOption;
            if (shippingObj != null)
            {
                mAddressCount++;
                //plcShippingAddress.Visible = true;
                tdShippingAddress.Visible   = true;
                plcShipping.Visible         = true;
                plcShippingOption.Visible   = true;
                lblShippingOptionValue.Text = HTMLHelper.HTMLEncode(shippingObj.ShippingOptionDisplayName);
                lblShippingValue.Text       = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalShipping, ShoppingCart.Currency);
            }
            else
            {
                //plcShippingAddress.Visible = false;
                tdShippingAddress.Visible = false;
                plcShippingOption.Visible = false;
                lblShippingValue.Text     = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalShipping, ShoppingCart.Currency);
                //plcShipping.Visible = false;
            }
        }

        // get payment method name
        PaymentOptionInfo paymentObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(ShoppingCart.ShoppingCartPaymentOptionID);

        if (paymentObj != null)
        {
            lblPaymentMethodValue.Text = HTMLHelper.HTMLEncode(paymentObj.PaymentOptionDisplayName);
        }


        // total price initialization
        lblTotalPrice.Text      = GetString("ecommerce.cartcontent.totalprice");
        lblTotalPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.RoundedTotalPrice, ShoppingCart.Currency);
    }
Exemplo n.º 21
0
        /// <summary>
        /// Sets the payment result to the <see cref="Order"/> object.
        /// </summary>
        /// <remarks>
        /// In case the <see cref="PaymentResultInfo.PaymentIsCompleted"/> property of <paramref name="paymentResult"/> is true, the order is marked as paid and the order status is set according to <see cref="PaymentOptionInfo.PaymentOptionSucceededOrderStatusID"/>.
        /// The <paramref name="paymentFailed"/> parameter indicates if the order is marked as unpaid and the order status is set according to <see cref="PaymentOptionInfo.PaymentOptionFailedOrderStatusID"/>.
        /// </remarks>
        /// <param name="paymentResult"><see cref="PaymentResultInfo"/> object representing an original Kentico payment result object from which the model is created.</param>
        /// <param name="paymentFailed">Indicates if the payment failed.</param>
        public void SetPaymentResult(PaymentResultInfo paymentResult, bool paymentFailed = false)
        {
            if (paymentResult == null)
            {
                throw new ArgumentNullException(nameof(paymentResult));
            }
            if (paymentResult.PaymentIsCompleted && paymentFailed)
            {
                throw new InvalidOperationException("Order payment failed but paymentResult.PaymentIsCompleted is true");
            }

            OriginalOrder.OrderPaymentResult = paymentResult;
            var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(OriginalOrder.OrderPaymentOptionID);

            if (paymentResult.PaymentIsCompleted)
            {
                var successStatusId = payment?.PaymentOptionSucceededOrderStatusID ?? 0;
                if (successStatusId > 0)
                {
                    OriginalOrder.OrderStatusID = successStatusId;
                }

                OriginalOrder.OrderIsPaid = true;
            }

            if (paymentFailed)
            {
                var failedStatusId = payment?.PaymentOptionFailedOrderStatusID ?? 0;
                if (failedStatusId > 0)
                {
                    OriginalOrder.OrderStatusID = failedStatusId;
                }

                OriginalOrder.OrderIsPaid = false;
            }

            Save();
        }
Exemplo n.º 22
0
 private IEnumerable <PaymentOptionInfo> GetApplicablePaymentMethods(ShoppingCartInfo cart)
 {
     return(mPaymentMethodRepository.GetAll().Where(paymentMethod => PaymentOptionInfoProvider.IsPaymentOptionApplicable(cart, paymentMethod)));
 }
Exemplo n.º 23
0
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        // Orders from current site
        var where = new WhereCondition()
                    .WhereEquals("OrderSiteID", SiteContext.CurrentSiteID);

        // Order status filter
        var status = OrderStatusInfoProvider.GetOrderStatusInfo(OrderStatus, SiteContext.CurrentSiteName);

        if (status != null)
        {
            where.WhereEquals("OrderStatusID", status.StatusID);
        }

        // Customer or company like filter
        if (!string.IsNullOrEmpty(CustomerOrCompany))
        {
            where.WhereIn("OrderCustomerID", new IDQuery <CustomerInfo>()
                          .Where("CustomerFirstName + ' ' + CustomerLastName + ' ' + CustomerFirstName LIKE N'%" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(CustomerOrCompany)) + "%'")
                          .Or()
                          .WhereContains("CustomerCompany", CustomerOrCompany));
        }

        // Filter for orders with note
        if (HasNote)
        {
            where.WhereNotEmpty("OrderNote");
        }

        // Payment method filter
        var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(PaymentMethod, SiteContext.CurrentSiteName);

        if (payment != null)
        {
            where.WhereEquals("OrderPaymentOptionID", payment.PaymentOptionID);
        }

        // Payment status filter
        switch (PaymentStatus.ToLowerCSafe())
        {
        case PAY_STATUS_NOT_PAID:
            where.Where(new WhereCondition().WhereFalse("OrderIsPaid").Or().WhereNull("OrderIsPaid"));
            break;

        case PAY_STATUS_PAID:
            where.WhereTrue("OrderIsPaid");
            break;
        }

        // Currency filter
        var currencyObj = CurrencyInfoProvider.GetCurrencyInfo(Currency, SiteContext.CurrentSiteName);

        if (currencyObj != null)
        {
            where.WhereEquals("OrderCurrencyID", currencyObj.CurrencyID);
        }

        // Min price in main currency filter
        if (MinPriceInMainCurrency > 0)
        {
            where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LargerOrEquals, MinPriceInMainCurrency);
        }

        // Max price in main currency filter
        if (MaxPriceInMainCurrency > 0)
        {
            where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LessOrEquals, MaxPriceInMainCurrency);
        }

        // Shipping option filter
        var shipping = ShippingOptionInfoProvider.GetShippingOptionInfo(ShippingOption, SiteContext.CurrentSiteName);

        if (shipping != null)
        {
            where.WhereEquals("OrderShippingOptionID", shipping.ShippingOptionID);
        }

        // Shipping country filter
        if (!string.IsNullOrEmpty(ShippingCountry) && ShippingCountry != "0")
        {
            AddCountryWhereCondition(where);
        }

        // Date filter
        AddDateWhereCondition(where);

        return(where);
    }
        private void GenerateEcommerceData(int siteID)
        {
            var siteName     = SiteInfoProvider.GetSiteName(siteID);
            var currencyInfo = CurrencyInfoProvider.GetCurrencies(siteID)
                               .Where("CurrencyIsMain", QueryOperator.Equals, 1).TopN(1).FirstOrDefault();
            var list1 = PaymentOptionInfoProvider.GetPaymentOptions(siteID).ToList();
            var list2 = ShippingOptionInfoProvider.GetShippingOptions(siteID).ToList();

            var orderStatusList = OrderStatusInfoProvider.GetOrderStatuses(siteID).ToDictionary(status => status.StatusName);

            var manufacturerExceptionList = new List <int>
            {
                ManufacturerInfoProvider.GetManufacturerInfo("Aerobie", siteName).ManufacturerID,
                //ManufacturerInfoProvider.GetManufacturerInfo("Chemex", siteName).ManufacturerID,
                //ManufacturerInfoProvider.GetManufacturerInfo("Espro", siteName).ManufacturerID
            };
            var list3 = SKUInfoProvider.GetSKUs(siteID).ToList().Where(sku =>
            {
                if (sku.IsProduct)
                {
                    return(!manufacturerExceptionList.Contains(sku.SKUManufacturerID));
                }
                return(false);
            }).ToList();
            int         num1;
            IList <int> intList;

            if (CustomerInfoProvider.GetCustomers().WhereEquals("CustomerSiteID", siteID).Count < 50)
            {
                num1    = customerNames.Length;
                intList = new List <int>();
                for (var index = 0; index < num1; ++index)
                {
                    intList.Add(GenerateCustomer(customerNames[index], siteID).CustomerID);
                }
            }
            else
            {
                intList = DataHelper.GetIntegerValues(CustomerInfoProvider.GetCustomers().Column("CustomerID")
                                                      .WhereEquals("CustomerSiteID", siteID).WhereNotEquals("CustomerEmail", "alex").Tables[0],
                                                      "CustomerID");
                num1 = intList.Count;
            }

            var num2 = 0;
            var num3 = 0;

            for (var index1 = 0; index1 <= 30; ++index1)
            {
                ++num2;
                var num4 = 0;
                if (index1 > 5)
                {
                    num4 = rand.Next(-1, 2);
                }
                for (var index2 = 0; index2 < num2 / 2 + num4; ++index2)
                {
                    var orderStatusInfo = index1 >= 25
                        ? index1 >= 29 ? orderStatusList["New"] : orderStatusList["InProgress"]
                        : orderStatusList["Completed"];
                    var orderInfo = new OrderInfo
                    {
                        OrderCustomerID = intList[num3 % num1],
                        OrderCurrencyID = currencyInfo.CurrencyID,
                        OrderSiteID     = siteID,
                        OrderStatusID   = orderStatusInfo.StatusID,
                        OrderIsPaid     = "Completed".Equals(orderStatusInfo.StatusName, StringComparison.Ordinal) ||
                                          (uint)rand.Next(0, 2) > 0U,
                        OrderShippingOptionID         = list2[rand.Next(list2.Count)].ShippingOptionID,
                        OrderPaymentOptionID          = list1[rand.Next(list1.Count)].PaymentOptionID,
                        OrderGrandTotal               = decimal.Zero,
                        OrderGrandTotalInMainCurrency = decimal.Zero,
                        OrderTotalPrice               = decimal.Zero,
                        OrderTotalPriceInMainCurrency = decimal.Zero,
                        OrderTotalShipping            = new decimal(10),
                        OrderTotalTax = new decimal(10)
                    };
                    OrderInfoProvider.SetOrderInfo(orderInfo);
                    var orderItems = GenerateOrderItems(orderInfo, list3);
                    GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Billing);
                    GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Shipping);
                    orderInfo.OrderDate       = DateTime.Now.AddDays(index1 - 30);
                    orderInfo.OrderTotalPrice = orderItems;
                    orderInfo.OrderTotalPriceInMainCurrency = orderItems;
                    orderInfo.OrderGrandTotal = orderItems;
                    orderInfo.OrderGrandTotalInMainCurrency = orderItems;
                    var cartInfoFromOrder = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderInfo.OrderID);
                    orderInfo.OrderInvoiceNumber = OrderInfoProvider.GenerateInvoiceNumber(cartInfoFromOrder);
                    orderInfo.OrderInvoice       = ShoppingCartInfoProvider.GetOrderInvoice(cartInfoFromOrder);
                    OrderInfoProvider.SetOrderInfo(orderInfo);
                    ++num3;
                }
            }

            if (UserInfoProvider.GetUserInfo("alex") != null)
            {
                return;
            }
            var customerInfo = new CustomerInfo
            {
                CustomerEmail             = "*****@*****.**",
                CustomerFirstName         = "Alexander",
                CustomerLastName          = "Adams",
                CustomerSiteID            = siteID,
                CustomerCompany           = "Alex & Co. Ltd",
                CustomerTaxRegistrationID = "12S379BDF798",
                CustomerOrganizationID    = "WRQ7987VRG79"
            };

            CustomerInfoProvider.SetCustomerInfo(customerInfo);
            var userInfo = CustomerInfoProvider.RegisterCustomer(customerInfo, "", "alex");
            var roleInfo = RoleInfoProvider.GetRoleInfo("SilverPartner", siteID);

            if (roleInfo != null)
            {
                UserInfoProvider.AddUserToRole(userInfo.UserID, roleInfo.RoleID);
            }
            for (var index = 0; index < 5; ++index)
            {
                var cart = new ShoppingCartInfo();
                cart.ShoppingCartCulture         = CultureHelper.GetDefaultCultureCode(siteName);
                cart.ShoppingCartCurrencyID      = currencyInfo.CurrencyID;
                cart.ShoppingCartSiteID          = siteID;
                cart.ShoppingCartCustomerID      = customerInfo.CustomerID;
                cart.ShoppingCartBillingAddress  = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID);
                cart.ShoppingCartShippingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID);
                cart.User = userInfo;
                ShoppingCartInfoProvider.SetShoppingCartInfo(cart);
                ShoppingCartInfoProvider.SetShoppingCartItem(cart,
                                                             new ShoppingCartItemParameters(list3.ElementAt(rand.Next(list3.Count)).SKUID, rand.Next(5)));
                cart.Evaluate();
                ShoppingCartInfoProvider.SetOrder(cart);
            }
        }
Exemplo n.º 25
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);
 /// <summary>
 /// Returns an enumerable collection of all enabled payment methods.
 /// </summary>
 /// <returns>Collection of enabled payment methods. See <see cref="PaymentOptionInfo"/> for detailed information.</returns>
 public IEnumerable <PaymentOptionInfo> GetAll()
 {
     return(PaymentOptionInfoProvider.GetPaymentOptions(SiteID, true)
            .ToList());
 }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check input values from textboxes and other contrlos
        string errorMessage = new Validator()
                              .NotEmpty(txtPaymentOptionDisplayName.Text.Trim(), GetString("paymentoption_edit.errorEmptyDisplayName"))
                              .NotEmpty(txtPaymentOptionName.Text.Trim(), GetString("paymentoption_edit.errorEmptyCodeName")).Result;

        if (!ValidationHelper.IsCodeName(txtPaymentOptionName.Text.Trim()))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat");
        }

        if (errorMessage == "")
        {
            // PaymentOptionName must be unique
            PaymentOptionInfo paymentOptionObj = null;
            string            siteWhere        = (mSiteId > 0) ? " AND (PaymentOptionSiteID = " + mSiteId + " OR PaymentOptionSiteID IS NULL)" : "";
            DataSet           ds = PaymentOptionInfoProvider.GetPaymentOptions("PaymentOptionName = '" + txtPaymentOptionName.Text.Trim().Replace("'", "''") + "'" + siteWhere, null, 1, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                paymentOptionObj = new PaymentOptionInfo(ds.Tables[0].Rows[0]);
            }

            if ((paymentOptionObj == null) || (paymentOptionObj.PaymentOptionID == mPaymentOptionId))
            {
                // Get the object
                if (paymentOptionObj == null)
                {
                    paymentOptionObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(mPaymentOptionId);
                    if (paymentOptionObj == null)
                    {
                        paymentOptionObj = new PaymentOptionInfo();
                        paymentOptionObj.PaymentOptionSiteID = mSiteId;
                    }
                }

                // Fill object
                paymentOptionObj.PaymentOptionID                     = mPaymentOptionId;
                paymentOptionObj.PaymentOptionDisplayName            = txtPaymentOptionDisplayName.Text.Trim();
                paymentOptionObj.PaymentOptionDescription            = txtDescription.Text.Trim();
                paymentOptionObj.PaymentOptionName                   = txtPaymentOptionName.Text.Trim();
                paymentOptionObj.PaymentOptionEnabled                = chkPaymentOptionEnabled.Checked;
                paymentOptionObj.PaymentOptionPaymentGateUrl         = txtGateUrl.Text.Trim();
                paymentOptionObj.PaymentOptionClassName              = txtPaymentClassName.Text.Trim();
                paymentOptionObj.PaymentOptionAssemblyName           = txtPaymentAssemblyName.Text.Trim();
                paymentOptionObj.PaymentOptionSucceededOrderStatusID = succeededElem.OrderStatusID;
                paymentOptionObj.PaymentOptionFailedOrderStatusID    = failedElem.OrderStatusID;
                paymentOptionObj.PaymentOptionAllowIfNoShipping      = chkAllowIfNoShipping.Checked;

                CheckConfigurationModification(paymentOptionObj.PaymentOptionSiteID);

                bool isNew = (paymentOptionObj.PaymentOptionID <= 0);

                PaymentOptionInfoProvider.SetPaymentOptionInfo(paymentOptionObj);

                // Upload image teaser
                if (isNew)
                {
                    file.ObjectID = paymentOptionObj.PaymentOptionID;
                    file.UploadFile();
                }

                URLHelper.Redirect("PaymentOption_Edit.aspx?paymentOptionId=" + Convert.ToString(paymentOptionObj.PaymentOptionID) + "&saved=1&siteId=" + SiteID);
            }
            else
            {
                // Show error message
                ShowError(GetString("PaymentOption_Edit.PaymentOptionNameExists"));
            }
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }
Exemplo n.º 28
0
    protected void OnBeforeSave(object sender, EventArgs e)
    {
        if ((Order == null) || (ShippingAddressSelector == null) || (ShippingOptionSelector == null) || (ShoppingCartFromOrder == null))
        {
            return;
        }

        // Get current values
        var addressID        = ValidationHelper.GetInteger(ShippingAddressSelector.Value, 0);
        var shippingOptionID = ValidationHelper.GetInteger(ShippingOptionSelector.Value, 0);

        // Is shipping needed?
        var isShippingNeeded = ShoppingCartFromOrder.IsShippingNeeded;

        // If shipping address is required
        if (isShippingNeeded || IsTaxBasedOnShippingAddress)
        {
            // If shipping address is not set
            if (addressID <= 0)
            {
                // Show error message
                ShowError(GetString("Order_Edit_Shipping.NoAddress"));
                return;
            }
        }

        try
        {
            // Check if original order shipping option was changed, the check cannot be done on edited object because edited object contains current value (not the original one)
            if (ShoppingCartFromOrder.ShoppingCartShippingOptionID != shippingOptionID)
            {
                PaymentOptionInfo payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(Order.OrderPaymentOptionID);

                // Check if payment is allowed with no shipping
                if ((payment != null) && (!payment.PaymentOptionAllowIfNoShipping && shippingOptionID == 0))
                {
                    // Set payment method to none and display warning
                    ShoppingCartFromOrder.ShoppingCartPaymentOptionID = 0;

                    var paymentMethodName  = ResHelper.LocalizeString(payment.PaymentOptionDisplayName, null, true);
                    var shippingOptionName = HTMLHelper.HTMLEncode(ShippingOptionSelector.ValueDisplayName);

                    ShowWarning(String.Format(GetString("com.shippingoption.paymentsetnone"), paymentMethodName, shippingOptionName));
                }

                // Set order new properties
                ShoppingCartFromOrder.ShoppingCartShippingOptionID = shippingOptionID;

                // Evaluate order data
                ShoppingCartFromOrder.Evaluate();

                // Update order data
                ShoppingCartInfoProvider.SetOrder(ShoppingCartFromOrder, true);
            }

            var newTrackingNumber = ValidationHelper.GetString(orderShippingForm.FieldEditingControls["OrderTrackingNumber"].DataValue, String.Empty).Trim();

            if (!newTrackingNumber.Equals(ShoppingCartFromOrder.Order.OrderTrackingNumber, StringComparison.InvariantCulture))
            {
                // Update on the current order instance
                var order = ShoppingCartFromOrder.Order;
                order.OrderTrackingNumber = newTrackingNumber;
                OrderInfoProvider.SetOrderInfo(Order);
            }

            // Show message
            ShowChangesSaved();

            // Stop automatic saving action
            orderShippingForm.StopProcessing = true;
        }
        catch (Exception ex)
        {
            // Show error message
            ShowError(ex.Message);
        }
    }
Exemplo n.º 29
0
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView dr = null;
        bool        orderCurrencyIsMain = false;

        switch (sourceName.ToLowerCSafe())
        {
        case "idandinvoice":
            dr = (DataRowView)parameter;
            int    orderId       = ValidationHelper.GetInteger(dr["OrderID"], 0);
            string invoiceNumber = ValidationHelper.GetString(dr["OrderInvoiceNumber"], "");

            // Show OrderID and invoice number in brackets if InvoiceNumber is different from OrderID
            if (!string.IsNullOrEmpty(invoiceNumber) && (invoiceNumber != orderId.ToString()))
            {
                return(HTMLHelper.HTMLEncode(orderId + " (" + invoiceNumber + ")"));
            }
            return(orderId);

        case "customer":
            dr = (DataRowView)parameter;
            string customerName    = dr["CustomerFirstName"] + " " + dr["CustomerLastName"];
            string customerCompany = ValidationHelper.GetString(dr["CustomerCompany"], "");

            // Show customer name and company in brakcets, if company specified
            if (!string.IsNullOrEmpty(customerCompany))
            {
                return(HTMLHelper.HTMLEncode(customerName + " (" + customerCompany + ")"));
            }
            return(HTMLHelper.HTMLEncode(customerName));

        //
        case "email":
            dr = (DataRowView)parameter;
            string mailCustomer = ValidationHelper.GetString(dr["CustomerEmail"], "");
            // Show customer mail
            return(HTMLHelper.HTMLEncode(mailCustomer));

        //

        case "totalpriceinmaincurrency":
            dr = (DataRowView)parameter;
            double totalPriceInMainCurrency = ValidationHelper.GetDouble(dr["OrderTotalPriceInMainCurrency"], 0);
            orderCurrencyIsMain = ValidationHelper.GetBoolean(dr["CurrencyIsMain"], false);

            // Format currency
            string priceInMainCurrencyFormatted = "";
            if (orderCurrencyIsMain)
            {
                priceInMainCurrencyFormatted = String.Format(dr["CurrencyFormatString"].ToString(), totalPriceInMainCurrency);
            }
            else
            {
                int siteId = ValidationHelper.GetInteger(dr["OrderSiteID"], 0);
                priceInMainCurrencyFormatted = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, siteId);
            }

            return(HTMLHelper.HTMLEncode(priceInMainCurrencyFormatted));

        case "totalpriceinorderprice":
            dr = (DataRowView)parameter;
            orderCurrencyIsMain = ValidationHelper.GetBoolean(dr["CurrencyIsMain"], false);

            if (orderCurrencyIsMain)
            {
                return("-");
            }

            // If order is not in main currency, show order price
            double orderTotalPrice = ValidationHelper.GetDouble(dr["OrderTotalPrice"], 0);
            string priceFormatted  = String.Format(dr["CurrencyFormatString"].ToString(), orderTotalPrice);

            // Formated currency
            return(HTMLHelper.HTMLEncode(priceFormatted));

        case "orderpaymentoptionid":
            // Tranform to display name and localize
            int paymentOptionId             = ValidationHelper.GetInteger(parameter, 0);
            PaymentOptionInfo paymentOption = PaymentOptionInfoProvider.GetPaymentOptionInfo(paymentOptionId);

            if (paymentOption != null)
            {
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(paymentOption.PaymentOptionDisplayName)));
            }
            break;

        case "ordershippingoptionid":
            // Tranform to display name and localize
            int shippingOptionId = ValidationHelper.GetInteger(parameter, 0);
            ShippingOptionInfo shippingOption = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingOptionId);

            if (shippingOption != null)
            {
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(shippingOption.ShippingOptionDisplayName)));
            }
            break;

        case "note":
            string note = ValidationHelper.GetString(parameter, "");

            if (string.IsNullOrEmpty(note))
            {
                return("-");
            }
            // Display link, note is in tooltip
            return("<a>" + GetString("general.view") + "</a>");
        }
        return(parameter);
    }
    /// <summary>
    /// Convert given payment option name to its ID for specified site.
    /// </summary>
    /// <param name="name">Name of the payment option to be converted.</param>
    /// <param name="siteName">Name of the site of the payment option.</param>
    protected override int GetID(string name, string siteName)
    {
        var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(name, siteName);

        return((payment != null) ? payment.PaymentOptionID : 0);
    }