package Authnet; my($VERSION) = '1.00'; use strict; no strict 'refs'; use Net::SSLeay qw(get_https post_https sslcat make_headers make_form); #------------------------------------------------------------------------------------------------ ## BEGIN SUBS HERE #------------------------------------------------------------------------------------------------ sub new { my $self = bless({},shift); my $parm = shift; $self->{_prog_name} = $parm->{prog_name} or croak("No prog_name parm"); $self->{_conf_path} = $parm->{conf_path} or croak("No conf_path parm"); $self->initialize(); return($self); } #----------------------------------------------------------------------------------- sub AUTOLOAD { # Handle the case where an undefined subroutine is called return(''); } #----------------------------------------------------------------------------------- sub DESTROY { my($self) = shift; $self->finish(); } #----------------------------------------------------------------------------------- sub finish { my($self) = shift; } #----------------------------------------------------------------------------------- sub initialize { my($self) = shift; require $self->{_conf_path}; if (defined(%conf::data)) { $self->{_conf} = \%conf::data; } $self->{_error} = undef; $self->{_err_txt} = undef; } #----------------------------------------------------------------------------------- #this sub processes the payment transaction via authorize.net #----------------------------------------------------------------------------------- sub auth_trans{ my ($self) = shift; my ($ref_url) = shift; my ($sub_id) = shift; my ($f_name) = shift; my ($l_name) = shift; my ($addr) = shift; my ($city) = shift; my ($state) = shift; my ($zip) = shift; my ($card_no) = shift; my ($cvv2) = shift; my ($exp_date) = shift; my ($amt) = shift; my ($DEBUG) = 1; if (!$sub_id){ $self->{_error} = 97; $self->system_notify(); return(0); } if (!$f_name || !$l_name || !$card_no || !$exp_date || !$amt){ $self->{_error} = 33; $self->{_err_txt} = 'First name, Last Name, Card Number, Exp Date, or Amount'; return(0); } my (@auth_array) = (); my($host) = $self->{_conf}{'Authnet_host'}; my($script) = $self->{_conf}{'Authen_script'}; my ($url) = $self->{_conf}{'Authnet_URL'}; my($headers) = make_headers('Connection' => 'close', 'Referer' => $ref_url, 'Accept-Language' => 'en-us', 'User-Agent' => 'Mozilla/4.0 (compatible; AIT 1.1)'); my ($form) = make_form('x_Login' => $self->{_conf}{'x_Login'}, 'x_Password' => $self->{_conf}{'x_Password'}, 'x_ADC_Delim_Character' => $self->{_conf}{'x_ADC_Delim_Character'}, 'x_ADC_Delim_Data' => $self->{_conf}{'x_ADC_Delim_Data'}, 'x_Encapsulate_Character' => $self->{_conf}{'x_Encapsulte_Character'}, 'x_ADC_URL' => $self->{_conf}{'x_ADC_URL'}, 'x_Method' => $self->{_conf}{'x_Method'}, 'x_Type' => $self->{_conf}{'x_Type'}, 'x_Version' => $self->{_conf}{'x_Version'}, 'x_Description' => $self->{_conf}{'x_Description'}, 'x_Cust_id' => $sub_id, 'x_First_Name' => $f_name, 'x_Last_Name' => $l_name, 'x_Address' => $addr, 'x_City' => $city, 'x_State' => $state, 'x_Zip' => $zip, 'x_Card_Num' => $card_no, 'x_Card_Code' => $cvv2, 'x_Exp_Date' => $exp_date, 'x_Amount' => $amt); if ($DEBUG){ print "\nFORM> $form\n"; print "\nHEADERS> $headers\n"; } my($page1,$response,%reply_headers1) = post_https($host,'443',$script,'',$form); print "\nPAGE1> $page1...$response\n"; if ($DEBUG){ my($key) = undef; foreach $key (sort keys %reply_headers1){ print "$key -> $reply_headers1{$key}\n"; } } my($x) = undef; ############attempt to contact transact.dll at least 5 times, exit loop if sucessfull, else generate error####### for($x=0;$x<5;$x++){ my ($page2,$result,%reply_headers2) = get_https($host,'443',"$script?$form"); print "\nPAGE2> $page2...$result\n"; if($result =~ m/OK/){ @auth_array = split(/,/,$page2); $self->{_error} = $auth_array[2]; last; }else{ $self->{_error} = 99; } if ($DEBUG){ $key = undef; foreach $key (sort keys %reply_headers2){ print "$key -> $reply_headers2{$key}\n"; } } } if($self->{_error} > 1){ #-- if error --# ###### if the error is a system error, then notify system contact ###### if ($self->{_conf}{'x_response_reason_code'}{$self->{_error}}{'System'} == 1){ $self->system_notify($sub_id); } ###### if omitted field error, then get field name for custom message ###### if ($self->{_error} == 33){ $auth_array[3] =~ /^(.+)\scannot/; $self->{_err_txt} = $1; } return(0); }else{ ##### if success, return x_trans_id ##### return(1,$auth_array[6]); } } #---------------------------------------------------------------------------------- #this sub returns error text #----------------------------------------------------------------------------------- sub error{ my($self) = shift; my($t) = $self->{_conf}{'x_response_reason_code'}{$self->{_error}}{'Text'}; if ($self->{_err_txt}){ $t .= " $self->{_err_txt}"; } undef($self->{_error}); return($t); } #----------------------------------------------------------------------------------- #this sub emails system contact in the event of a system error #----------------------------------------------------------------------------------- sub system_notify{ my($self) = shift; my($sub_id) = shift; my($error) = $self->{_conf}{'x_response_reason_code'}{$self->{_error}}{'Text'}; if ($DEBUG){print "SUB_ID => $sub_id\nERROR => $error\n";} my($mailto) = 'ccgateway@cinergycom.com'; my($smail) = '/usr/lib/sendmail'; open (MAIL, "|$smail -f $mailto gmorris\@evansville.net") or die "Error sending email:$!"; print MAIL < To: Authorize.net Processing Gateway <$mailto> Subject: A system error has occurred The following error has occurred while processing a credit card transaction for customer $sub_id: Error $self->{_error}: $error Calling Program: $self->{_prog_name} EOM close MAIL; $self->{_error} = 98; } 1;