Getting "Invalid JSON sent in the Webhook notification" Authorize.net

505 Views Asked by At

My Authorize.net webhook is set up properly on the A.net side, and when I trigger an event to get the notification, I get this in the error log:

PHP Fatal error: Uncaught exception 'JohnConde\Authnet\AuthnetInvalidJsonException' with message 'Invalid JSON sent in the Webhook notification' in /.../AuthnetWebhook.php:67 Stack trace: 0 /.../webhook.php(23): JohnConde\Authnet\AuthnetWebhook->__construct('xxxxxxxxxxx...', '', Array) 1 {main} thrown in /.../AuthnetWebhook.php on line 67

I can successfully setup the webhook and get notification history through the library on Github. Here is the code I'm using as my endpoint. Both allow_url_fopen and allow_url_include are set to enabled on my server.

<?php

namespace myapplication;

use JohnConde\Authnet\AuthnetWebhook;

require('.../config.inc.php');

require('.../autoload.php');

$headers = getallheaders();
$payload = file_get_contents("php://input");
$webhook = new AuthnetWebhook(AUTHNET_SIGNATURE, $payload, $headers);
if ($webhook->isValid()) {

    $transactionId = $webhook->payload->id;

    $fp = fopen('results.json', 'w');
    fwrite($fp, json_encode($webhook));
    fclose($fp);


    // Access notifcation values
    // echo $webhook->eventType;
}



?>

Thanks for any help!

2

There are 2 best solutions below

12
On

Your payload is an empty string.. you can see it in the error.

AuthnetWebhook->__construct('xxxxxxxxxxx...', '', Array)

So

new AuthnetWebhook(AUTHNET_SIGNATURE, $payload, $headers); 

I am not familiar with AuthnetWebhook but I would bet (if I was a gambler) that the payload variable should not be empty.

1
On

Solved. The endpoint URL was incorrect. I had mysite.com/webhook.php and needed www.mysite.com/webhook.php.