Jump to content

[SOLVED] Need help EMERGENCY please!


jaxdevil

Recommended Posts

:'(

 

Ok, hello everyone, I am Scott, I know this may be kind of rude just popping in and needing help right off the bat, but I am stuck and need to finish this tonight.

 

I am posting data from a form to a php script, I need the fields from the form post to insert into the php script. I have tried $_POST["fieldname"] and tried switching the form to 'GET and using $_GET["fieldname"]. When passing the data using the 'GET' method I can see the data is being sent correctly to the php script, but the php script just displays the entire "$_POST["fieldname"]" instead of the actual data being posted in the form field for 'fieldname'. Please help! If you need any more information let me know and I will post right back, I will keep checking this all night, hopefully some wondeful person will help me :)

Link to comment
Share on other sites

Thanks a million for helping out you guys!! Here is the script, form, and class I am using (I ********** out my api key and password)...

 

The submit form...

<form method="GET" action="demo.php">
Transaction Amount:<input type="text" size="12" maxlength="12" name="x_amountx"><br />
Expiration Date:<select name="x_exp_datex">
<option value="1107">11/07</option>
<option value="1207">12/07</option>
<option value="0108">01/08</option>
<option value="0208">02/08</option>
<option value="0308">03/08</option>
<option value="0408">04/08</option>
<option value="0508">05/08</option>
<option value="0608">06/08</option>
<option value="0708">07/08</option>
<option value="0808">08/08</option>
<option value="0908">09/08</option>
<option value="1008">10/08</option>
<option value="1108">11/08</option>
<option value="1208">12/08</option>
<option value="0109">01/09</option>
<option value="0209">02/09</option>
<option value="0309">03/09</option>
<option value="0409">04/09</option>
<option value="0509">05/09</option>
<option value="0609">06/09</option>
<option value="0709">07/09</option>
<option value="0809">08/09</option>
<option value="0909">09/09</option>
<option value="1009">10/09</option>
<option value="1109">11/09</option>
<option value="1209">12/09</option>
<option value="0110">01/10</option>
<option value="0210">02/10</option>
<option value="0310">03/10</option>
<option value="0410">04/10</option>
<option value="0510">05/10</option>
<option value="0610">06/10</option>
<option value="0710">07/10</option>
<option value="0810">08/10</option>
<option value="0910">09/10</option>
<option value="1010">10/10</option>
<option value="1110">11/10</option>
<option value="1210">12/10</option>
<option value="0111">01/11</option>
<option value="0211">02/11</option>
<option value="0311">03/11</option>
<option value="0411">04/11</option>
<option value="0511">05/11</option>
<option value="0611">06/11</option>
<option value="0711">07/11</option>
<option value="0811">08/11</option>
<option value="0911">09/11</option>
<option value="1011">10/11</option>
<option value="1111">11/11</option>
<option value="1211">12/11</option>
<option value="0112">01/12</option>
<option value="0212">02/12</option>
<option value="0312">03/12</option>
<option value="0412">04/12</option>
<option value="0512">05/12</option>
<option value="0612">06/12</option>
<option value="0712">07/12</option>
<option value="0812">08/12</option>
<option value="0912">09/12</option>
<option value="1012">10/12</option>
<option value="1112">11/12</option>
<option value="1212">12/12</option>
<option value="0113">01/13</option>
<option value="0213">02/13</option>
<option value="0313">03/13</option>
<option value="0413">04/13</option>
<option value="0513">05/13</option>
<option value="0613">06/13</option>
<option value="0713">07/13</option>
<option value="0813">08/13</option>
<option value="0913">09/13</option>
<option value="1013">10/13</option>
<option value="1113">11/13</option>
<option value="1213">12/13</option>
Credit Card Number:<input type="text" size="16" maxlength="16" name="x_card_numx"><br />
<input type="submit" value="submit" name="submit"><br />
</form><br />

 

The php script I am trying to insert the fields from above into....

<?php

require_once('authorizenet.class.php');

$a = new authorizenet_class;

$a->add_field('x_card_num', '$_GET[x_card_numx]');   // test successful visa
$a->add_field('x_amount', '$_GET[x_amountx]');
$a->add_field('x_exp_date', '$_GET[x_exp_datex]');    // march of 2008

switch ($a->process()) {

   case 1:  // Successs
      echo "<b>Success:</b><br>";
      echo $a->get_response_reason_text();
      echo "<br><br>Details of the transaction are shown below...<br><br>";
      break;
      
   case 2:  // Declined
      echo "<b>Payment Declined:</b><br>";
      echo $a->get_response_reason_text();
      echo "<br><br>Details of the transaction are shown below...<br><br>";
      break;
      
   case 3:  // Error
      echo "<b>Error with Transaction:</b><br>";
      echo $a->get_response_reason_text();
      echo "<br><br>Details of the transaction are shown below...<br><br>";
      break;
}

$a->dump_fields();      // outputs all the fields that we set
$a->dump_response();    // outputs the response from the payment gateway

?>

 

The class the script is including....

<?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_class {

   var $field_string;
   var $fields = array();
   
   var $response_string;
   var $response = array();
   
   var $gateway_url = "https://cardpresent.authorize.net/gateway/transact.dll";
   
   function authorizenet_class() {
      
      // some default values
      
      $this->add_field('x_cpversion', '1.0');
      $this->add_field('x_login', '**********');
      $this->add_field('x_tran_key', '**********');
      $this->add_field('x_market_type', '2');
      $this->add_field('x_device_type', '5');
      $this->add_field('x_response_format', '1');
      $this->add_field('x_delim_char', '|');
      $this->add_field('x_encap_char', '');
   
   }
   
   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 (
           'Version','ResponseCode','Code','Description','AuthCode', 'AVSResultCode','CVVResultCode','TransID','RefTransID','TransHash','TestMode'	
      );

      // 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)." </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 </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 </td>
               </tr>";
         $i++;
      } 
      echo "</table><br>";
   }    
}

?>

Link to comment
Share on other sites

You shouldn't be putting quotes around the variables in your function.

 

Change this

$a->add_field('x_card_num', '$_GET[x_card_numx]');   // test successful visa
$a->add_field('x_amount', '$_GET[x_amountx]');
$a->add_field('x_exp_date', '$_GET[x_exp_datex]');    // march of 2008

 

To

$a->add_field('x_card_num', $_GET['x_card_numx']);   // test successful visa
$a->add_field('x_amount', $_GET['x_amountx']);
$a->add_field('x_exp_date', $_GET['x_exp_datex']);    // march of 2008

 

See if that does it for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.