I would like to implement a shippo webhook in order to know the delivery status of my shipments, their documentation is a little unclear... I don't know what information will be passed to my script
I have setup a test URL and a live one and have added those to my account, in API -> Webhooks.
Whenever my script is requested either via the live or test URLs I get empty arrays, no data. Please help me figure this out. Anyone from Shippo??
Here is what I have so far:
<?php
namespace MW\PublicBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ShippoController extends Controller
{
/**
* @Route("/shippo/", name="shippo_web_hook")
* @Method("GET|POST")
*/
public function webHookAction(Request $request)
{
if ($request->getMethod() == 'POST'){
$post = $request->request->all();
} elseif ($request->getMethod() == 'GET'){
$post = $request->query->all();
}
file_put_contents(__DIR__ . '/shippo.txt', print_r($post,true));
$mailer = $this->get('swiftmailer.mailer.transactional');
$messageObject = \Swift_Message::newInstance()
->setSubject('Shippo Webhook Posted DATA')
->setFrom('emai@example.com')
->setTo('email@example.com')
->setBody(print_r($post,true) . "\n" . print_r($_REQUEST,true) . "\n" . print_r($_POST,true));
try {
$mailer->send($messageObject);
} catch (\Exception $e){
}
return new Response('OK');
}
}
As you can see I should be able to catch some incoming data but I get nothing but empty arrays..