/// <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);
        }
    }
    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);
    }
Example #3
0
        /// <summary>
        /// Creates a payment method model.
        /// </summary>
        /// <param name="paymentMethod">Selected payment method.</param>
        /// <param name="paymentMethods">List of all available payment methods.</param>
        public PaymentMethodViewModel(PaymentOptionInfo paymentMethod, SelectList paymentMethods)
        {
            PaymentMethods = paymentMethods;

            if (paymentMethod != null)
            {
                PaymentMethodID = paymentMethod.PaymentOptionID;
            }
        }
    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);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Field validator error messages initialization
        rfvDisplayName.ErrorMessage = GetString("paymentoption_edit.errorEmptyDisplayName");
        rfvCodeName.ErrorMessage    = GetString("paymentoption_edit.errorEmptyCodeName");

        string currentPaymentOption = GetString("PaymentOption_Edit.NewItemCaption");

        // Get paymentOption id from querystring
        mPaymentOptionId = QueryHelper.GetInteger("paymentOptionId", 0);
        mSiteId          = ConfiguredSiteID;
        if (mPaymentOptionId > 0)
        {
            PaymentOptionInfo paymentOptionObj = EditedObject as PaymentOptionInfo;

            if (paymentOptionObj != null)
            {
                currentPaymentOption = ResHelper.LocalizeString(paymentOptionObj.PaymentOptionDisplayName);
                mSiteId = paymentOptionObj.PaymentOptionSiteID;
                CheckEditedObjectSiteID(mSiteId);

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(paymentOptionObj);

                    // Show that the paymentOption was created or updated successfully
                    if (QueryHelper.GetString("saved", "") == "1")
                    {
                        // Show message
                        ShowChangesSaved();
                    }
                }
            }
        }

        // Init file uploader
        file.ObjectID   = mPaymentOptionId;
        file.ObjectType = ECommerceObjectType.PAYMENTOPTION;
        file.Category   = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL;
        file.SiteID     = mSiteId;

        succeededElem.SiteID = mSiteId;
        failedElem.SiteID    = mSiteId;

        // Initializes page title control
        string[,] pageTitleTabs         = new string[2, 3];
        pageTitleTabs[0, 0]             = GetString("PaymentOption_Edit.ItemListLink");
        pageTitleTabs[0, 1]             = "~/CMSModules/Ecommerce/Pages/Tools/Configuration/PaymentOptions/PaymentOption_List.aspx?siteId=" + SiteID;
        pageTitleTabs[0, 2]             = "";
        pageTitleTabs[1, 0]             = FormatBreadcrumbObjectName(currentPaymentOption, mSiteId);
        pageTitleTabs[1, 1]             = "";
        pageTitleTabs[1, 2]             = "";
        CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
    }
Example #6
0
        private void SetUpPaymentOptions()
        {
            mPaymentOption = Factory.PaymentMethodDefault;
            mPaymentOption.PaymentOptionFailedOrderStatusID    = mOrderStatusFailed.StatusID;
            mPaymentOption.PaymentOptionSucceededOrderStatusID = mOrderStatusPaid.StatusID;
            mPaymentOption.Update();

            mPaymentOptionWithoutStatus = Factory.NewPaymentOption();
            mPaymentOptionWithoutStatus.PaymentOptionFailedOrderStatusID    = 0;
            mPaymentOptionWithoutStatus.PaymentOptionSucceededOrderStatusID = 0;
            mPaymentOptionWithoutStatus.Insert();
        }
 /// <summary>
 /// Load data of editing paymentOption.
 /// </summary>
 /// <param name="paymentOptionObj">PaymentOption object</param>
 protected void LoadData(PaymentOptionInfo paymentOptionObj)
 {
     txtPaymentOptionName.Text        = paymentOptionObj.PaymentOptionName;
     chkPaymentOptionEnabled.Checked  = paymentOptionObj.PaymentOptionEnabled;
     txtPaymentOptionDisplayName.Text = paymentOptionObj.PaymentOptionDisplayName;
     txtGateUrl.Text                   = paymentOptionObj.PaymentOptionPaymentGateUrl;
     txtPaymentAssemblyName.Text       = paymentOptionObj.PaymentOptionAssemblyName;
     txtPaymentClassName.Text          = paymentOptionObj.PaymentOptionClassName;
     succeededElem.OrderStatusID       = paymentOptionObj.PaymentOptionSucceededOrderStatusID;
     failedElem.OrderStatusID          = paymentOptionObj.PaymentOptionFailedOrderStatusID;
     this.chkAllowIfNoShipping.Checked = paymentOptionObj.PaymentOptionAllowIfNoShipping;
 }
    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);
    }
        /// <summary>
        /// Prepares a view model of the preview checkout process step including the shopping cart,
        /// the customer details, and the payment method.
        /// </summary>
        /// <returns>View model with information about the future order.</returns>
        private PreviewAndPayViewModel PreparePreviewViewModel()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // Prepares the customer details
            DeliveryDetailsViewModel deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), null, null),
                ShippingOption = new ShippingOptionViewModel()
                {
                    ShippingOptionID          = cart.ShippingOption.ShippingOptionID,
                    ShippingOptionDisplayName = ShippingOptionInfoProvider.GetShippingOptionInfo(cart.ShippingOption.ShippingOptionID).ShippingOptionDisplayName
                }
            };

            // Prepares the payment method
            PaymentMethodViewModel paymentViewModel = new PaymentMethodViewModel
            {
                PaymentMethods = new SelectList(GetApplicablePaymentMethods(cart), "PaymentOptionID", "PaymentOptionDisplayName")
            };

            // Gets the selected payment method
            PaymentOptionInfo paymentMethod = cart.PaymentOption;

            if (paymentMethod != null)
            {
                paymentViewModel.PaymentMethodID = paymentMethod.PaymentOptionID;
            }

            // Prepares a model from the preview step
            PreviewAndPayViewModel model = new PreviewAndPayViewModel
            {
                DeliveryDetails = deliveryDetailsModel,
                Cart            = new ShoppingCartViewModel(cart),
                PaymentMethod   = paymentViewModel
            };

            return(model);
        }
        internal IEnumerable <PaymentOptionInfo> InitPaymentMethods()
        {
            return(new[]
            {
                PaymentMethodDefault = new PaymentOptionInfo
                {
                    PaymentOptionDisplayName = "Cash on delivery",
                    PaymentOptionName = "CashOnDelivery",
                    PaymentOptionEnabled = true,
                    PaymentOptionSiteID = SiteInfo.SiteID
                },

                PaymentMethodDisabled = new PaymentOptionInfo
                {
                    PaymentOptionDisplayName = "Money transfer",
                    PaymentOptionName = "MoneyTransfer",
                    PaymentOptionEnabled = false,
                    PaymentOptionSiteID = SiteInfo.SiteID
                }
            });
        }
        //EndDocSection:PreparePayment

        //DocSection:PreparePreview
        /// <summary>
        /// Prepares a view model of the preview checkout process step including the shopping cart,
        /// the customer details, and the payment method.
        /// </summary>
        /// <returns>View model with information about the future order.</returns>
        private PreviewAndPayViewModel PreparePreviewViewModel()
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // Prepares the customer details
            DeliveryDetailsViewModel deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerModel(cart.Customer),
                BillingAddress = new BillingAddressModel(cart.BillingAddress, null, null)
            };

            // Prepares the payment method
            PaymentMethodViewModel paymentViewModel = new PaymentMethodViewModel
            {
                PaymentMethods = new SelectList(GetApplicablePaymentMethods(cart), "PaymentOptionID", "PaymentOptionDisplayName")
            };

            // Gets the selected payment method if any
            PaymentOptionInfo paymentMethod = cart.PaymentMethod;

            if (paymentMethod != null)
            {
                paymentViewModel.PaymentMethodID = paymentMethod.PaymentOptionID;
            }

            // Prepares a model from the preview step
            PreviewAndPayViewModel model = new PreviewAndPayViewModel
            {
                DeliveryDetails = deliveryDetailsModel,
                Cart            = cart,
                PaymentMethod   = paymentViewModel
            };

            return(model);
        }
Example #12
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);
    protected void OnBeforeSave(object sender, EventArgs e)
    {
        if ((Order == null) || (ShippingAddressSelector == null) || (ShippingOptionSelector == null))
        {
            return;
        }

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

        // Is shipping needed?
        bool isShippingNeeded = ((ShoppingCartFromOrder != null) && 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
        {
            // Shipping option changed
            if ((ShoppingCartFromOrder != null) && (Order.OrderShippingOptionID != shippingOptionID))
            {
                // Shipping option and payment method combination is not allowed
                if (PaymentShippingInfoProvider.GetPaymentShippingInfo(Order.OrderPaymentOptionID, shippingOptionID) == null)
                {
                    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;

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

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

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

                // Evaluate order data
                ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCartFromOrder);

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

            // Update tracking number
            Order.OrderTrackingNumber = ValidationHelper.GetString(orderShippingForm.FieldEditingControls["OrderTrackingNumber"].DataValue, String.Empty).Trim();
            OrderInfoProvider.SetOrderInfo(Order);

            // Show message
            ShowChangesSaved();

            // Stop automatic saving action
            orderShippingForm.StopProcessing = true;
        }
        catch (Exception ex)
        {
            // Show error message
            ShowError(ex.Message);
        }
    }
    /// <summary>
    /// Gets and bulk updates payment methods. Called when the "Get and bulk update methods" button is pressed.
    /// Expects the CreatePaymentMethod method to be run first.
    /// </summary>
    private bool GetAndBulkUpdatePaymentMethods()
    {
        // Prepare the parameters
        string where = "PaymentOptionName LIKE N'MyNewMethod%'";
        where = SqlHelperClass.AddWhereCondition(where, "PaymentOptionSiteID = " + CMSContext.CurrentSiteID, "AND");

        // Get the data
        DataSet methods = PaymentOptionInfoProvider.GetPaymentOptions(where, null);
        if (!DataHelper.DataSourceIsEmpty(methods))
        {
            // Loop through the individual items
            foreach (DataRow methodDr in methods.Tables[0].Rows)
            {
                // Create object from DataRow
                PaymentOptionInfo modifyMethod = new PaymentOptionInfo(methodDr);

                // Update the properties
                modifyMethod.PaymentOptionDisplayName = modifyMethod.PaymentOptionDisplayName.ToUpper();

                // Update the payment method
                PaymentOptionInfoProvider.SetPaymentOptionInfo(modifyMethod);
            }

            return true;
        }

        return false;
    }
    /// <summary>
    /// Creates payment method. Called when the "Create method" button is pressed.
    /// </summary>
    private bool CreatePaymentMethod()
    {
        // Create new payment method object
        PaymentOptionInfo newMethod = new PaymentOptionInfo();

        // Set the properties
        newMethod.PaymentOptionDisplayName = "My new method";
        newMethod.PaymentOptionName = "MyNewMethod";
        newMethod.PaymentOptionSiteID = CMSContext.CurrentSiteID;
        newMethod.PaymentOptionEnabled = true;

        // Create the payment method
        PaymentOptionInfoProvider.SetPaymentOptionInfo(newMethod);

        return true;
    }
Example #16
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);
        }
    }
Example #17
0
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private string GetWhereCondition()
    {
        // Orders from current site
        string where = "OrderSiteID = " + CMSContext.CurrentSiteID;

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

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

        // Customer or company like filter
        if (!string.IsNullOrEmpty(CustomerOrCompany))
        {
            string safeQueryStr = SecurityHelper.GetSafeQueryString(CustomerOrCompany);
            where = SqlHelper.AddWhereCondition(where, "OrderCustomerID  IN (SELECT CustomerID FROM COM_Customer WHERE ((CustomerFirstName + ' ' + CustomerLastName + ' ' + CustomerFirstName) LIKE N'%" + safeQueryStr + "%') OR (CustomerCompany LIKE N'%" + safeQueryStr + "%'))");
        }

        // Filter for orders with note
        if (HasNote)
        {
            where = SqlHelper.AddWhereCondition(where, "(OrderNote != '') AND (OrderNote IS NOT NULL)");
        }

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

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

        // Payment status filter
        switch (PaymentStatus.ToLowerCSafe())
        {
        case PAY_STATUS_NOT_PAID:
            where = SqlHelper.AddWhereCondition(where, "(OrderIsPaid = 0) OR (OrderIsPaid IS NULL)");
            break;

        case PAY_STATUS_PAID:
            where = SqlHelper.AddWhereCondition(where, "OrderIsPaid = 1");
            break;
        }

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

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

        // Min price in main currency filter
        if (MinPriceInMainCurrency > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "OrderTotalPriceInMainCurrency >= " + MinPriceInMainCurrency);
        }

        // Max price in main currency filter
        if (MaxPriceInMainCurrency > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "OrderTotalPriceInMainCurrency <= " + MaxPriceInMainCurrency);
        }

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

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

        // Shipping country filter
        where = SqlHelper.AddWhereCondition(where, GetCountryWhereCondition());

        // Date filter
        where = SqlHelper.AddWhereCondition(where, GetDateWhereCondition());

        return(where);
    }
    /// <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);
        }
    }
    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>
 /// Load data of editing paymentOption.
 /// </summary>
 /// <param name="paymentOptionObj">PaymentOption object</param>
 protected void LoadData(PaymentOptionInfo paymentOptionObj)
 {
     txtPaymentOptionName.Text = paymentOptionObj.PaymentOptionName;
     chkPaymentOptionEnabled.Checked = paymentOptionObj.PaymentOptionEnabled;
     txtPaymentOptionDisplayName.Text = paymentOptionObj.PaymentOptionDisplayName;
     txtDescription.Text = paymentOptionObj.PaymentOptionDescription;
     txtGateUrl.Text = paymentOptionObj.PaymentOptionPaymentGateUrl;
     txtPaymentAssemblyName.Text = paymentOptionObj.PaymentOptionAssemblyName;
     txtPaymentClassName.Text = paymentOptionObj.PaymentOptionClassName;
     succeededElem.OrderStatusID = paymentOptionObj.PaymentOptionSucceededOrderStatusID;
     failedElem.OrderStatusID = paymentOptionObj.PaymentOptionFailedOrderStatusID;
     chkAllowIfNoShipping.Checked = paymentOptionObj.PaymentOptionAllowIfNoShipping;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Field validator error messages initialization
        rfvDisplayName.ErrorMessage = GetString("paymentoption_edit.errorEmptyDisplayName");
        rfvCodeName.ErrorMessage    = GetString("paymentoption_edit.errorEmptyCodeName");

        // Control initializations
        lblPaymentOptionName.Text        = GetString("PaymentOption_Edit.PaymentOptionNameLabel");
        lblPaymentOptionDisplayName.Text = GetString("PaymentOption_Edit.PaymentOptionDisplayNameLabel");
        // Gateway
        lblPaymentGateway.Text      = GetString("PaymentOption_Edit.GatewaySettings");
        lblGateUrl.Text             = GetString("PaymentOption_Edit.GateUrl");
        lblPaymentAssemblyName.Text = GetString("PaymentOption_Edit.PaymentAssemblyName");
        lblPaymentClassName.Text    = GetString("PaymentOption_Edit.PaymentClassName");
        // Statuses
        lblStatusFailed.Text  = GetString("PaymentOption_Edit.PaymentFailedStatus");
        lblStatusSucceed.Text = GetString("PaymentOption_Edit.PaymentSucceedStatus");

        btnOk.Text = GetString("General.OK");

        string currentPaymentOption = GetString("PaymentOption_Edit.NewItemCaption");

        // Get paymentOption id from querystring
        mPaymentOptionId = QueryHelper.GetInteger("paymentOptionId", 0);
        mSiteId          = ConfiguredSiteID;
        if (mPaymentOptionId > 0)
        {
            PaymentOptionInfo paymentOptionObj = PaymentOptionInfoProvider.GetPaymentOptionInfo(mPaymentOptionId);
            EditedObject = paymentOptionObj;

            if (paymentOptionObj != null)
            {
                currentPaymentOption = ResHelper.LocalizeString(paymentOptionObj.PaymentOptionDisplayName);
                mSiteId = paymentOptionObj.PaymentOptionSiteID;
                CheckEditedObjectSiteID(mSiteId);

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(paymentOptionObj);

                    // Show that the paymentOption was created or updated successfully
                    if (QueryHelper.GetString("saved", "") == "1")
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("General.ChangesSaved");
                    }
                }
            }

            this.CurrentMaster.Title.TitleText  = GetString("PaymentOption_Edit.HeaderCaption");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_PaymentOption/object.png");
        }
        else // Add new
        {
            this.CurrentMaster.Title.TitleText  = GetString("PaymentOption_New.HeaderCaption");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_PaymentOption/new.png");
        }

        this.succeededElem.SiteID = mSiteId;
        this.failedElem.SiteID    = mSiteId;

        // Initializes page title control
        string[,] pageTitleTabs = new string[2, 3];
        pageTitleTabs[0, 0]     = GetString("PaymentOption_Edit.ItemListLink");
        pageTitleTabs[0, 1]     = "~/CMSModules/Ecommerce/Pages/Tools/Configuration/PaymentOptions/PaymentOption_List.aspx?siteId=" + SiteID;
        pageTitleTabs[0, 2]     = "";
        pageTitleTabs[1, 0]     = FormatBreadcrumbObjectName(currentPaymentOption, mSiteId);
        pageTitleTabs[1, 1]     = "";
        pageTitleTabs[1, 2]     = "";
        this.CurrentMaster.Title.Breadcrumbs   = pageTitleTabs;
        this.CurrentMaster.Title.HelpTopicName = "newedit_payment_method";
        this.CurrentMaster.Title.HelpName      = "helpTopic";
    }
Example #22
0
        public void SetUp()
        {
            Fake <ShippingOptionInfo, ShippingOptionInfoProvider>();
            Fake <PaymentOptionInfo, PaymentOptionInfoProvider>();
            Fake <ShoppingCartInfo, ShoppingCartInfoProvider>();
            Fake <CountryInfo, CountryInfoProvider>();
            Fake <StateInfo, StateInfoProvider>();
            Fake <ShoppingCartCouponCodeInfo, ShoppingCartCouponCodeInfoProvider>().WithData();

            mShoppingCartInfo = new ShoppingCartInfo();


            var paymentMethodRepository  = Substitute.For <IPaymentMethodRepository>();
            var shippingOptionRepository = Substitute.For <IShippingOptionRepository>();
            var countryRepository        = Substitute.For <ICountryRepository>();
            var addressRepository        = Substitute.For <ICustomerAddressRepository>();
            var shoppingService          = Substitute.For <IShoppingService>();

            shoppingService.GetCurrentShoppingCart().Returns(mShoppingCartInfo);

            var shippingUSPS = new ShippingOptionInfo()
            {
                ShippingOptionID   = SHIPPING_OPTION_ID,
                ShippingOptionName = "ShippingUSPS"
            };

            var paymentCashOnDelivery = new PaymentOptionInfo
            {
                PaymentOptionID   = PAYMENT_METHOD_ID,
                PaymentOptionName = "CashOnDelivery"
            };

            var paymentNotApplicable = new PaymentOptionInfo
            {
                PaymentOptionID   = PAYMENT_METHOD_NOT_APPLICABLE_ID,
                PaymentOptionName = "PaymentNotApplicable"
            };

            // Override method IsPaymentOptionApplicableInternal to make payment method not applicable
            PaymentOptionInfoProvider.ProviderObject = new LocalPaymentOptionInfoProvider();

            var countryUSA = new CountryInfo
            {
                CountryName = "USA",
                CountryID   = COUNTRY_ID
            };

            var stateOregon = new StateInfo
            {
                StateName = "Oregon",
                StateID   = STATE_ID,
                CountryID = COUNTRY_ID
            };

            shippingOptionRepository.GetAllEnabled().Returns(new List <ShippingOptionInfo> {
                shippingUSPS
            });
            paymentMethodRepository.GetAll().Returns(new List <PaymentOptionInfo> {
                paymentCashOnDelivery, paymentNotApplicable
            });
            countryRepository.GetCountryStates(COUNTRY_ID).Returns(new List <StateInfo> {
                stateOregon
            });
            countryRepository.GetCountryStates(COUNTRY_WITHOUT_STATES_ID).Returns(new List <StateInfo> {
            });
            countryRepository.GetCountry(COUNTRY_ID).Returns(countryUSA);

            checkoutService = new CheckoutService(shoppingService, addressRepository, paymentMethodRepository, shippingOptionRepository, countryRepository);
        }
Example #23
0
 protected override bool IsPaymentOptionApplicableInternal(ShoppingCartInfo cart, PaymentOptionInfo paymentOption)
 {
     return(paymentOption.PaymentOptionID != PAYMENT_METHOD_NOT_APPLICABLE_ID);
 }
    /// <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);
        }
    }