I am having a problem interfacing with Authorize.net as well. I am creating a perl module using Net::SSLeay in a similay way as listed in this thread and other sources I have found.
The problem comes when I perform a post_https operation. Every time I attempt to post, I receive the error message "Invalid Merchant Login or Account Inactive". However, I turn right around and perform a get_https operation using the same information and achieve desired results (i.e. a delimited response string).
Am I doing something wrong? Will using the get_https method produce the desired results? I can provide more info on what I am doing, if needed. Please someone help!!!
Below is my module code:
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 pa
+rm");
$self->{_conf_path} = $parm->{conf_path} or croak("No conf_path pa
+rm");
$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 D
+ate, 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 (compatib
+le; 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_Descri
+ption'},
'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',$scr
+ipt,'',$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, exi
+t 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->{_erro
+r}}{'System'} == 1){
$self->system_notify($sub_id);
}
###### if omitted field error, then get field name for cus
+tom 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->{_err
+or}}{'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 <<EOM;
From: Authorize.net Processing Gateway <$mailto>
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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.