Jump to content

Authorize.net Aim Setup


adrenalinepcs

Recommended Posts

i found a script online and modified a bunch of it. it works but it always desplays the error message even when authorize.net records the transaction.

 

here is the code:

 

<?php 
   
   /* 
       + + + AUTHORIZENET.COM / PHP + + + 
       
       Requirements: Unix web server 
                     PHP 4.1 or higher 
                     Curl (http://curl.haxx.se/) 
                     
       [1] Set Variables 
       [2] Seed Data Array For POSTING 
       [3] Convert Array to POST string (key_1=val_1&key_2=val_2...) 
       [4] Securely POST to AuthorizeNet using "curl" 
       [5] Handle Response FROM AuthorizeNet - Set $authorized = TRUE if transaction wass successful 
       
       AuthorizeNet Documentation -> http://www.authorizenet.com/support 
       
   */ 
   
   
   // [1] Set Variables 
   
   $error                       = ""; 
   $test_mode                   = false; 
   $authorized                  = false; 
   $data                        = ""; 
   $response                    = ""; 
   $total_cost                  = $_REQUEST['Amount']; 
  $login                       = "xxxxxxxxx"; 
  $tran                        = "xxxxxxxxx"; 
   
   // [2] Seed Data Array For POSTING 
   // 
   // NOTE: the $_REQUEST field names much match your HTML checkout form 
   $post_array = array( 
                    "x_login"                => $login 
                   ,"x_tran_key"             => $tran 
                   ,"x_version"              => "3.0" 
                   ,"x_test_request"         => "FALSE" 
                   ,"x_delim_data"           => "TRUE" 
                   ,"x_relay_response"       => "FALSE" 
                   ,"x_first_name"           => $First_Name 
                   ,"x_last_name"            => $Last_Name 
                   ,"x_address"              => $Address 
                   ,"x_city"                 => $City 
                   ,"x_state"                => $State 
                   ,"x_zip"                  => $Zip 
                   ,"x_country"              => $Country 
                   ,"x_phone"                => $Phone 
                   ,"x_email"                => $Email 
                   ,"x_email_customer"       => "TRUE" 
                   ,"x_amount"               => $total_cost 
                   ,"x_Description"          => $Description 
                   ,"x_method"               => "ECHECK" 
                   ,"x_type"                 => "AUTH_ONLY" 
                ,"x_recurring_billing"    => $_REQUEST['Recurring_Billing'] 
              ,"x_bank_aba_code"        => $_REQUEST['Bank_ABA_Code'] 
              ,"x_bank_acct_num"        => $_REQUEST['Bank_Acct_Num'] 
              ,"x_bank_acct_type"       => $_REQUEST['Bank_Acct_Type'] 
              ,"x_bank_name"            => $_REQUEST['Bank_Name'] 
              ,"x_bank_acct_name"       => $_REQUEST['Bank_Acct_Name'] 
              ,"x_description"          => $_REQUEST['Description'] 
              ,"x_echeck_type"          => "WEB" 

               ); 
   
   // [3] Convert Array to POST string (key_1=val_1&key_2=val_2...) 
   reset($post_array); 
   while (list ($key, $val) = each($post_array)) { 
       $data .= $key . "=" . urlencode($val) . "&"; 
   } 

   // [4] Securely POST to AuthorizeNet using "curl" 

// BEGIN PHP_CURL.DLL CODE - Author: Peter Drake - 4/29/03 
// Use for Win32 or Unix-type systems with php-curl.dll 
// Get a CURL handle 
       $curl_handle = curl_init(); 

// Tell CURL the URL of the CGI 
       curl_setopt($curl_handle, CURLOPT_URL, "https://secure.authorize.net/gateway/transact.dll"); 

// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.php 
// for more details 
       curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1); 
       curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); 
       curl_setopt($curl_handle, CURLOPT_POST, 1); 
       curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data); 

// Perform the POST and get the data returned by the server. 
       $response = curl_exec ($curl_handle) or die ("There has been an error connecting to Authorize.net."); 

// Close the CURL handle 
       curl_close ($curl_handle); 
//END PUP_CURL.DLL CODE 

               
   // [5] Handle Response FROM AuthorizeNet 
   //     Set $authorized = TRUE if transaction wass successful 
   if (is_array($response)) { 
       if (count($response) > 0) { 
           // Change the array key indexing from 0-base to 1-base 
           $temp_response = "," . $response[0]; 
           $response_array = explode(",", $temp_response); 
           unset($response_array[0]); 
             
           if ($response_array[1] == 1) { 
               $authorized = true; 
           } else { 
               $error = "<b>" . $response_array[4] . "</b> "; 
           } 
             
           // Debugging Text 
           if ($test_mode) { //set above in step [1] 
               while (list ($key, $val) = each($response_array)) { 
                   print("<b>$key</b> = " . $val . "<br>\n"); 
               } 
           } 
       } else { 
           $authorized = false; 
       } 
   } else { 
       $authorized = false; 
   }              
     
//  Successful Authorization - Add the order and forward the user... 
   if($authorized) { 

//I put in a BS condition, to keep the if statements consistent 
       if(1==1) {                      

           echo "Success"; 
             
       } else { 
           $error = "There was a problem processing your order."; 
       } 
   } else { 
       // Credit Card Error (returned from authorizenet) 
       $error .= "We're sorry, but the transaction was not accepted.  Please re-check what you entered you entered."; 
   } 
     
   echo $error; 
?>

 

anyone know whats going on?

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello,

 

your code looks OK and it should work.

 

This is what I suggest:

 

after where it says

<?php

// Perform the POST and get the data returned by the server.

$response = curl_exec ($curl_handle) or die ("There has been an error connecting to Authorize.net.");

?>

 

go ahead and add this:

 

print($response);

exit;

 

Then run the script. You will see an array response from authorize.net. Please paste it here for me (dont worry it does not have private info - just use fictional customer info in the script).

I went through alot of hassle to get my server to work with AUTHNET API...and I just to see someone struggling with it.

 

Goodluck

AWI

Share this post


Link to post
Share on other sites

i was able to it to work. not using that code though.

i used the scripts from:

www.digitalsorceress.com/pant/

 

and then had to modify it to work with my server

 

so in the functions file i changed the curl code to:

 

// BEGIN PHP_CURL.DLL CODE - Author: Peter Drake - 4/29/03

// Use for Win32 or Unix-type systems with php-curl.dll

// Get a CURL handle

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...