#!/usr/bin/perl -wT ####################################################################################### # Copyright 2001. General Public License # # You can use, modify and redistribute this software under the terms of 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/archive29/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 readable format my $adc_url = 'FALSE'; # no return url my $auth_version = '3.0'; # version of authorize.net gateway 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, etc. # 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,'',$post_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

\n"; # Display the reply headers. print h4('Headers received from v3.0 transact.dll:'); foreach my $key (keys %headers) { print "$key: $headers{$key}
\n"; } print h4('Server response received from v3.0 transact.dll:'), "$response
\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].
"; print "Response Subcode (1): $col[1]
\n"; print "Response Reason Code (2): $col[2]
\n"; print "Response Reason Text (3): $col[3]
\n"; print "Authorization Code (4): $col[4]
\n"; print "AVS Code (5): $col[5]
\n"; print "Trans ID (6): $col[6]
\n", p; my $elements = scalar(@col); my $fields = $elements - 7; print "Total Number of Fields: $fields
"; my ($i, $item); for ($i=7; $i<$elements; $i++) { $item = $i - 6; print "$item. ($i) $col[$i]
\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 failed or there was an internal error." } print end_html;