#42638: Update URLs for B::OP AuthorizeNet
[Business-OnlinePayment-AuthorizeNet.git] / AuthorizeNet / AIM.pm
index 2906079..e7ecd56 100644 (file)
@@ -2,22 +2,19 @@ package Business::OnlinePayment::AuthorizeNet::AIM;
 
 use strict;
 use Carp;
+use Business::OnlinePayment::HTTPS;
 use Business::OnlinePayment::AuthorizeNet;
-use Net::SSLeay qw/make_form post_https make_headers/;
+use Business::OnlinePayment::AuthorizeNet::AIM::ErrorCodes '%ERRORS';
 use Text::CSV_XS;
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
 
-require Exporter;
-
-@ISA = qw(Exporter Business::OnlinePayment::AuthorizeNet);
-@EXPORT = qw();
-@EXPORT_OK = qw();
-$VERSION = '3.21';
+@ISA = qw(Business::OnlinePayment::AuthorizeNet Business::OnlinePayment::HTTPS);
+$VERSION = '3.24';
 
 sub set_defaults {
     my $self = shift;
 
-    $self->server('secure.authorize.net') unless $self->server;
+    $self->server('secure2.authorize.net') unless $self->server;
     $self->port('443') unless $self->port;
     $self->path('/gateway/transact.dll') unless $self->path;
 
@@ -38,7 +35,7 @@ sub map_fields {
                    'post authorization'   => 'PRIOR_AUTH_CAPTURE',
                    'void'                 => 'VOID',
                   );
-    $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
+    $content{'action'} = $actions{lc($content{'action'} || '')} || $content{'action'};
 
     # TYPE MAP
     my %types = ('visa'               => 'CC',
@@ -47,7 +44,7 @@ sub map_fields {
                  'discover'           => 'CC',
                  'check'              => 'ECHECK',
                 );
-    $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
+    $content{'type'} = $types{lc($content{'type'} || '')} || $content{'type'};
     $self->transaction_type($content{'type'});
 
     # ACCOUNT TYPE MAP
@@ -56,13 +53,9 @@ sub map_fields {
                          'business checking'   => 'CHECKING',
                          'business savings'    => 'SAVINGS',
                         );
-    $content{'account_type'} = $account_types{lc($content{'account_type'})}
+    $content{'account_type'} = $account_types{lc($content{'account_type'} || '')}
                                || $content{'account_type'};
 
-    $content{'referer'} = defined( $content{'referer'} )
-                            ? make_headers( 'Referer' => $content{'referer'} )
-                            : "";
-
     if (length $content{'password'} == 15) {
         $content{'transaction_key'} = delete $content{'password'};
     }
@@ -173,7 +166,10 @@ sub submit {
             length  $self->{_content}->{customer_org}
         ) {
           push @required_fields, qw( customer_org customer_ssn );
-        } else {
+        }
+        elsif ( defined $self->{_content}->{license_num} and
+                length  $self->{_content}->{license_num}
+        ) {
           push @required_fields, qw(license_num license_state license_dob);
         }
 
@@ -259,12 +255,13 @@ sub submit {
     $post_data{'x_ADC_URL'} = 'FALSE';
     $post_data{'x_Version'} = '3.1';
 
-    my $pd = make_form(%post_data);
-    my $s = $self->server();
-    my $p = $self->port();
-    my $t = $self->path();
-    my $r = $self->{_content}->{referer};
-    my($page,$server_response,%headers) = post_https($s,$p,$t,$r,$pd);
+    my $opt = defined( $self->{_content}->{referer} )
+                ? { 'headers' => { 'Referer' => $self->{_content}->{referer} } }
+                : {};
+
+    my($page, $server_response, %headers) =
+      $self->https_post( $opt, \%post_data );
+
     #escape NULL (binary 0x00) values
     $page =~ s/\x00/\^0/g;
 
@@ -294,7 +291,11 @@ sub submit {
         $self->is_success(0);
         $self->result_code($col[2]);
         $self->error_message($col[3]);
-        unless ( $self->result_code() ) { #additional logging information
+        if ( $self->result_code ) {
+          my $addl = $ERRORS{ $self->result_code };
+          $self->error_message( $self->error_message. ' - '. $addl->{notes})
+            if $addl && ref($addl) eq 'HASH' && $addl->{notes};
+        } else { #additional logging information
           #$page =~ s/\x00/\^0/g;
           $self->error_message($col[3].
             " DEBUG: No x_response_code from server, ".
@@ -314,34 +315,6 @@ __END__
 
 Business::OnlinePayment::AuthorizeNet::AIM - AuthorizeNet AIM backend for Business::OnlinePayment
 
-=head1 AUTHOR
-
-Jason Kohles, jason@mediabang.com
-
-Ivan Kohler <ivan-authorizenet@420.am> updated it for Authorize.Net protocol
-3.0/3.1 and is the current maintainer.  Please send patches as unified diffs
-(diff -u).
-
-Jason Spence <jspence@lightconsulting.com> contributed support for separate
-Authorization Only and Post Authorization steps and wrote some docs.
-OST <services@ostel.com> paid for it.
-
-T.J. Mather <tjmather@maxmind.com> sent a number of CVV2 patches.
-
-Mike Barry <mbarry@cos.com> sent in a patch for the referer field.
-
-Yuri V. Mkrtumyan <yuramk@novosoft.ru> sent in a patch to add the void action.
-
-Paul Zimmer <AuthorizeNetpm@pzimmer.box.bepress.com> sent in a patch for
-card-less post authorizations.
-
-Daemmon Hughes <daemmon@daemmonhughes.com> sent in a patch for "transaction
-key" authentication as well support for the recurring_billing flag and the md5
-method that returns the MD5 hash which is returned by the gateway.
-
-Steve Simitzis contributed a patch for better compatibility with
-eProcessingNetwork's AuthorizeNet compatability mode.
-
 =head1 SEE ALSO
 
 perl(1). L<Business::OnlinePayment> L<Business::OnlinePayment::AuthorizeNet>.