PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 6th, 2002, 05:08 PM
thedude thedude is offline
The Dude Abides
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,063 thedude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 4 m 29 sec
Reputation Power: 10
Authorize.net AIM connection

Another post here got me interested in the new AIM connection method, so I tried some of my old code on it and none seems to work. Either that or my curl setup has a problem.

Has anyone else connected using the AIM method yet? Code snippets would help me see the error of my ways.
__________________
The Dude
I'm the Dude. So that's what you call me.
That, or Duder, His Dudeness, Or El Duderino.
If, you know, you're not into the whole brevity thing

Reply With Quote
  #2  
Old December 6th, 2002, 05:55 PM
davetufts davetufts is offline
-------------------
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 200 davetufts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 56 sec
Reputation Power: 9
Since there's quite a bit of code, I posted it here:
http://dev.dave.imarc.net/examples/authorizenet.phps

Things to note:
- Take advantage of Authorizenet's Test Mode, by setting $test_mode to true
- You'll have to change all the user entered variables to work with your credit card form.
- Edit the post-authorization calls (right now they're calling methods specific to my shopping cart, then forwarding the user to a 'Thanks' page)
- I know that PHP can be compiled with Curl support, but I found it easier to call curl from the command line - exec(/usr/local/bin/curl...) - you may need to change the path to curl.

good luck

Reply With Quote
  #3  
Old December 6th, 2002, 07:07 PM
thedude thedude is offline
The Dude Abides
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,063 thedude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 4 m 29 sec
Reputation Power: 10
Some of the snippets I have are similar to that, but I'm not sure that they work with the new AIM method. They used to work with the ADC direct, but now it doesn't seem to be connecting.

I looked through the docs and it doesn't appear that things have changed all that much.

hmmm

Reply With Quote
  #4  
Old December 6th, 2002, 09:04 PM
davetufts davetufts is offline
-------------------
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 200 davetufts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 56 sec
Reputation Power: 9
it still works on my site...

Reply With Quote
  #5  
Old December 6th, 2002, 09:09 PM
thedude thedude is offline
The Dude Abides
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,063 thedude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 4 m 29 sec
Reputation Power: 10
Well, I'll keep plugging away

thanks for the help

Reply With Quote
  #6  
Old December 7th, 2002, 12:15 AM
thedude thedude is offline
The Dude Abides
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,063 thedude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 4 m 29 sec
Reputation Power: 10
Dave,
Are you sure your code is working properly? I get parse errors when I run it. Even after removing the portions that talk to your cart.

Most are connected to the nested if statements.

This slight mod works, but only gives the error message: We're sorry, but your credit card....

PHP Code:
<?
        
    
// [1] Set Variables
    
    
$error                       "";
    
$test_mode                   true;
    
$authorized                  false;
    
$data                        "";
    
$response                    "";
    
$x_Test_Request              "TRUE";
    
$total_cost                  $total_cart;
    
    if (
$test_mode) { //set above in step [1]
        
$x_Test_Request              "TRUE";
        
$credit_card_number          "4007000000027";
        
$credit_card_expiration_date "12/05";
        
$total_cost                  "100.00";
    }
    
    
// [2] Seed Data Array For POSTING
    
$post_array = array(
                     
"x_Login"                => ""
                    
,"x_Password"            => ""
                    
,"x_Type"                => "AUTH_ONLY"
                    
,"x_Method"                => "CC"
                    
,"x_Version"            => "3.0"
                    
,"x_ADC_Delim_Data"        => "TRUE"
                    
,"x_ADC_URL"            => "FALSE"
                    
,"x_Test_Request"        => $x_Test_Request
                    
,"x_Amount"                => $total_cost
                    
,"x_Card_Num"            => $credit_card_number
                    
,"x_Exp_Date"            => $credit_card_expiration_date
                    
,"x_Email"                => $email
                    
,"x_Phone"                => $day_phone
                    
,"x_First_Name"            => $first_name
                    
,"x_Last_Name"            => $last_name
                    
,"x_Company"            => $company
                    
,"x_Address"            => $address
                    
,"x_City"                => $city
                    
,"x_State"                => $state
                    
,"x_Zip"                => $zip
                    
,"x_Ship_To_First_Name"    => $ship_first_name
                    
,"x_Ship_To_Last_Name"    => $ship_last_name
                    
,"x_Ship_To_Company"    => $ship_company
                    
,"x_Ship_To_Address"    => $ship_address_1
                    
,"x_Ship_To_City"        => $ship_city
                    
,"x_Ship_To_State"        => $ship_state
                    
,"x_Ship_To_Zip"        => $ship_zip
                
);
    
    
// [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"
    
if( !is_file"/usr/bin/curl" ) ) die( "Fatal Error: Could not locate cURL in /usr/bin/curl ." ); 
    
exec("/usr/bin/curl -m 120 -d \"$data\" [url]https://secure.authorize.net/gateway/transact.dll[/url] -L"$response);
                
    
// [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 your credit card information was not accepted.  Please re-check the credit card type, number, and expiration date you entered.";
    }
    
    echo 
$error;
?>

Reply With Quote
  #7  
Old December 7th, 2002, 08:40 AM
davetufts davetufts is offline
-------------------
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 200 davetufts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 56 sec
Reputation Power: 9
Are you sure that there wasn't anything else in your code causing the parse errors? This page is the exact same page as my original source-code example (except with the '.php' extenstion, insead of '.phps'):
http://dev.dave.imarc.net/examples/authorizenet.php

Since the Authorizenet login and password ("x_Login" / "x_Password") are both invalid (currently set to 'xxxxxxx'), I'm getting the appropriate error from authorizenet. The bold text 'The merchant login ID..." is echoed back directly from Authorizenet's resonse ($response_array[4]).

I'm getting the same response when I use your code -
http://dev.dave.imarc.net/examples/dude.php
which also gets the proper error (since in your code, the login/password are blank)

Do you have a autorizenet account, if so make sure that you use your login/password in step #2 ( // [2] Seed Data Array For POSTING)

Reply With Quote
  #8  
Old December 7th, 2002, 01:01 PM
thedude thedude is offline
The Dude Abides
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,063 thedude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 4 m 29 sec
Reputation Power: 10
Yes, I have an account and the right info was seeded. The only error I got was what I wrote above. I didn't even get the other stuff, that you got on your site, i.e. all the response stuff.

I did get several parse errors with yours, but I worked through them. Mostly they were from bracket errors.

I'm beginning to suspect something is going on with my curl installation (actually my hosts curl install). I know the path is valid (I physically went in and found the curl file), so something else must be going on.

Last edited by thedude : December 7th, 2002 at 01:11 PM.

Reply With Quote
  #9  
Old December 28th, 2002, 06:27 PM
Demel Demel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 11 Demel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi

I found this topic and tried to work with your code. However - I am very new to PHP and all that stuff and have a problem.

I am setting the variables of my order form to match the ones from your code. However - the CC expiration date are 2 variables and your code shows only one. How can I convert this? Here's the code from my order form:

PHP Code:
<input type="text" name="cc_number" size="40" style="font-family:verdana; font-size:10px; border-top-width:1px; border-left-width:1px;">
            </
p>
</
td>
</
tr>
      
</
table>
<
table width="223" border="0">
        
<
tr align="left" valign="top"
          
<
td width="90"
            
<
p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Month:</b></font>
        
<
br>
                <
select name="expmo" style="font-family:verdana; font-size:10px; border-top-width:1px; border-left-width:1px;">
                  <
option value="01">01</option>
<
option value="02">02</option>
<
option value="03">03</option>
<
option value="04">04</option>
<
option value="05">05</option>
<
option value="06">06</option>
<
option value="07">07</option>
<
option value="08">08</option>
<
option value="09">09</option>
<
option value="10">10</option>
<
option value="11">11</option>
<
option value="12">12</option>
</
select>
        
            </
p>
</
td>
<
td width="123"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Year:</b></font>
            
<
br>
              <
select name="expyr" style="font-family:verdana; font-size:10px; border-top-width:1px; border-left-width:1px;">
                
<
option value="2002">2002</option>
<
option value="2003">2003</option>
<
option value="2004">2004</option>
<
option value="2005">2005</option>
<
option value="2006">2006</option>
<
option value="2007">2007</option>
<
option value="2008">2008</option>
</
select


Any chance that you can post your orderform maybe?

Thanks!

Demel

Reply With Quote
  #10  
Old December 28th, 2002, 11:04 PM
Demel Demel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 11 Demel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am making some progress with this script.

Question:

PHP Code:
 $authorized                  false


How do I set this if I would take the script live (or do I comment out this line completely)?

Demel

Reply With Quote
  #11  
Old December 28th, 2002, 11:12 PM
davetufts davetufts is offline
-------------------
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 200 davetufts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 56 sec
Reputation Power: 9