When IPPay returns a non-sensical response, don't include it in the error message...
[Business-OnlinePayment-IPPay.git] / IPPay.pm
index 3d1582d..2dd2c85 100644 (file)
--- a/IPPay.pm
+++ b/IPPay.pm
@@ -54,12 +54,9 @@ sub set_defaults {
                           response_page response_code response_headers
                      ));
 
-    # module specific data
-    if ( $opts{debug} ) {
-        $self->debug( $opts{debug} );
-        delete $opts{debug};
-    }
+    $DEBUG = exists($opts{debug}) ? $opts{debug} : 0;
 
+    # module specific data
     my %_defaults = ();
     foreach my $key (keys %opts) {
       $key =~ /^default_(\w*)$/ or next;
@@ -240,7 +237,7 @@ sub submit {
          "(HTTPS headers: ".
          join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
          "(Raw HTTPS content: $page)"
-      if $DEBUG;
+      if $DEBUG > 1;
     return unless $server_response=~ /^200/;
     $transaction_id = $page;
   }
@@ -387,11 +384,11 @@ sub submit {
   $writer->endTag('JetPay');
   $writer->end();
 
-  warn "$post_data\n" if $DEBUG;
+  warn "$post_data\n" if $DEBUG > 1;
 
   my ($page,$server_response,%headers) = $self->https_post($post_data);
 
-  warn "$page\n" if $DEBUG;
+  warn "$page\n" if $DEBUG > 1;
 
   my $response = {};
   if ($server_response =~ /^200/){
@@ -414,13 +411,20 @@ sub submit {
   $self->is_success($self->result_code() eq '000' ? 1 : 0);
 
   unless ($self->is_success()) {
-    unless ( $self->error_message() ) { #additional logging information
-      $self->error_message(
-        "(HTTPS response: $server_response) ".
-        "(HTTPS headers: ".
-          join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
-        "(Raw HTTPS content: $page)"
-      );
+    unless ( $self->error_message() ) {
+      if ( $DEBUG ) {
+        #additional logging information, possibly too sensitive for an error msg
+        # (IPPay seems to have a failure mode where they return the full
+        #  original request including card number)
+        $self->error_message(
+          "(HTTPS response: $server_response) ".
+          "(HTTPS headers: ".
+            join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
+          "(Raw HTTPS content: $page)"
+        );
+      } else {
+        $self->error_message('No ResponseText or ErrMsg was returned by IPPay (enable debugging for raw HTTPS response)');
+      }
     }
   }