Payment method without additional info

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
In my new shop, pick up in store and pay in store are the only options. Is there a payment method without any additional info (whick means an extra click for the customer)? If I don't fill anythin in in the Configuration box in, let's say, Pay in Store, there still will appear an extra page to get through. How do I get rid of it?
13 years ago
An easy trick without having to change a lot is to put a redirect to the next page in the control that is shown after selection of the payment type.
The control that is used per payment method is located in:
NopcommerceStore\Templates\Payment\[YourPaymentMethod]PaymentModule.ascx.
13 years ago
That sounds like a good idea... I'm not that good att coding though, so I would appreciate a little help on the way :)

/Johanna
13 years ago
Do you still need help with this?
I have some time to look into this this week.
12 years ago
Does anyone have a way to remove the "Select Payment Method" step. I only have one payment option and I want to go straight from Shipping to Payment Info. There is no point in the "Select Payment Method" with a Credit card only option it just adds an extra step and complexity.

Also, unless I'm reading it wrong modifying the PaymentModule.ascx file for the payment processor that you're using would not accomplish what I need as that step is after the one I need to skip?
12 years ago
Allshookup wrote:
Does anyone have a way to remove the "Select Payment Method" step. I only have one payment option and I want to go straight from Shipping to Payment Info. There is no point in the "Select Payment Method" with a Credit card only option it just adds an extra step and complexity.

Also, unless I'm reading it wrong modifying the PaymentModule.ascx file for the payment processor that you're using would not accomplish what I need as that step is after the one I need to skip?


Same here,
Even I am facing the same issue.
Can someone guide us as to how to remove that extra step of Payment Method as it is not valid
want the Payment info to be directly populated after billing address instead of Payment Method.

Please do reply asap ..

Thanks in advance
12 years ago
I'm pretty sure it has something to do with this file /Modules/CheckoutPaymentMethod.ascx.cs I just have no coding experience.



using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Payment;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Shipping;
using NopSolutions.NopCommerce.BusinessLogic.Tax;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.BusinessLogic.Infrastructure;


namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class CheckoutPaymentMethodControl: BaseNopFrontendUserControl
    {
        protected CheckoutStepChangedEventHandler handler;
        protected ShoppingCart cart = null;

        protected string FormatPaymentMethodInfo(PaymentMethod paymentMethod)
        {
            decimal paymentMethodAdditionalFee = this.PaymentService.GetAdditionalHandlingFee(paymentMethod.PaymentMethodId);
            decimal rateBase = this.TaxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, NopContext.Current.User);
            decimal rate = this.CurrencyService.ConvertCurrency(rateBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            if (rate > decimal.Zero)
            {
                string rateStr = PriceHelper.FormatPaymentMethodAdditionalFee(rate, true);
                return string.Format("({0})", rateStr);
            }
            else
            {
                return string.Empty;
            }
        }

        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //reward points
                ApplyRewardPoints();

                //payment methods
                int paymentMethodId = this.SelectedPaymentMethodId;
                if (paymentMethodId > 0)
                {
                    var paymentMethod = this.PaymentService.GetPaymentMethodById(paymentMethodId);
                    if (paymentMethod != null && paymentMethod.IsActive)
                    {
                        //save selected payment methods
                        NopContext.Current.User.LastPaymentMethodId = paymentMethodId;
                        this.CustomerService.UpdateCustomer(NopContext.Current.User);
                        var args1 = new CheckoutStepEventArgs() { PaymentMethodSelected = true };
                        OnCheckoutStepChanged(args1);
                        if (!this.OnePageCheckout)
                            Response.Redirect("~/checkoutpaymentinfo.aspx");
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((NopContext.Current.User == null) || (NopContext.Current.User.IsGuest && !this.CustomerService.AnonymousCheckoutAllowed))
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }

            if (this.Cart.Count == 0)
                Response.Redirect(SEOHelper.GetShoppingCartUrl());
        }

        protected int SelectedPaymentMethodId
        {
            get
            {
                int selectedPaymentMethodId = 0;
                foreach (DataListItem item in this.dlPaymentMethod.Items)
                {
                    RadioButton rdPaymentMethod = (RadioButton)item.FindControl("rdPaymentMethod");
                    if (rdPaymentMethod.Checked)
                    {
                        selectedPaymentMethodId = Convert.ToInt32(this.dlPaymentMethod.DataKeys[item.ItemIndex].ToString());
                        break;
                    }
                }
                return selectedPaymentMethodId;
            }
            set
            {
                foreach (DataListItem item in this.dlPaymentMethod.Items)
                {
                    RadioButton rdPaymentMethod = (RadioButton) item.FindControl("rdPaymentMethod");

                    rdPaymentMethod.Checked = false;
                    int paymentMethodId = 0;
                    if (int.TryParse(this.dlPaymentMethod.DataKeys[item.ItemIndex].ToString(), out paymentMethodId))
                    {
                        if (paymentMethodId == value)
                        {
                            rdPaymentMethod.Checked = true;
                            break;
                        }
                    }
                }
            }
        }

        protected virtual void OnCheckoutStepChanged(CheckoutStepEventArgs e)
        {
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public bool IsPaymentWorkflowRequired()
        {
            bool result = true;

            //check whether order total equals zero
            if (NopContext.Current.User != null)
            {
                decimal? shoppingCartTotalBase = this.ShoppingCartService.GetShoppingCartTotal(this.Cart,
                NopContext.Current.User.LastPaymentMethodId, NopContext.Current.User);

                if (shoppingCartTotalBase.HasValue && shoppingCartTotalBase.Value == decimal.Zero)
                {
                    result = false;
                }
            }
            return result;
        }

        public void ApplyRewardPoints()
        {
            //reward points
            if (NopContext.Current.User != null)
            {
                NopContext.Current.User.UseRewardPointsDuringCheckout = cbUseRewardPoints.Checked;
            }

            //Check whether payment workflow is required
            bool isPaymentWorkflowRequired = IsPaymentWorkflowRequired();
            if (!isPaymentWorkflowRequired)
            {
                //save selected payment methods
                NopContext.Current.User.LastPaymentMethodId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);

                var args1 = new CheckoutStepEventArgs() { PaymentMethodSelected = true };
                OnCheckoutStepChanged(args1);
                if (!this.OnePageCheckout)
                    Response.Redirect("~/checkoutpaymentinfo.aspx");
            }
        }

        public void BindData()
        {
            //Check whether payment workflow is required
            bool isPaymentWorkflowRequired = IsPaymentWorkflowRequired();
            if (!isPaymentWorkflowRequired)
            {
                //save selected payment methods
                NopContext.Current.User.LastPaymentMethodId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);
                
                var args1 = new CheckoutStepEventArgs() { PaymentMethodSelected = true };
                OnCheckoutStepChanged(args1);
                if (!this.OnePageCheckout)
                    Response.Redirect("~/checkoutpaymentinfo.aspx");
            }

            //reward points
            if (this.OrderService.RewardPointsEnabled && !this.Cart.IsRecurring)
            {
                int rewardPointsBalance = NopContext.Current.User.RewardPointsBalance;
                decimal rewardPointsAmountBase = this.OrderService.ConvertRewardPointsToAmount(rewardPointsBalance);
                decimal rewardPointsAmount = this.CurrencyService.ConvertCurrency(rewardPointsAmountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                if (rewardPointsAmount > decimal.Zero)
                {
                    string rewardPointsAmountStr = PriceHelper.FormatPrice(rewardPointsAmount, true, false);
                    cbUseRewardPoints.Text = GetLocaleResourceString("Checkout.UseRewardPoints", rewardPointsBalance, rewardPointsAmountStr);
                    pnlRewardPoints.Visible = true;
                }
                else
                {
                    pnlRewardPoints.Visible = false;
                }
            }
            else
            {
                pnlRewardPoints.Visible = false;
            }

            //payment methods
            int? filterByCountryId = null;
            if (NopContext.Current.User.BillingAddress != null && NopContext.Current.User.BillingAddress.Country != null)
            {
                filterByCountryId = NopContext.Current.User.BillingAddress.CountryId;
            }

            bool hasButtonMethods = false;
            var boundPaymentMethods = new List<PaymentMethod>();
            var paymentMethods = this.PaymentService.GetAllPaymentMethods(filterByCountryId);
            foreach (var pm in paymentMethods)
            {
                switch (pm.PaymentMethodType)
                {
                    case PaymentMethodTypeEnum.Unknown:
                    case PaymentMethodTypeEnum.Standard:
                        {
                            if (!Cart.IsRecurring || this.PaymentService.SupportRecurringPayments(pm.PaymentMethodId) != RecurringPaymentTypeEnum.NotSupported)
                                boundPaymentMethods.Add(pm);
                        }
                        break;
                    case PaymentMethodTypeEnum.Button:
                        {
                            //PayPal Express is placed here as button
                            if (pm.SystemKeyword == "PayPalExpress")
                            {
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

            //bind PayPal Express button
            btnPaypalExpressButton.BindData();
            if (btnPaypalExpressButton.Visible)
                hasButtonMethods = true;

            if (boundPaymentMethods.Count == 0)
            {
                if (hasButtonMethods)
                {
                    phSelectPaymentMethod.Visible = false;
                    pnlPaymentMethodsError.Visible = false;

                    //no reward points in this case
                    pnlRewardPoints.Visible = false;
                }
                else
                {
                    phSelectPaymentMethod.Visible = false;
                    pnlPaymentMethodsError.Visible = true;                    
                    lPaymentMethodsError.Text = GetLocaleResourceString("Checkout.NoPaymentMethods");

                    //no reward points in this case
                    pnlRewardPoints.Visible = false;
                }
            }
            else if (boundPaymentMethods.Count == 1)
            {
                phSelectPaymentMethod.Visible = true;
                pnlPaymentMethodsError.Visible = false;
                dlPaymentMethod.DataSource = boundPaymentMethods;
                dlPaymentMethod.DataBind();

                //select a default payment method
                if (dlPaymentMethod.Items.Count > 0)
                {
                    var tmp1 = dlPaymentMethod.Items[0];
                    var rdPaymentMethod = tmp1.FindControl("rdPaymentMethod") as RadioButton;
                    if (rdPaymentMethod != null)
                    {
                        rdPaymentMethod.Checked = true;
                    }
                    //or you can select it and go to the next step of checkout
                    //but it this case a customer will not be able apply a reward point a select a "button" payment metho
                }
            }
            else
            {
                phSelectPaymentMethod.Visible = true;
                pnlPaymentMethodsError.Visible = false;
                dlPaymentMethod.DataSource = boundPaymentMethods;
                dlPaymentMethod.DataBind();
                
                //select a default payment method
                if (dlPaymentMethod.Items.Count > 0)
                {
                    if (NopContext.Current.User != null &&
                        NopContext.Current.User.LastPaymentMethod != null)
                    {
                        //already selected payment method
                        this.SelectedPaymentMethodId = NopContext.Current.User.LastPaymentMethod.PaymentMethodId;
                    }
                    else
                    {
                        //otherwise, the first payment method
                        var tmp1 = dlPaymentMethod.Items[0];
                        var rdPaymentMethod = tmp1.FindControl("rdPaymentMethod") as RadioButton;
                        if (rdPaymentMethod != null)
                        {
                            rdPaymentMethod.Checked = true;
                        }
                    }
                }
            }
        }

        public event CheckoutStepChangedEventHandler CheckoutStepChanged
        {
            add
            {
                handler += value;
            }
            remove
            {
                handler -= value;
            }
        }

        public ShoppingCart Cart
        {
            get
            {
                if (cart == null)
                {
                    cart = this.ShoppingCartService.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
                }
                return cart;
            }
        }

        public bool OnePageCheckout
        {
            get
            {
                if (ViewState["OnePageCheckout"] != null)
                    return (bool)ViewState["OnePageCheckout"];
                return false;
            }
            set
            {
                ViewState["OnePageCheckout"] = value;
            }
        }
    }
}

12 years ago
I would also like some help with this.  Using version 1.90.
12 years ago
Hey guys,

Has anyone sorted this yet?

I'm working on this too. I only use one payment method so in an attempt to sort this step I have opened the .cs codepage behind and copied the code from the section 'btnNextStep_Click' and pasted it into the 'Page_Load' section, my logic is that the action we want to confirm is what happens on that button press, which checks that a payment method is selected and goes the the next page.
I also tried setting the radio button to automatically be checked so that when the page loads it already has the same content and settings that it would had it loaded and been manually selected by the user.

So far no luck but i'm a vb programer not a c# one so its a slow business. I'll post my findings, if I actually do manage to suss it out!
12 years ago
BigBadAds wrote:
Hey guys,

Has anyone sorted this yet?

I'm working on this too. I only use one payment method so in an attempt to sort this step I have opened the .cs codepage behind and copied the code from the section 'btnNextStep_Click' and pasted it into the 'Page_Load' section, my logic is that the action we want to confirm is what happens on that button press, which checks that a payment method is selected and goes the the next page.
I also tried setting the radio button to automatically be checked so that when the page loads it already has the same content and settings that it would had it loaded and been manually selected by the user.

So far no luck but i'm a vb programer not a c# one so its a slow business. I'll post my findings, if I actually do manage to suss it out!


Currently working, so I won't be able to tell you exactly what to do but I can give you the steps to resolve this.

Steps:

- On the previous page, you can set it so you get redirected to the page you want it to go to.

- On each checkout step, there are steps you need to set as true. Using the code inside btnNextStep_Click is correct. Putting it on the page load is incorrect. You should be adding the code to the previous page's btnNextStep_Click code and remove the redirect that points it to the payment method page.


if (Page.IsValid)
            {
                //reward points
                ApplyRewardPoints();

                //payment methods
                int paymentMethodId = this.SelectedPaymentMethodId; //This Code should be changed to auto select the Payment Method ID. It's a number value, so if you're hard coding, you can just put the ID number into it.For example: int paymentMethodId = 1
                if (paymentMethodId > 0)
                {
                    var paymentMethod = this.PaymentService.GetPaymentMethodById(paymentMethodId);
                    if (paymentMethod != null && paymentMethod.IsActive)
                    {
                        //save selected payment methods
                        NopContext.Current.User.LastPaymentMethodId = paymentMethodId;
                        this.CustomerService.UpdateCustomer(NopContext.Current.User);
                        var args1 = new CheckoutStepEventArgs() { PaymentMethodSelected = true }; // change args1 to another value, you can't use args1 twice. since you're adding the code to the previous page.
                        OnCheckoutStepChanged(args1); // change to the value that was changed.
                        if (!this.OnePageCheckout)
                            Response.Redirect("~/checkoutpaymentinfo.aspx");
                    }
                }
            }


- Copy paste the ApplyRewardPoints() function from the payment method page to the page you're redirect from.

- Make sure you comment out previous code so in case you do have additional payment methods, you can revert back to it.

Hope it makes sense.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.