Using Authorize.net sandbox Web UI, set up an webhook to call Symfony controller by URL. By default Auth.net sends POST request with data in JSON format. Verified at Requestb.in that the data is sent:
RAW BODY:
{"notificationId":"f803dsa2c9-32fa-4f44-8dsd-b9b2324lf9a7",
"eventType":"net.authorize.payment.authcapture.created",
"eventDate":"2017-09-19T09:29:46.9455538Z",
"webhookId":"f2a105zd-drf4-491v-ab31-9cdd4a8ad04a",
"payload":{"responseCode":21,
"authCode":"111",
"avsResponse":"M",
"authAmount":12.5,
"entityName":"transaction",
"id":"45"}
}
Then trying to retrieve POST data in Symfony Controller and write it in a sample file, return actually does nothing:
Controller code:
/**
* @Route("/webhook")
* Class DonateController
* @package AppBundle\Controller
*/
class WebHookController extends Controller
{
/**
* @Route("/test", name="webhooktest")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function WebHookAction(Request $request){
set_include_path('/var/www/project/web/');
$file = 'webhook_test.txt';
$content = $request->getContent();
$json = json_decode($content, true);
$wr = "Request object test 0: " . $request->request->all() . "\n\n";
$wr = $wr . "Object : " . $request->__toString() . "\n\n";
file_put_contents($file, $wr);
return $this->render('test/webhook.html.twig',
[
'wr' => $wr
]);
}
Unlucky, the $request contains only header, $request->request->all() returns only empty Array
Tried to extend from FOSRestController with body_listener instead of classic Symfony Controller without any difference.
config.xml part:
param_fetcher_listener: true
body_listener:
decoders:
json: fos_rest.decoder.json
Also tried to handle requests with symfony-json-request-transformer and SymfonyBundlesJsonRequestBundle, no result.
What's wrong here?