0.07
[Business-OnlinePayment-vSecureProcessing.git] / lib / Business / OnlinePayment / vSecureProcessing.pm
index 0ae9adc..696da87 100644 (file)
@@ -11,7 +11,26 @@ use Business::OnlinePayment::HTTPS;
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
 $DEBUG = 0;
-$VERSION = '0.05';
+$VERSION = '0.07';
+
+sub _info {
+  'info_compat'       => '0.01',
+  'gateway_name'      => 'vSecure Processing',
+  'gateway_url'       => 'http://www.vsecureprocessing.com/',
+  'module_version'    => $VERSION,
+  'supported_types'   => [qw( CC )],
+  'token_support'     => 0,
+  'test_transaction'  => 1,
+  'partial_auth'      => 1,
+  'supported_actions' => [
+                           'Normal Authorization',
+                           #'Authorization Only',
+                           #'Post Authorization',
+                           'Reverse Authorization',
+                           'Void',
+                           'Credit',
+                         ],
+}
 
 # mapping out all possible endpoints
 # but this version will only be building out "charge", "void", & "credit"
@@ -98,7 +117,7 @@ sub set_defaults {
     $self->build_subs(qw/
             platform tid appid
             action reference_number cvv2_response avs_code response_code
-            risk_score txn_amount txn_date
+            risk_score txn_amount txn_date partial_auth partial_auth_amount
     /);
     
     $DEBUG = exists($options{debug}) ? $options{debug} : $DEBUG;
@@ -314,6 +333,41 @@ sub submit {
     $self->server_response($server_response);
     # parse the result page.
     $self->parse_response($page);
+
+    if ( $self->is_success && $self->response_code == 10 ) { #partial auth
+
+      if ( $self->partial_auth ) {
+
+        $self->partial_auth_amount( $self->txn_amount );
+
+      } else {
+        #XXX reverse auth if i was an auth only...
+        my $void = new Business::OnlinePayment(
+                         'vSecureProcessing',
+                         map { $_ -> $self->$_() } qw( platform appid tid )
+                   );
+
+        $void->content(
+          'action'           => 'Void',
+          'amount'           => $self->txn_amount,
+          'test_transaction' => $self->test_transaction,
+          'authorization'    => $self->authorization,
+          map { $_ => $content{$_} } qw( login password card_number expiration )
+        );
+      
+        $void->submit;
+
+        if ( !$void->is_success ) {
+          #XXX now what??? at least this is better than return is_success 0 or 1
+          die "Couldn't void partial auth";
+        } else {
+          $self->is_success(0);
+        }
+
+      }
+
+    }
     
     if (!$self->is_success() && !$self->error_message() ) {
         if ( $DEBUG ) {
@@ -361,17 +415,17 @@ sub parse_response {
         $self->is_success($self->result_code() eq '0' ? 1 : 0);
         if ($self->is_success()) {
             $self->authorization($response->{ReferenceNumber});
-        }
-        # fill in error_message if there is is an error
-        if ( !$self->is_success && exists($response->{AdditionalResponseData})) {
-            $self->error_message('Error '.$response->{ResponseCode}.': '.$response->{AdditionalResponseData});
-        }elsif ( !$self->is_success && exists($response->{Receipt}) ) {
-            $self->error_message('Error '.$response->{ResponseCode}.': '.(exists($response->{Receipt})) ? $response->{Receipt} : '');
+        } else { # fill in error_message if there is is an error
+            $self->error_message( 'Error '.$response->{ResponseCode}.': '.
+                                    (    $response->{AdditionalResponseData}
+                                      || $response->{Receipt}
+                                      || $response->{ResultCode}
+                                    )
+                                );
         }
         
     } else {
-        die 'Error communicating with vSecureProcessing server';
-        return;
+        die 'Error communicating with vSecureProcessing server (server sent response: '. $self->server_response. ')';
     }
     
 }