THRAK has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on a script to interface to Authorize.Net and seem to be getting nowhere fast. I've never used Net::SSLeay which is what the outdated example script uses, although I'm using the newer V1.09. I've searched here and the net at large and haven't found anything (that's not $200 anyway!) about interfacing to Authorize.Net. If I can get this working I figure not only do I benefit, but other Perlers who may need to tread this road may do so with less effort.
I talked to AuthNet technical support that gave me a different address that will echo back the form values that are sent, and it would appear that things are not being properly sent. The person I talked to didn't quite know how to proceed and I'm currently awaiting a return call from someone else. Incidentally I went back and ran the example script and it fails in the same fashion as I describe below. My script is based heavily upon the example script, but has been modified to run under strict. I've found a couple of problems/concerns when I set the SSLeay trace to 3...
The first being Odd number of elements in hash assignment at ./an_pm.pl line 65. The script then attempts to connect to the server...
Opening connection to server105.hypermart.net:443 (63.251.5.33)
Followed by ...
Argument "server105.hypermart.net" isn't numeric in subroutine entry at /usr/local/lib/perl5/5.6.1/i686-linux/Socket.pm line 442.
Things then seem to proceed as normal. When accessing AuthNet I get an "Invalid Merchant Login or Account Inactive" reply. When accessing the test server, it sends back one field named "1/8" with no value assigned (obviously because it's not a field that was sent). I'm guessing my problems are related to the two errors above, but I don't know what is causing them. It seems to establish a connection, but then is sending wrong/corrupted data. The code...
-THRAK
www.polarlava.com
The first being Odd number of elements in hash assignment at ./an_pm.pl line 65. The script then attempts to connect to the server...
Opening connection to server105.hypermart.net:443 (63.251.5.33)
Followed by ...
Argument "server105.hypermart.net" isn't numeric in subroutine entry at /usr/local/lib/perl5/5.6.1/i686-linux/Socket.pm line 442.
Things then seem to proceed as normal. When accessing AuthNet I get an "Invalid Merchant Login or Account Inactive" reply. When accessing the test server, it sends back one field named "1/8" with no value assigned (obviously because it's not a field that was sent). I'm guessing my problems are related to the two errors above, but I don't know what is causing them. It seems to establish a connection, but then is sending wrong/corrupted data. The code...
#!/usr/bin/perl -w # Based upon the work of Doc Web... # Copyright 08.07.1999 by Doc Webb, webmaster@e-business-hosting.com # All rights reserved. # USAGE: # authnet.pl <first_name> <last_name> <CC_number> <expiration_date> + <charge_amount> ################ ### includes ### ################ use strict; use Net::SSLeay qw(post_https make_headers make_form); $Net::SSLeay::ssl_version = 3; # force version in OpenSSL (autodetect +broken?) $Net::SSLeay::trace = 3; ############################ ### Script Configuration ### ############################ $|++; #unbuffer output my $debug = 1; ################################### ### Authorize.Net Configuration ### ################################### # These all related to setting in the Authorize.Net Developer's Guide my $login = 'testdrive'; #Authorize.Net login name my $test_mode = 'TRUE'; # TRUE=test, FALSE=live!!! #Generally, these shouldn't need to be changed... my $adc_delim_data = 'TRUE'; my $adc_url = 'FALSE'; my $authnet_ver = '3.0'; #my $host = 'secure.authorize.net'; #my $script = '/gateway/transact.dll'; my $host = 'server105.hypermart.net'; my $script = '/testan/getpost.cgi'; my $port = '443'; ### Charge Form Data ### my $first_name = shift || 'John'; my $last_name = shift || 'Doe'; my $card_num = shift || '4222222222222'; my $expiration_date = shift || '1102'; my $charge_amount = shift || '1'; my $authorization_type = "AUTH_ONLY"; my $auth_type = 'AUTH_ONLY'; my $payment_method = 'CC'; ### Reply Data ### my ($reply_data, $reply_type, %reply_headers); ###### DO NOT CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOUR DOI +NG! ###### ################################# ### Authorize.Net Interaction ### ################################# #Build form data... my %form_data = make_form + ( + 'x_Login' => $login ,'x_Version' => $authnet_ver ,'x_ADC_Delim_Data' => $adc_delim_data ,'x_ADC_URL' => $adc_url ,'x_Test_Request' => $test_mode ,'x_Type' => $auth_type ,'x_Method' => $payment_method ,'x_First_Name' => $first_name ,'x_Last_Name' => $last_name ,'x_Amount' => $charge_amount ,'x_Card_Num' => $card_num ,'x_Exp_Date' => $expiration_date ); # Send data via $form_data{'payment_method'}he same encrypted channel. + ($reply_data, $reply_type, %reply_headers) = post_https($host, $port, +$script, '', %form_data); ### SHOULD PUT A COMM FAILURE CHECK HERE ### if ($debug) { # print "Content-type: text/html\n\n"; print "Sent the following string:<br><br>\n"; print "https://${host}${script}?x_Login=$login&x_Version=$authnet_ +ver&x_ADC_Delim_Data=$adc_delim_data&x_ADC_URL=$adc_url&x_Type=$auth_ +type&x_Test_Request=$test_mode&x_Method=$payment_method&x_First_Name= +$first_name&x_Last_Name=$last_name&x_Amount=$charge_amount&x_Card_Num +=$card_num&x_Exp_Date=$expiration_date<BR><BR>\n"; # Display the reply headers. print "Reply headers received from v3.0 transact.dll:<BR>\n"; foreach my $key (keys %reply_headers) { print "$key: $reply_headers{$key}<BR>\n"; } print "<BR>Reply type specification received from v3.0 transact.dl +l:<BR> $reply_type<BR>\n"; # split out the returned fields my @data = split (/\,/, $reply_data); # Print the unparsed reply_data. print STDOUT "<BR>Unparsed reply data:<BR> $reply_data<BR>\n"; print "<BR>Data returned by v3.0 transact.dll (see v3.0 transact.d +ll documentation for a descriptions of each data item ret +urned):<BR>\n"; my $data_item = 1; foreach(@data) { print "Item $data_item: $_<BR>\n"; $data_item++; } } __END__
-THRAK
www.polarlava.com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Interfacing to Authorize.Net
by traveler (Parson) on Nov 09, 2001 at 00:01 UTC | |
by THRAK (Monk) on Nov 09, 2001 at 00:27 UTC | |
by traveler (Parson) on Nov 09, 2001 at 00:50 UTC | |
by THRAK (Monk) on Nov 09, 2001 at 01:07 UTC | |
Re: Interfacing to Authorize.Net
by THRAK (Monk) on Nov 09, 2001 at 02:20 UTC | |
by Anonymous Monk on Feb 19, 2004 at 19:43 UTC | |
Re: Interfacing to Authorize.Net
by monecky (Initiate) on Nov 09, 2001 at 05:47 UTC | |
by THRAK (Monk) on Nov 09, 2001 at 18:42 UTC | |
Re: Interfacing to Authorize.Net
by lil sister (Initiate) on Nov 18, 2001 at 04:53 UTC | |
by gmorris (Initiate) on Dec 29, 2001 at 00:43 UTC | |
by Anonymous Monk on Apr 03, 2002 at 10:36 UTC |
Back to
Seekers of Perl Wisdom