#!/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 ################ ### 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 DOING! ###### ################################# ### 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:

\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

\n"; # Display the reply headers. print "Reply headers received from v3.0 transact.dll:
\n"; foreach my $key (keys %reply_headers) { print "$key: $reply_headers{$key}
\n"; } print "
Reply type specification received from v3.0 transact.dll:
$reply_type
\n"; # split out the returned fields my @data = split (/\,/, $reply_data); # Print the unparsed reply_data. print STDOUT "
Unparsed reply data:
$reply_data
\n"; print "
Data returned by v3.0 transact.dll (see v3.0 transact.dll documentation for a descriptions of each data item returned):
\n"; my $data_item = 1; foreach(@data) { print "Item $data_item: $_
\n"; $data_item++; } } __END__