John McAlester

WP-shoppingcart plugin with godaddy.com Shared Hosting

Godaddy.com shared hosting uses a secure proxy server for cURL sessions.  This is fine but it requires that you change a little bit of the code in a PHP file if you would like to get that to work with the wp-shopping cart plugin and authorize.net as your payment gateway. 

You will need to purchase the Gold-Cart upgrade for wp-shopping cart if you would like to be able to use authorize.net as your payment gateway. After setting up the plugin and adding my products I was extremely frustrated to find out that my shopping cart transactions were not going through correctly. I had entered my API information correctly and I was sure that the plugin was set up in the right way but I was getting a blank page returned every time I tried to submit a transaction.

The solution is that the cURL session has to be written so that the call goes through godaddy’s secure proxy server. The first clue came from this page: http://davidwalsh.name/godaddy-hosting-tip-using-curl-on-godaddy-shared-hosting which alerted me to how godaddy shared hosting handles cURL calls. I then went to the help page at godaddy.com which gave me the correct code for a cURL call to their proxy servers. That page is: http://help.godaddy.com/article.php?article_id=289&topic_id=435

The authorize.php file located in gold_cart_files/merchants is the file with the code that actually sends the data that the shopper enters into your shopping cart to authorize.net. This file normally sends the data through a regular http:// address but godaddy shared hosting only uses a secure https:// protocol to do cURL sessions. So you have to add a few lines of code to your authorize.php file.

These are the 3 lines of code that you need to copy:

curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");

Paste those 3 lines of code into your authorize.php file just after the lines of code below (should be about line 190):

#
# Start CURL session
#
$user_agent = "WP eCommerce plugin for Wordpress";
$referrer = get_option('transact_url');
$ch=curl_init();

The final cURL session code looks like this:

#
# Start CURL session
#
$user_agent = "WP eCommerce plugin for Wordpress";
$referrer = get_option('transact_url');
$ch=curl_init();
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt($ch, CURLOPT_URL, "https://secure.authorize.net/gateway/transact.dll");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($ch);
curl_close($ch);

Then save the file and your shopping cart should be able to do cURL sessions through godaddy shared hosting to authorize.net

You can download a complete authorize.php file with the new code inserted here

Tags: , ,

Leave a Reply