Hi there
I am having a script that I am trying to implement but my PHP skills are very limited. I asked the author for help but that did not work out and I wonder if someone here can help me a little bit.
1) Would I set the include command listed below into my order form or would I call the script authnet.php as "action" from my order form?
2) Where and How would place the link to a page that acts as a followup after an order has been approved or declined?
3) The "$result = get_auth_result" section - is that where I specify my variables and would it look like this
// "[First Name]",
=
// "$FirstName",
<?
/////////////////////////
// authnet.php
//http://michael.spinweb.net/code/authnet.phps
// first, include the library file with this statement:
// include("authnet.php");
// then, send your data to the function (yes, the order of the
// fields must be exactly as shown) and read the result like this:
// $result = get_auth_result("[test mode (1 or 0)]",
// "[mode (simple or verbose)]",
// "[AuthorizeNet Login]",
// "[AuthorizeNet password]",
// "[Authorization Code]",
// "[Transaction ID]",
// "[Request Type (AUTH_CAPTURE, etc.)]",
// "[Amount]",
// "[Card Number]",
// "[Exp Date (mm/yyyy)]",
// "[First Name]",
// "[Last Name]",
// "[Company]",
// "[Address]",
// "[City]",
// "[State]",
// "[Zip]",
// "[Country]",
// "[Shipping First Name]",
// "[Shipping Last Name]",
// "[Shipping Company]",
// "[Shipping Address]",
// "[Shipping City]",
// "[Shipping State]",
// "[Shipping Zip]",
// "[Shipping Country]",
// "[Phone]",
// "[Email]",
// "[Customer or Account ID]",
// "[Invoice Number]",
// "[Email Customer (TRUE or FALSE)]",
// "[Merchant Email]",
// "[Description]")
//
// NOT ALL FIELDS ARE NECESSARY!
// If you do not plan to use an argument, you still need to
// send a blank placeholder for it, like this: ""
// the variable "$result" now equals one of the following:
// simple mode:
// "1" - this means the card was approved... all is happy
// "Error: [message]" - there was a problem with the transaction
// in simple mode, [message] will contain the detailed approval
// or decline message that AuthorizeNet returns. Useful for
// telling the user what went wrong.
// verbose mode:
// In this case the string will be a big chunk of stuff that you will
// need to split out yourself. If you are using verbose mode, you are
// (or should be) already familiar with the AuthorizeNet interface
// specs and I don't need to go into detail.
//
// and you may now use the return result in the logic of the
// rest of your application
//////////////////////
// USER-DEFINED VARIABLES
/////////////////////
// if PHP has CURL compiled in, set this to 1
// of not, set it to 0 and set the path to CURL on your system
$NATIVE_CURL = 1;
// path to CURL
// only needed if $NATIVE_CURL is set to 0
$CURL = "/usr/local/bin/curl";
///////////
// URL for posting to Authorize.Net
$AUTHNET_URL = "https://secure.authorize.net/gateway/transact.dll";
$TEST_URL = "https://certification.authorize.net/gateway/transact.dll";
// this function connects to AuthorizeNet and reads the result
function get_auth_result($test_mode,
$mode,
$login,
$password,
$auth_code,
$trans_id,
$type,
$amount,
$cardnum,
$expdate,
$first_name,
$last_name,
$company,
$address,
$city,
$state,
$zip,
$country,
$shipping_first_name,
$shipping_last_name,
$shipping_company,
$shipping_address,
$shipping_city,
$shipping_state,
$shipping_zip,
$shipping_country,
$phone,
$email,
$account_id,
$invoice,
$email_customer,
$merchant_email,
$description)
{
// define globals
global $NATIVE_CURL;
global $CURL;
global $AUTHNET_URL;
global $TEST_URL;
// if we're in test mode, override the
// Authorize.Net login with the test login
if($test_mode == 1)
{
$AUTHNET_URL = $TEST_URL;
}
// build the data string that contains the
// credit card info and customer data
$data = "x_ADC_Delim_Data=TRUE&";
$data .= "x_ADC_URL=FALSE&";
$data .= "x_Login=$login&";
$data .= "x_Password=$password&";
$data .= "x_Version=3.0&";
$data .= "x_Auth_Code=$auth_code&";
$data .= "x_trans_id=$trans_id&";
$data .= "x_Type=$type&";
$data .= "x_Amount=$amount&";
$data .= "x_Method=CC&";
$data .= "x_Card_Num=$cardnum&";
$data .= "x_Exp_Date=$expdate&";
$data .= "x_First_Name=$first_name&";
$data .= "x_Last_Name=$last_name&";
$data .= "x_Company=$company&";
$data .= "x_Address=$address&";
$data .= "x_City=$city&";
$data .= "x_State=$state&";
$data .= "x_Zip=$zip&";
$data .= "x_Country=$country&";
$data .= "x_Ship_To_First_Name=$shipping_first_name&";
$data .= "x_Ship_To_Last_Name=$shipping_last_name&";
$data .= "x_Ship_To_Company=$shipping_company&";
$data .= "x_Ship_To_Address=$shipping_address&";
$data .= "x_Ship_To_City=$shipping_city&";
$data .= "x_Ship_To_State=$shipping_state&";
$data .= "x_Ship_To_Zip=$shipping_zip&";
$data .= "x_Ship_To_Country=$shipping_country&";
$data .= "x_Phone=$phone&";
$data .= "x_Email=$email&";
$data .= "x_Cust_ID=$account_id&";
$data .= "x_Invoice_Num=$invoice&";
$data .= "x_Email_Customer=$email_customer&";
$data .= "x_Merchant_Email=$merchant_email&";
$data .= "x_Description=$description";
$data = ereg_replace(" ", "+", $data);
if($NATIVE_CURL == 1)
{
// initialize a url for curl
$ch = curl_init("$AUTHNET_URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$data");
// post the data and read the result
$return_string = curl_exec($ch);
$verbose_string = $return_string;
curl_close ($ch);
// split the string by comma
$auth_status = explode(",", $return_string);
}
else
{
// post the data using old-style curl on the system
exec("$CURL -d \"$data\" $AUTHNET_URL", $return_string);
$verbose_string = $return_string[0];
// split the string by comma
$auth_status = explode(",", $return_string[0]);
}
if($mode == "simple")
{
// get the status of the credit card and
// assign it to the variable card_status
if($auth_status[0] == "1")
{
// set the status to 1... all good
$card_status = "1";
}
else
{
// return the error
$card_status = "Error: $auth_status[3]";
}
}
elseif($mode == "verbose")
{
// return the full result
$card_status = $verbose_string;
}
// return the card status
return $card_status;
}
?>
Thanks!