2

I am trying to integrate a payment gateway with my headless magento 2 website.

So after the payment is processed/failed, the payment website makes a POST request to my API with x-www-form-encoded data, and it throws me the following error:

{"message":"Server cannot understand Content-Type HTTP header media type application/x-www-form-urlencoded","trace":null}

I've tried using:

   $request_body = file_get_contents('php://input');

    $data = json_decode($request_body,true);

But this doesn't work either.

Normal form works, sending these params as JSON works too, but they are sending the params in x-www-form-encoded format, and we can't change that.

Please help!

1

I just solved the same issue. You need to define a way for Magento to deserialize url-encoded requests. Take a look to this repository. In more specific how Deserializer and Decoder works.

repo : https://github.com/ICEPAY/Magento-2

What you need :

https://github.com/ICEPAY/Magento-2/tree/master/Model/PostbackNotification https://github.com/ICEPAY/Magento-2/tree/master/Webapi/Rest/Request/Deserializer https://github.com/ICEPAY/Magento-2/blob/master/etc/di.xml

| improve this answer | |

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.