Plugin route not working when using HttpPost attribute

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 3 años
Hi
I have a problem with the callback Action method in the payment plugin in NopCommerce 4.0 (Bank redirect User with post method to call back URL and post some values). when I use [HttpPost] routing not found my action and when to remove that, my action is called but form values are null.
I test some attributes but routing is not found my action yet.
       //[HttpPost]
       //[AutoValidateAntiforgeryToken]
       //[AdminAntiForgery(true)]
        public ActionResult CallBack(IFormCollection form)
        {....
Hace 3 años
My route Provider class:

  public class PaymentPluginRoutProvider : IRouteProvider
  {
    public int Priority => -1;

    public void RegisterRoutes(IRouteBuilder routeBuilder)
    {
      routeBuilder.MapRoute("Plugin.Payments.PaymentPlugin.CallBack", "Plugins/PaymentPlugin/CallBack", new { controller = "PaymentPlugin", action = "CallBack" });
      
    }
  }

Controller and action code:

public class PaymentPluginController : BasePaymentController
{
       [HttpPost]
        public IActionResult CancelOrder()
        {
                  //some code .....
         }
}

this form on the bank's site:

<form method="post" name="returnForm" action="http://www.mydomain.com/Plugins/PaymentPlugin/CallBack">
        <input type="hidden" id="RefId" name="RefId" value="EA877FCE3FCEE510">
        <input type="hidden" id="ResCode" name="ResCode">
        <input type="hidden" id="SaleOrderId" name="SaleOrderId" value="93">
    </form>

I'm very confused and I think everything should work fine but it does not and I get a page not found error.
Hace 3 años
I dont know about recieving the form parameter
In the first instance you should be able to test the controller action first them modify

// My route
            endpointRouteBuilder.MapControllerRoute("Test.PaymentWebhook", "Test/Webhook/{orderId:regex(\\d*)}",
                new { controller = "PaymentTest", action = "TestWebhook" });

// My controller and function
namespace Nop.Plugin.Payments.Test.Controllers
{
    [AutoValidateAntiforgeryToken]
    public class PaymentTestController : BasePaymentController
    {
        [IgnoreAntiforgeryToken]
        public virtual IActionResult TestWebhook(int? orderId, string id)
        {
                // do some stuff
        }
}

// Test it
https://yourwebsite.com/test/webhook/13172
Hace 3 años
Thank you very much Yidna.
I finally realized this insane problem. The return address from the bank started with HTTP, whereas this address should have started with HTTPS. In this case, the posted information was lost due to the change of address.
I hope this helps others.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.