Reply
Member
plintu
Posts: 3
Registered: ‎08-18-2010

https://secure.authorize.net/gateway/transact.dll, keeps opening up and showing transaction details

For some reason when I post the data to authorize.net it keeps going to the transaction page and showing the details rather than leaving the user on my website here is the form that I am using and below that is the auth class I am using:

 

<form id="order-pay-form" method="post" action="https://secure.authorize.net/gateway/transact.dll"  sid="{$order['id']}">
    <input type="hidden" name="x_version" value="3.1" />
    <input type="hidden" name="x_delim_data" value="TRUE" />
    <input type="hidden" name="x_delim_char" value="|" />    
    <input type="hidden" name="x_url" value="http://www.xxxxxxxxxx.com/order/authnetcallback.php" />
    <input type="hidden" name="x_type" value="AUTH_ONLY" />
    <input type="hidden" name="x_method" value="CC" />
    <input type="hidden" name="x_relay_response" value="TRUE" />
    <input type="hidden" name="x_login" value="xxxxxxxxxxxxxxxx" />
    <input type="hidden" name="x_tran_key" value="xxxxxxxxxxxxxxxxx" />
    <input type="hidden" name="x_currency_code" value="USD" />
    <input type="hidden" name="x_amount" value="{$total_money}" />
    <input type="hidden" name="x_item" value="{$order_id}" />
    
    <!-- <center><img src="/static/css/i/paypal_logo.gif" /></center><br /><br /><br /> --><b>
    <fieldset>
    <legend>Your Information</legend>
    <table cellspacing="5" cellpadding="5">
    <tr><td>First Name:<br /><input type="text" name="x_first_name" /></td>
    <td>Last Name:<br /><input type="text" name="x_last_name" /></td></tr>
    <tr><td>Billing Address:<br /><input type="text" name="x_address" /></td>
    <td>City:<br /><input type="text" name="x_city" /></td></tr>
    <tr><td>State:<br /><input type="text" name="x_state" /></td>
    <td>Zip Code:<br /><input type="text" name="x_zip" /></td></tr>
    
    <tr><td>Phone No:<br /><input type="text" name="x_phone" /></td>
    <td>E-Mail:<br /><input type="text" name="x_email" /></td>
    </tr></table>
    </fieldset>
    <br />
    <br />
    <br />
    
    <fieldset>
    <legend>Card Details</legend>
    <table cellspacing="5" cellpadding="5">
    <tr><td>Card Holder Number:<br /><input type="text" name="x_card_num" maxlength="16" /></td>
    <td>Expiration Date:<br /><input type="text" name="x_exp_date" maxlength="4" size="3"/>(MMYY, eg. Mar 2012 --> 0312)</td></tr>
    <td>Security Code:<br /><input type="text" name="x_card_code" maxlength="3" size="3"/></td></tr>
    </table></fieldset>
    <br />
    </b>
    <table><tr><td><input type="submit" class="gotopay formbutton" value="Pay" /></td><td align='right'><img src="/static/css/i/AuthorizeNetLogo.jpg" /><br /></td><td align='right'><img src="/static/css/i/verifiedsecure.jpg" /><br /></td><td align='right'><img src="/static/css/i/guaranteed.jpg" width='100' height='100'  /><br /></td></tr>

 

 

here is my authnetcallback.php:

 

 

<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

// Get the subscription ID if it is available. 
// Otherwise $subscription_id will be set to zero.
$subscription_id = (int) $_POST['x_item_number'];
 
// Check to see if we got a valid subscription ID.
// If so, do something with it.
if ($subscription_id)
{
    // Get the response code. 1 is success, 2 is decline, 3 is error
    $response_code = (int) $_POST['x_response_code'];
 
    // Get the reason code. 8 is expired card.
    $reason_code = (int) $_POST['x_response_reason_code'];
 
    if ($response_code == 1)
    {
        // If Approved!
 
         $email = $_POST['x_email'];
         $lastname = $_POST['x_last_name'];
         $firstname = $_POST['x_first_name'];
         $currency = $_POST['x_currency'];
         $order_id  = $_POST['x_order_id'];
	     $out_trade_no = $_POST['x_item_number'];
	     $total_fee = $_POST['x_amount'];
		$order = Table::Fetch('order', $order_id);
		if ( $order['state'] == 'unpay' ) {
			//1
			$table = new Table('order');
			$table->SetPk('id', $order_id);
			$table->pay_id = $out_trade_no;
			$table->money = $total_fee;
			$table->state = 'pay';
			$flag = $table->update( array('state', 'pay_id', 'money') );

			if ( $flag ) {
				$table = new Table('pay');
				$table->id = $out_trade_no;
				$table->order_id = $order_id;
				$table->money = $total_fee;
				$table->currency = $currency;
				$table->bank = 'Pay';
				$table->service = 'pay';
				$table->create_time = time();
				$table->insert( array('id', 'order_id', 'money', 'currency', 'service', 'create_time', 'bank') );

				//update team,user,order,flow state//
				ZTeam::BuyOne($order);
			}
		}
		echo "success";
		
		
    }
    else if ($response_code == 2)
    {
	echo "fail declined";
        // Declined
    }
    else if ($response_code == 3 && $reason_code == 8)
    {
	echo "fail expired card";
        // An expired card
    }
    else 
    {
	echo "failed for unknown reasons";
        // Other error
    }
}
?>

 

here is my AIM:

 

 

 

 

 

<?php
/*******************************************************************************
 *                Authorize.net AIM Interface using CURL
 *******************************************************************************
 *      Author:     Micah Carrick
 *      Email:      email@micahcarrick.com
 *      Website:    http://www.micahcarrick.com
 *
 *      File:       authorizenet.class.php
 *      Version:    1.0.1
 *      Copyright:  (c) 2005 - Micah Carrick 
 *                  You are free to use, distribute, and modify this software 
 *                  under the terms of the GNU General Public License.  See the
 *                  included license.txt file.
 *      
 *******************************************************************************
 *  REQUIREMENTS:
 *      - PHP4+ with CURL and SSL support
 *      - An Authorize.net AIM merchant account
 *      - (optionally) http://www.authorize.net/support/AIM_guide.pdf
 *  
 *******************************************************************************
 *  VERION HISTORY:
 *  
 *      v1.0.1 [01.19.2006] - Fixed urlencode glitch (finally)
 *      v1.0.0 [04.07.2005] - Initial Version
 *
 *******************************************************************************
 *  DESCRIPTION:
 *
 *      This class was developed to simplify interfacing a PHP script to the
 *      authorize.net AIM payment gateway.  It does not do all the work for
 *      you as some of the other scripts out there do.  It simply provides
 *      an easy way to implement and debug your own script.  
 * 
 *******************************************************************************
*/

class authorizenet {

   var $field_string;
   var $fields = array();
   
   var $response_string;
   var $response = array();
   
   var $gateway_url = "https://secure.authorize.net/gateway/transact.dll";
   
   function authorizenet() {
      
      // some default values
      
      $this->add_field('x_version', '3.1');
      $this->add_field('x_delim_data', 'TRUE');
      $this->add_field('x_delim_char', '|');  
      $this->add_field('x_url', 'FALSE');
      $this->add_field('x_type', 'AUTH_ONLY');
      $this->add_field('x_method', 'CC');
      $this->add_field('x_relay_response', 'FALSE');
     
   }
   
   function add_field($field, $value) {
   
      // adds a field/value pair to the list of fields which is going to be 
      // passed to authorize.net.  For example: "x_version=3.1" would be one
      // field/value pair.  A list of the required and optional fields to pass
      // to the authorize.net payment gateway are listed in the AIM document
      // available in PDF form from www.authorize.net

      $this->fields["$field"] = $value;   

   }

   function process() {
       
      // This function actually processes the payment.  This function will 
      // load the $response array with all the returned information.  The return
      // values for the function are:
      // 1 - Approved
      // 2 - Declined
      // 3 - Error
 
      // construct the fields string to pass to authorize.net
      foreach( $this->fields as $key => $value ) 
         $this->field_string .= "$key=" . urlencode( $value ) . "&";
      
      // execute the HTTPS post via CURL
      $ch = curl_init($this->gateway_url); 
      curl_setopt($ch, CURLOPT_HEADER, 0); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $this->field_string, "& " )); 
      $this->response_string = urldecode(curl_exec($ch)); 
      
      if (curl_errno($ch)) {
         $this->response['Response Reason Text'] = curl_error($ch);
         return 3;
      }
      else curl_close ($ch);
 
       
      // load a temporary array with the values returned from authorize.net
      $temp_values = explode('|', $this->response_string);
 
      // load a temporary array with the keys corresponding to the values 
      // returned from authorize.net (taken from AIM documentation)
      $temp_keys= array ( 
           "Response Code", "Response Subcode", "Response Reason Code", "Response Reason Text",
           "Approval Code", "AVS Result Code", "Transaction ID", "Invoice Number", "Description",
           "Amount", "Method", "Transaction Type", "Customer ID", "Cardholder First Name",
           "Cardholder Last Name", "Company", "Billing Address", "City", "State",
           "Zip", "Country", "Phone", "Fax", "Email", "Ship to First Name", "Ship to Last Name",
           "Ship to Company", "Ship to Address", "Ship to City", "Ship to State",
           "Ship to Zip", "Ship to Country", "Tax Amount", "Duty Amount", "Freight Amount",
           "Tax Exempt Flag", "PO Number", "MD5 Hash", "Card Code (CVV2/CVC2/CID) Response Code",
           "Cardholder Authentication Verification Value (CAVV) Response Code"
      );
 
      // add additional keys for reserved fields and merchant defined fields
      for ($i=0; $i<=27; $i++) {
         array_push($temp_keys, 'Reserved Field '.$i);
      }
      $i=0;
      while (sizeof($temp_keys) < sizeof($temp_values)) {
         array_push($temp_keys, 'Merchant Defined Field '.$i);
         $i++;
      }
 
      // combine the keys and values arrays into the $response array.  This
      // can be done with the array_combine() function instead if you are using
      // php 5.
      for ($i=0; $i<sizeof($temp_values);$i++) {
         $this->response["$temp_keys[$i]"] = $temp_values[$i];
      }
      // $this->dump_response();
      // Return the response code.
      return $this->response['Response Code'];

   }
   
   function get_response_reason_text() {
      return $this->response['Response Reason Text'];
   }

   function dump_fields() {
 
      // Used for debugging, this function will output all the field/value pairs
      // that are currently defined in the instance of the class using the
      // add_field() function.
      
      echo "<h3>authorizenet_class->dump_fields() Output:</h3>";
      echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
            <tr>
               <td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
               <td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
            </tr>"; 
            
      foreach ($this->fields as $key => $value) {
         echo "<tr><td>$key</td><td>".urldecode($value)."&nbsp;</td></tr>";
      }
 
      echo "</table><br>"; 
   }

   function dump_response() {
 
      // Used for debuggin, this function will output all the response field
      // names and the values returned for the payment submission.  This should
      // be called AFTER the process() function has been called to view details
      // about authorize.net's response.
      
    echo "<h3>authorizenet_class->dump_response() Output:</h3>";
     echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
            <tr>
            <td bgcolor=\"black\"><b><font color=\"white\">Index&nbsp;</font></b></td>
             <td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
               <td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
            </tr>";
            
      $i = 0;
     foreach ($this->response as $key => $value) {
        echo "<tr>
                  <td valign=\"top\" align=\"center\">$i</td>
                  <td valign=\"top\">$key</td>
                  <td valign=\"top\">$value&nbsp;</td>
               </tr>";
         $i++;
      } 
      echo "</table><br>";
   }    
}


 

 can anyone see why it would be opening up and showing the transaction details?

 

Member
plintu
Posts: 3
Registered: ‎08-18-2010

Re: https://secure.authorize.net/gateway/transact.dll, keeps opening up and showing transaction deta

[ Edited ]

Forgot to mention I am programming in php :smileyvery-happy: and to better describe what it is doing, when the user clicks on submit it opens transact.dll in the browser and shows the transaction details. It is still posting the data back to authcallback.php like it should be, but I do not want the user seeing the transaction details page.

What would be the best option here, am I forced to use jquery ajax function to post the data or is there something simple that I am missing?

Member
plintu
Posts: 3
Registered: ‎08-18-2010

Re: https://secure.authorize.net/gateway/transact.dll, keeps opening up and showing transaction deta

can anyone help me get this form to work?

stymiee
Posts: 1,462
Topics: 17
Kudos: 70
Solutions: 126
Registered: ‎09-14-2009

Re: https://secure.authorize.net/gateway/transact.dll, keeps opening up and showing transaction deta

It looks like you are confusing SIM, AIM, and Silent Post. Try using this AIM tutorial and let me know if you have any issues with it.


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Integrate Every Authorize.Net XML API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

The Handling Online Payments With Authorize.Net and PHP Series
Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Part 8 | Part 9 | Part 10 | Part 11

My Blog posts for Authorize.Net - The Validating Credit Card Series
Credit Card Numbers | Expiration Dates | CVV Numbers

My Blog posts for Authorize.Net - Other Topics
Notifying Users Their Credit Card Is About to Expire Without PCI Compliance Issues
Precision Math with PHP
HTTP Headers to Help Secure Your Website

Please don't ask me questions via private message or email. They will be ignored.
Use the forums. That's what they are here for.