Suggestion: Payment Method Restrictions on Customer Roles

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi,

Would be a great feature to be able to restrict Payment Method to one or many Customer Roles.
Eg. Only your "trusted" customers can order with Purchase Order, others have to pay with Credit Card.


--
Kenny
10 years ago
Hi Kenny,

Thanks for suggestion. Please vote for this work item here
10 years ago
I agree :-)
9 years ago
Did this ever get implemented?  Seems like a must have for anyone wanting use the PO feature as well as allowing retails customers to order.
9 years ago
[email protected] wrote:
Did this ever get implemented?  Seems like a must have for anyone wanting use the PO feature as well as allowing retails customers to order.

Not yet. Payment Director plug in can do the job.
9 years ago
You can see some Payment Director examples in this blog post
8 years ago
This is an absolute must have for any e-commerce website and why nop has not done yet this boggles the mind. We've been dealing with this since nop 1.9.

If anyone is still looking we implemented this code into Opc.PaymentMethods.cshtml. Tests perfect for nop 3.1 to 3.6 and possibly earlier versions. Haven't tested on 3.7 yet.

Add a Customer Role named Corporate. Add all the customers you want to use a purchase order to the Corporate role.

Then replace all code in Opc.PaymentMethods.cshtml with:


@model CheckoutPaymentMethodModel
@using Nop.Web.Models.Checkout;
@using Nop.Core.Domain.Customers;

@{
  List<CustomerRole> crCustRole = new List<CustomerRole>();
  List<string> strCustRole = new List<string>();
  crCustRole.AddRange(WorkContext.CurrentCustomer.CustomerRoles);
  int intCRCount = crCustRole.Count;
  bool isCorp = false;
  for (int iCRIndex = 0; iCRIndex < intCRCount; iCRIndex++)
  {
    strCustRole.Add(crCustRole[iCRIndex].Name);
    if (crCustRole[iCRIndex].Name == "Corporate")
    {
      isCorp = true;
    }
  }

}

<div class="checkout-data">
    @Html.Widget("op_checkout_payment_method_top")
    <div class="section payment-method">
        @if (Model.DisplayRewardPoints && Model.PaymentMethods.Count > 0)
        {
            <div class="use-reward-points">
                @Html.EditorFor(model => model.UseRewardPoints)
                @string.Format(T("Checkout.UseRewardPoints").Text, Model.RewardPointsBalance, Model.RewardPointsAmount)
            </div>
        }
        @if (Model.PaymentMethods.Count > 0)
        {
          <ul class="method-list">
            @for (int i = 0; i < Model.PaymentMethods.Count; i++)
            {
              var paymentMethod = Model.PaymentMethods[i];
              var paymentMethodName = paymentMethod.Name;
              if (!String.IsNullOrEmpty(paymentMethod.Fee))
              {
                paymentMethodName = T("Checkout.SelectPaymentMethod.MethodAndFee", paymentMethodName, paymentMethod.Fee).Text;
              }
              <li>
                <div class="method-name">
                  @if (!isCorp && paymentMethod.Name == "Purchase Order")
                  {
                  }
                  else
                  {
                    if (!String.IsNullOrEmpty(paymentMethod.LogoUrl))
                    {
                      <div class="payment-logo">
                        <label for="paymentmethod_@(i)">
                          <img src="@paymentMethod.LogoUrl" alt="@paymentMethodName" />
                        </label>
                      </div>
                    }
                    <div class="payment-details">
                      <input id="paymentmethod_@(i)" type="radio" name="paymentmethod" value="@(paymentMethod.PaymentMethodSystemName)" checked="@paymentMethod.Selected" />
                      <label for="paymentmethod_@(i)">@paymentMethodName</label>
                    </div>
                  }
                </div>
              </li>
            }
          </ul>
        }
        else
        {
            <div class="message-error">
                @T("Checkout.NoPaymentMethods")
            </div>
        }
    </div>
    @Html.Widget("op_checkout_payment_method_bottom")
</div>


That's it. Done. Haven't checked to see if implemented in 3.7 but if it hasn't it really needs to get done.
8 years ago
I agree that it would be nice if nop added the option to restrict payment methods by role but if you're going to customise code to achieve it, it's a one liner to do it in the purchase order plugin (or any other payment method plugin that has source code available) rather than changing core code. See this post for details: https://www.nopcommerce.com/boards/t/38073/checkout-without-payment.aspx#153723
8 years ago
It's probably a one-liner to do in .cshtml file too :)
...
var paymentMethodName = paymentMethod.Name;
@if (paymentMethod.Name == "Purchase Order" && !WorkContext.CurrentCustomer.CustomerRoles.Any(r => r.Name == "Corporate")) {continue;}




(not tested )
8 years ago
"var paymentMethodName = paymentMethod.Name;"

Thanks. Agreed there are probably simpler ways but the code was written back when we we're using 1.9. I'll check and test but you would need to loop thru the available 'paymentMethod.Names'. So probably not quite a one liner. The line above would not find 'Corporate' unless you looped through and broke when 'Corporate' was found.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.