1

I've got a webhook which sends a XML and mail after a order is paid succesfully. The payment provider (Mollie) needs to get a 200 OK response otherwise it keeps calling my webhook, which sends the XML and mail continuesly. Anyone knows what I'm doing wrong here..?

    if($payment->status == 'paid') {
            // Create XML file
            include_once("create-xml.php");
            file_put_contents("order-" . $orders[0]['id'] . ".xml",$xml);

            // Send XML file
            include_once("send-xml.php");

            // Delete XML file
            unlink("order-" . $orders[0]['id'] . ".xml");

            // Send e-mail to customer
            include_once("send-mail.php");


            header(':', true, 200);
            header('X-PHP-Response-Code: 200', true, 200);
            return;

        }
Ptrckk
  • 56
  • 5
  • 1
    You don't need curl if you're not actually using it to initiate contact with another site. Look into [`http_response_code`](https://www.php.net/manual/en/function.http-response-code.php) – aynber Dec 23 '19 at 13:30
  • I've looked at that question before, but can't seem to get that working aswell. I've updated my code, with the return i've had before. – Ptrckk Dec 23 '19 at 13:33
  • simply `exit( http_response_code( 200 ) );` at the end ought to suffice – Professor Abronsius Dec 23 '19 at 13:36
  • i guess 200 is default code response and you don't event need so set it. you may have other error – Omar Ghorbel Dec 23 '19 at 14:31
  • I've had a `exit();` at the end of my "send-mail.php", which returned a 500 error before it even reached the 200 response. After deleting the `exit();` and putting `exit( http_response_code( 200 ) );` at the end of my script, it works. – Ptrckk Dec 24 '19 at 09:57

0 Answers0