cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Authorize.net Wordpress Plugin Breaks Suddenly

I have a Wordpress plugin I guilt almost a year ago which suddenly stopped working properly this week. The problem seems to be that my webhook.php file is not updating my database containing the order status when it is paid. I can think of no reason why this would be because of anything I did due to the simple fact that I have not changed the code in nearly a year and I hadn't made any changes at all to the site using the plugin recently.

This problem seems possibly related to other cases of update queries not always working when run against the Wordpress database.

A redacted version of the webhook code is as follows:

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);
function print_log($val) {
    return file_put_contents('stderr.txt', print_r($val, TRUE));
}
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->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."'");
        $orderrow = $wpdb->get_row("SELECT orderid, post, site, url, status, refid, transid, transtype, transstatus FROM orders WHERE transid = '".$transactionId."'");
        $siteid = $orderrow->site;
        $postid = $orderrow->post;
        //print_log('post = ' . $postid);
        $siterow = $wpdb->get_row("SELECT siteid, sitename, siteurl, siteemail, approved, price FROM sites WHERE siteid ='".$siteid."'");
        $site = $siterow->siteid;
        $sitename = $siterow->sitename;
        $siteurl = $siterow->siteurl;
        $siteemail = $siterow->siteemail;
        $approved = $siterow->approved;
        $remoteurl = $siteurl.'wp-content/plugins/myplugin/webhook.php?post='.$postid.'&tid='.$transactionId.'&key='.\SampleCodeConstants::HOST_KEY;
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $remoteurl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        $data = array(
            'post' => $postid,
            'tid' => $transactionId,
            'key' => \SampleCodeConstants::HOST_KEY
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        http_response_code(200);
    }
}
0 REPLIES 0