Fix required fields in USAePay refunds, RT#8819
authormark <mark>
Thu, 9 Sep 2010 22:22:07 +0000 (22:22 +0000)
committermark <mark>
Thu, 9 Sep 2010 22:22:07 +0000 (22:22 +0000)
USAePay.pm

index 0157a20..a1ac81a 100644 (file)
@@ -9,10 +9,33 @@ use URI::Escape;
 use vars qw($VERSION @ISA $DEBUG);
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.01';
+$VERSION = '0.02';
 
 $DEBUG = 0;
 
+sub _info {
+  {
+    'info_compat'           => '0.01',
+    'gateway_name'          => 'USAePay',
+    'gateway_url'           => 'http://www.usaepay.com',
+    'module_version'        => $VERSION,
+    'supported_types'       => [ 'CC', 'ECHECK' ],
+    'supported_actions'     => {
+                                  CC => [
+                                    'Normal Authorization',
+                                    'Authorization Only',
+                                    'Post Authorization',
+                                    'Credit',
+                                    'Void',
+                                    ],
+                                  ECHECK => [
+                                    'Normal Authorization',
+                                    'Credit',
+                                    ],
+    },
+  };
+}
+
 my $default_path = '/gate.php';
 my $default_cert_path = '/secure/gate.php';
 
@@ -21,8 +44,8 @@ sub set_defaults {
     $self->server('www.usaepay.com');
     $self->port('443');
     $self->path($default_path);
+    $self->build_subs(qw(avs_code cvv2_response));
 
-    $self->build_subs(qw(order_number));
 }
 
 sub map_fields {
@@ -43,6 +66,8 @@ sub map_fields {
   my %cc_actions = ('normal authorization' => 'sale',
                     'authorization only'   => 'authonly',
                     'post authorization'   => 'postauth',
+                    'credit'               => 'credit',
+                    'void'                 => 'void',
                    );
   my %ec_actions = ('normal authorization' => 'check',
                     'credit'               => 'checkcredit',
@@ -87,6 +112,7 @@ sub submit {
       routing_code     => 'UMrouting',
       account_number   => 'UMaccount',
       customer_ssn     => 'UMssn',
+      action           => 'UMcommand',
     );
     my %content = $self->content;
     if ( $DEBUG ) {
@@ -95,18 +121,20 @@ sub submit {
 
     my @required_fields = qw(type action login);
 
+    my $action = $self->{_content}->{action};
     if ($self->transaction_type() eq 'CC' ) {
-#      push @required_fields, qw/card_number expiration amount invoice_number name address zip/;
-      push @required_fields, qw/card_number expiration amount name address zip/;
-      if ($self->{_content}->{action} eq 'postauth') {
-        push @required_fields, qw/authorization/;
-      }
-      if (    $self->{_content}->{action} eq 'void'
-           || $self->{_content}->{action} eq 'capture') {
+      if ($action eq 'void' or $action eq 'capture') {
         push @required_fields, qw/order_number/;
       }
-    }elsif ($self->transaction_type() eq 'ECHECK' ) {
-#      push @required_fields, qw/routing_code account_number amount invoice_number name customer_ssn/;
+      else {
+        # sale, authonly, credit, postauth
+        push @required_fields, qw/card_number expiration amount address zip/;
+        if ($action eq 'postauth') {
+          push @required_fields, qw/authorization/;
+        }
+      }
+    } 
+    elsif ($self->transaction_type() eq 'ECHECK' ) {
       push @required_fields, qw/routing_code account_number amount name customer_ssn/;
     } else {
       croak("USAePay can't handle transaction type: ".
@@ -123,7 +151,12 @@ sub submit {
       UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir
       UMredirApproved UMredirDeclined UMechofields UMtestmode
     ) );
-    $post_data{'UMtestmode'} = $self->test_transaction() ? 1 : 0;
+    # test_transaction(0): normal mode
+    #                  1 : test mode (validates formatting only)
+    #                  2 : use sandbox server
+    #                  3 : test mode on sandbox server
+    $self->server('sandbox.usaepay.com') if ( $self->test_transaction & 2 );
+    $post_data{'UMtestmode'} = ($self->test_transaction() & 1) ? 1 : 0;
     $post_data{'UMsoftware'} = __PACKAGE__. " $VERSION";
     if ( $DEBUG ) {
       warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
@@ -155,6 +188,9 @@ sub submit {
     } else {
       $self->is_success(0);
     }
+    $self->order_number($response->{UMrefNum});
+    $self->avs_code($response->{UMavsResultCode});
+    $self->cvv2_response($response->{UMcvv2ResultCode});
     $self->result_code($response->{UMresult});
     $self->error_message($response->{UMerror});
     $self->server_response($response);