4

I sent a “POST” request via external server for version magento-2.3

My internal Magento URL cannot verify and response is

"Invalid Form Key. Please refresh the page."

as a summary, i want to reach to magento-2.3 from outside and is there any valid way to do it ?

Additional information

I'm planning to build a payment module for my Magento store,
So my PSP working with this way;

When the customer clicks pay button of javascript embeded payment form, my PSP POSTing a value to my provided callbackUrl which is my controller inside of my module. (So I'm expecting a POST value to my controller.

It looks like this: https://mywebsite.com/mymodule/response).

When I'm trying to grab the value with this code piece
($postData = $this->getRequest()->getPostValue(); $postData['token']).

When I'm trying to do this, Magento is requesting a value named "form_key". In earlier version there was no usage like this. I'm suspecting there is a change in the Magento 2.3.0.

Can you help me ?

3
protected $request;
protected $formKey;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\Data\Form\FormKey $formKey,
    \Magento\Framework\App\Request\Http $request
) {
    $this->request = $request;
    $this->formKey = $formKey;
    $this->request->setParam('form_key', $this->formKey->getFormKey());
    parent::__construct(
        $context
    );
}

This is an fix, which send form_key in all the requests. The above code will work on Magento 2.3 and below Magento 2.3.

  • In which file do we need to add this code @Arjun Manoharan – Prachi Saxena Sep 9 at 6:04
  • Please tell me where to add this code @ArjunManoharan – Kowsigan Atsayam Sep 17 at 12:07
1

I am sure that problems came from session storage & cookie setting.

You should follow below:

DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain';

DELETE FROM core_config_data WHERE path='web/cookie/cookie_path';

Delete all directories from below folders:

/var/session
/var/cache
  • Thanks @hiren-kadivar unfortunately the problem continues. I updated my question. Can you look again? – mehmetselim Jan 31 at 13:08
1

found a solution. it works Magento 2.3 upgrade breaks HTTP POST requests to custom module endpoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.