Reply
Member
Posts: 6
Registered: ‎05-20-2021

Where Do I Find Webhook Logs and Test an Active Webhook?

I am trying Authorize.net for the first time and have successfully setup a sandbox checkout option using the Accept Hosted redirect method, but as far as I can tell my webhook is not receiving the net.authorize.payment.authcapture.created event or if it is it is not processing it right. Does Authorize.net have place where I could view the history of all attempts to send webhook notifications to my server and what was contained in those hooks? Is there a way I could click on a transaction and make Authorize.net send a new notification right away?

 

Right now I am using a domain that is not in production on my remote server becasue I couldn't find a solution for testing webhooks on localhost. I am coming from Stripe and they had an app you could install on your desktop that would allow that, but I see no such thing from Authorize. The method I am trying to use is the same one found at http://www.johnconde.net/blog/handling-authorize-net-webhooks-with-php/.

 

Here is some sample code edited to omit some potentially sensitive stuff.

 

namespace Authnetjson;
// Set your secret key. Remember to switch to your live secret key in production.
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// error message to be logged
$error_message = "This is an error message!";
// path of the log file where errors need to be logged
$log_file = "phperr.txt";
// setting error logging to be active
ini_set("log_errors", TRUE);
// setting the logging file in php.ini
ini_set('error_log', $log_file);
require_once('../../../wp-load.php');
require 'vendor/autoload.php';
require_once 'constants/SampleCodeConstants.php';
$headers = getallheaders();
$payload = file_get_contents("php://input");
$webhook = new AuthnetWebhook(\SampleCodeConstants::WEBHOOK_SIGNATURE, $payload, $headers);
if ($webhook->isValid()) {
    // Access notification values
    $transactionId = $webhook->payload->id;
    $merchantrefid = $webhook->payload->merchantReferenceId;
    $eventtype = $webhook->payload->eventType;
    // Here you can get more information about the transaction
    $request  = AuthnetApiFactory::getJsonApiHandler(\SampleCodeConstants::MERCHANT_LOGIN_ID, \SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
    $response = $request->getTransactionDetailsRequest(array(
        'transId' => $transactionId,
    ));
    $transtype = $response->transaction->transactionType;
    $transstatus = $response->transaction->transactionStatus;
    global $wpdb;
    if($eventtype == 'net.authorize.payment.authcapture.created')
    {
        $wpdb->query("UPDATE orders SET status = 'paid', transid = '".$transactionId."', transtype = '".$transtype."', transstatus = '".$transstatus."' WHERE refid = '".$merchantrefid."'");
    }
}
http_response_code(200);
Member
Posts: 6
Registered: ‎05-20-2021

Re: Where Do I Find Webhook Logs and Test an Active Webhook?

I also added a second endpoint at WebhookInbox just to make sure webhooks are being sent somewhere. I have yet to receive a single notification at that location despite it being listed as an active webhook in my account. I made another test purchase and still have not received any notifications at all at the second endpoint.

Member
Posts: 6
Registered: ‎05-20-2021

Re: Where Do I Find Webhook Logs and Test an Active Webhook?

Also, how do I get the webhook identification number? When I check the webhooks section of my account the webhook id numbers are not displayed.

Member
Posts: 4
Registered: ‎06-03-2021

Re: Where Do I Find Webhook Logs and Test an Active Webhook?

You can obtain the webhook id by looking at its link, the number after https://discord.com/api/webhooks/ is the id, and the part after that is the token.