in reply to Interfacing to Authorize.Net
#!/usr/bin/perl -wT ###################################################################### +################# # Copyright 2001. General Public License # # You can use, modify and redistribute this software under the terms o +f the GNU # General Public License as published by the Free Software Foundation. + And provided # that this header appear on all copies of the software. This program +is distributed # without warranty. # # References: http://www.perldoc.com/cpan/Net/SSLeay.html # http://remus.prakinf.tu-ilmenau.de/ssl-users/arc +hive29/0042.html # ###################################################################### +################# use strict; use CGI qw(:standard); use Text::CSV; use Net::SSLeay qw(post_https make_headers make_form); my $DEBUG = 1; ############################### Credit Card Data ############ +################### # only address number and zip code required for AVS my $first_name = 'Firstname'; my $last_name = 'Lastname'; my $address = 'Address'; my $city = 'City'; my $state = 'State'; my $zip = 'Zip'; my $email = 'Email'; my $cc_type = 'VISA'; my $cc_number = '4222222222222'; my $exp_date = '11/2002'; my $cc_amount = '1.00'; my $description = 'Description'; ############################### Authorize.Net Configuration # +############################## my $login = 'login'; # Authorize.Net login name my $test_mode; if ($DEBUG) { $test_mode = 'TRUE'; # TRUE=test } else { $test_mode = 'FALSE'; # FALSE=live } # for the most part these should remain the same my $adc_delim_data = 'TRUE'; # return results in machine read +able format my $adc_url = 'FALSE'; # no return url my $auth_version = '3.0'; # version of authorize.net gatew +ay code # version 3.0 defaults my $server = 'secure.authorize.net'; my $path = '/gateway/transact.dll'; my $port = '443'; # if other authorization types will be accepted, may need to make +it an argument # password is not needed for auth_capture type my $auth_type = 'AUTH_CAPTURE'; my $password = ''; ### check for required data for this auth type such as credit card, et +c. # setup ADC form fields my %submit_data = (x_Login => "$login", x_Password => "$password", x_Version => "$auth_version", x_ADC_Delim_Data => "$adc_delim_data", x_ADC_URL => "$adc_url", x_Test_Request => "$test_mode", x_Type => "$auth_type", x_Description => "$description", x_First_Name => "$first_name", x_Last_Name => "$last_name", x_Address => "$address", x_City => "$city", x_State => "$state", x_Zip => "$zip", x_Email => "$email", x_Card_Num => "$cc_number", x_Exp_Date => "$exp_date", x_Amount => "$cc_amount"); ############################### Process the Transaction ##### +########################## # make the form data my $post_data = &make_form(%submit_data); # Send data via SSL (encrypted channel) and wait for reply # $page is the content as defined by http (usually your HTML page) # $response is the first line sent back on hte SSL connection. # %headers is a hash of HTTP headers/response codes sent back my($page,$response,%headers) = &post_https($server,$port,$path,'',$p +ost_data); ############################### See What Was Returned ######## +####################### print header(), start_html(); # if $page is defined, success! if (defined $page) { if ($DEBUG) { print h3('Sent the following string:'), "https://${server}${path}?$post_data<BR><BR>\n"; # Display the reply headers. print h4('Headers received from v3.0 transact.dll:'); foreach my $key (keys %headers) { print "$key: $headers{$key}<BR>\n"; } print h4('Server response received from v3.0 transact.dll:'), "$response<br>\n"; #parse the page my $csv = new Text::CSV(); $csv->parse($page); my @col = $csv->fields(); print h4("see Developer's Guide - Appendix C - Response Codes"); print "Response Code (0): $col[0].<br>"; print "Response Subcode (1): $col[1]<br>\n"; print "Response Reason Code (2): $col[2]<br>\n"; print "Response Reason Text (3): $col[3]<br>\n"; print "Authorization Code (4): $col[4]<br>\n"; print "AVS Code (5): $col[5]<br>\n"; print "Trans ID (6): $col[6]<br>\n", p; my $elements = scalar(@col); my $fields = $elements - 7; print "<b>Total Number of Fields: $fields</b><br>"; my ($i, $item); for ($i=7; $i<$elements; $i++) { $item = $i - 6; print "$item. ($i) $col[$i]<BR>\n"; } } } else { # return empty list (or was it undef) if they fail to connection +(or any internal errors) print "Failed to open tcp connection, SSL connection negotiation f +ailed or there was an internal error." } print end_html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Interfacing to Authorize.Net
by gmorris (Initiate) on Dec 29, 2001 at 00:43 UTC | |
by Anonymous Monk on Apr 03, 2002 at 10:36 UTC |