Get error on checkout page in Payment Method Section for my Payment Plugin "The method or operation is not implemented."

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 9 ans
Hi

I have problem with my payment plugin. I create my plugin from paypal standard but get error on checkout page when go from shipment section to payment section.



I clear asp.net temp folder and change global.asax file and restart app but still get this error. :(
Il y a 9 ans
your payment plugin is hosted payment flow or normal flow ??

i think you have set the PaymentMethodType.Standard and you did implement ProcessPayment() method PaymentProcesses.cs file of payment plugin

so that's why it throwing exceptions
Il y a 9 ans
vipul.dumaniya wrote:
your payment plugin is hosted payment flow or normal flow ??

i think you have set the PaymentMethodType.Standard and you did implement ProcessPayment() method PaymentProcesses.cs file of payment plugin

so that's why it throwing exceptions


thanks for answer

my code here:


using Nop.Core;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.Shipping;
using Nop.Core.Plugins;
using Nop.Services.Configuration;
using Nop.Services.Directory;
using Nop.Services.Localization;
using Nop.Services.Orders;
using Nop.Services.Payments;
using Nop.Services.Tax;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Nop.Plugin.Payments.SamanPay
{
    public class SamanPayProcessor : BasePlugin, IPaymentMethod
    {
        #region Fields

        private readonly SamanPaySettings _samanPayPluginSettings;
        private readonly ISettingService _settingService;
        private readonly IOrderTotalCalculationService _orderTotalCalculationService;
        private readonly CurrencySettings _currencySettings;
        private readonly IWebHelper _webHelper;
        private readonly ICheckoutAttributeParser _checkoutAttributeParser;
        private readonly ITaxService _taxService;
        private readonly HttpContextBase _httpContext;
        private readonly ICurrencyService _currencyService;


        #endregion

        #region Ctor

        public SamanPayProcessor(SamanPaySettings SamanPayPluginSettings,
            ISettingService settingService, ICurrencyService currencyService,
            CurrencySettings currencySettings, IWebHelper webHelper,
            ICheckoutAttributeParser checkoutAttributeParser, ITaxService taxService,
            IOrderTotalCalculationService orderTotalCalculationService, HttpContextBase httpContext)
        {
            this._samanPayPluginSettings = SamanPayPluginSettings;
            this._settingService = settingService;
            this._currencyService = currencyService;
            this._currencySettings = currencySettings;
            this._webHelper = webHelper;
            this._checkoutAttributeParser = checkoutAttributeParser;
            this._taxService = taxService;
            this._orderTotalCalculationService = orderTotalCalculationService;
            this._httpContext = httpContext;
        }

        #endregion

        #region Utilities

        /// <summary>
        /// Gets Paypal URL
        /// </summary>
        /// <returns></returns>
        private string GetSamanPayUrl()
        {
            return "https://sep.shaparak.ir/Payment.aspx";
        }

        #endregion

        #region Methods

        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();
            result.NewPaymentStatus = PaymentStatus.Pending;
            return result;
        }

        /// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var builder = new StringBuilder();

            builder.Append(GetSamanPayUrl());

            var orderTotal = Math.Round(postProcessPaymentRequest.Order.OrderTotal, 2);
            builder.AppendFormat("&Amount={0}", orderTotal.ToString("0.00", CultureInfo.InvariantCulture));

            builder.AppendFormat("&MID={0}", _samanPayPluginSettings.MerchantID);

            builder.AppendFormat("&ResNum={0}", postProcessPaymentRequest.Order.Id);

            string returnUrl = _webHelper.GetStoreLocation(false) + "Plugins/SamanPay/ResultHandler";
            builder.AppendFormat("&RedirectURL={0}", HttpUtility.UrlEncode(returnUrl));

            _httpContext.Response.Redirect(builder.ToString());
        }

        /// <summary>
        /// Returns a value indicating whether payment method should be hidden during checkout
        /// </summary>
        /// <param name="cart">Shoping cart</param>
        /// <returns>true - hide; false - display.</returns>
        public bool HidePaymentMethod(IList<ShoppingCartItem> cart)
        {
            //you can put any logic here
            //for example, hide this payment method if all products in the cart are downloadable
            //or hide this payment method if current customer is from certain country
            return false;
        }

        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();
            result.AddError("Capture method not supported");
            return result;
        }

        /// <summary>
        /// Refunds a payment
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result = new RefundPaymentResult();
            result.AddError("Refund method not supported");
            return result;
        }

        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();
            result.AddError("Void method not supported");
            return result;
        }

        /// <summary>
        /// Process recurring payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();
            result.AddError("Recurring payment not supported");
            return result;
        }

        /// <summary>
        /// Cancels a recurring payment
        /// </summary>
        /// <param name="cancelPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public CancelRecurringPaymentResult CancelRecurringPayment(CancelRecurringPaymentRequest cancelPaymentRequest)
        {
            var result = new CancelRecurringPaymentResult();
            result.AddError("Recurring payment not supported");
            return result;
        }

        /// <summary>
        /// Gets a value indicating whether customers can complete a payment after order is placed but not completed (for redirection payment methods)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>Result</returns>
        public bool CanRePostProcessPayment(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            //let's ensure that at least 5 seconds passed after order is placed
            //P.S. there's no any particular reason for that. we just do it
            if ((DateTime.UtcNow - order.CreatedOnUtc).TotalSeconds < 5)
                return false;

            return true;
        }

        /// <summary>
        /// Gets a route for provider configuration
        /// </summary>
        /// <param name="actionName">Action name</param>
        /// <param name="controllerName">Controller name</param>
        /// <param name="routeValues">Route values</param>
        public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "Configure";
            controllerName = "SamanPay";
            routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.Payments.SamanPay.Controllers" }, { "area", null } };
        }

        /// <summary>
        /// Gets a route for payment info
        /// </summary>
        /// <param name="actionName">Action name</param>
        /// <param name="controllerName">Controller name</param>
        /// <param name="routeValues">Route values</param>
        public void GetPaymentInfoRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "PaymentInfo";
            controllerName = "SamanPay";
            routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.Payments.SamanPay.Controllers" }, { "area", null } };
        }

        public Type GetControllerType()
        {
            return typeof(SamanPay.Controllers.SamanPayController);
        }

        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            throw new NotImplementedException();
        }

        public override void Install()
        {
            //settings
            var settings = new SamanPaySettings
            {
                MerchantID = 0,                
            };
            _settingService.SaveSetting(settings);

            //locales

            this.AddOrUpdatePluginLocaleResource("Plugins.Payments.SamanPay.Fields.RedirectionTip", "You will be redirected to SamanPay site to complete the order.");

            this.AddOrUpdatePluginLocaleResource("Plugins.Payments.SamanPay.Fields.MerchantID", "Merchant ID");
            this.AddOrUpdatePluginLocaleResource("Plugins.Payments.SamanPay.Fields.MerchantID.Hint", "Merchant ID");

            base.Install();
        }

        public override void Uninstall()
        {
            //settings
            _settingService.DeleteSetting<SamanPaySettings>();

            //locales

            this.DeletePluginLocaleResource("Plugins.Payments.SamanPay.Fields.RedirectionTip");

            this.DeletePluginLocaleResource("Plugins.Payments.SamanPay.Fields.MerchantID");
            this.DeletePluginLocaleResource("Plugins.Payments.SamanPay.Fields.MerchantID.Hint");

        
            base.Uninstall();
        }



        #endregion

        #region Properies

        /// <summary>
        /// Gets a value indicating whether capture is supported
        /// </summary>
        public bool SupportCapture
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Gets a value indicating whether partial refund is supported
        /// </summary>
        public bool SupportPartiallyRefund
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Gets a value indicating whether refund is supported
        /// </summary>
        public bool SupportRefund
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Gets a value indicating whether void is supported
        /// </summary>
        public bool SupportVoid
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Gets a recurring payment type of payment method
        /// </summary>
        public RecurringPaymentType RecurringPaymentType
        {
            get
            {
                return RecurringPaymentType.NotSupported;
            }
        }

        /// <summary>
        /// Gets a payment method type
        /// </summary>
        public PaymentMethodType PaymentMethodType
        {
            get
            {
                return PaymentMethodType.Redirection;
            }
        }

        /// <summary>
        /// Gets a value indicating whether we should display a payment information page for this plugin
        /// </summary>
        public bool SkipPaymentInfo
        {
            get
            {
                return false;
            }
        }

        #endregion

    }
}


Il y a 9 ans
the code seems to be ok.

can you check your log may be it has detail error of which method is not implemented etc ??

also which version are you using ??
Il y a 9 ans
vipul.dumaniya wrote:
the code seems to be ok.

can you check your log may be it has detail error of which method is not implemented etc ??

also which version are you using ??


I use version 3.5

the log:



System.NotImplementedException: The method or operation is not implemented. at Nop.Plugin.Payments.SamanPay.SamanPayProcessor.GetAdditionalHandlingFee(IList`1 cart) at Nop.Services.Payments.PaymentService.GetAdditionalHandlingFee(IList`1 cart, String paymentMethodSystemName) at Nop.Web.Controllers.CheckoutController.PreparePaymentMethodModel(IList`1 cart, Int32 filterByCountryId) at Nop.Web.Controllers.CheckoutController.OpcLoadStepAfterShippingMethod(List`1 cart) at Nop.Web.Controllers.CheckoutController.OpcSaveShippingMethod(FormCollection form)

Il y a 9 ans
I have this method




        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            throw new NotImplementedException();
        }

Il y a 9 ans
you have to add GetAdditionalHandlingFee() method on your payment processer same like other payment method.

you can check the IPaymentMethod interface and you have to implement all those method in your payment processer
Il y a 9 ans
EbiPenMan wrote:
I have this method




        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            throw new NotImplementedException();
        }




if you don't have any additional handling fee then you can use below code


        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            return decimal.zero;
        }

Il y a 9 ans
vipul.dumaniya wrote:
I have this method




        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            throw new NotImplementedException();
        }




if you don't have any additional handling fee then you can use below code


        public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
        {
            return decimal.zero;
        }



vipul.dumaniya Thank you very much for your help

My problem was resolved. :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.