Jump to content

How to return an HTTP response in a controller?


Recommended Posts

Hello, I'm creating a payment module with Lyra marketplace API and I'm stuck with something probably really simple..

After payment process, the API send a webhook on our server and I'm actually on it. I have created a Front controller extending ModuleFrontController and I'm using the postProcess() method because they send us an order uuid. The problem is, I can't find how to return a correct HTTP response and not a string or template... 

My actual code is

public function postProcess()
{
  $response = new Response();
  $response->setContent(json_encode(['data' => '123']));
  $response->headers->set('Content-Type', 'application/json');

  return $response;
}

but unfortunately it return a 500 error with the message : "/index.php?fc=module&module=lyramkp&controller=webhook - Uncaught  --> Smarty: 0():Missing '$template' parameter "

I would also like to add an allow origins header to be sure no one else than Lyra can call this URL. But actually, what I can do is returning a die() or something like that...

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...