RT#57135: Credit card validation: take action based on AVS response [warnings in...
authorJonathan Prykop <jonathan@freeside.biz>
Sat, 28 May 2016 23:42:30 +0000 (18:42 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Sat, 28 May 2016 23:42:30 +0000 (18:42 -0500)
FS/FS/cust_main/Billing_Realtime.pm
FS/FS/log_context.pm

index 8cac982..c676607 100644 (file)
@@ -1918,6 +1918,8 @@ sub realtime_verify_bop {
     }
   }
 
     }
   }
 
+  my $log = FS::Log->new('FS::cust_main::Billing_Realtime::realtime_verify_bop');
+
   if ( $transaction->is_success() ) {
 
     $cust_pay_pending->status('authorized');
   if ( $transaction->is_success() ) {
 
     $cust_pay_pending->status('authorized');
@@ -1962,6 +1964,7 @@ sub realtime_verify_bop {
       my $e = "Authorization successful but reversal failed, custnum #".
               $self->custnum. ': '.  $reverse->result_code.
               ": ". $reverse->error_message;
       my $e = "Authorization successful but reversal failed, custnum #".
               $self->custnum. ': '.  $reverse->result_code.
               ": ". $reverse->error_message;
+      $log->warning($e);
       warn $e;
       return $e;
 
       warn $e;
       return $e;
 
@@ -2000,6 +2003,7 @@ sub realtime_verify_bop {
     # Neither address nor postal code matches N N N N
 
     if (my $avscode = uc($transaction->avs_code)) {
     # Neither address nor postal code matches N N N N
 
     if (my $avscode = uc($transaction->avs_code)) {
+
       # map codes to accept/warn/reject
       my $avs = {
         'American Express card' => {
       # map codes to accept/warn/reject
       my $avs = {
         'American Express card' => {
@@ -2053,13 +2057,18 @@ sub realtime_verify_bop {
       my $cardtype = cardtype($content{card_number});
       if ($avs->{$cardtype}) {
         my $avsact = $avs->{$cardtype}->{$avscode};
       my $cardtype = cardtype($content{card_number});
       if ($avs->{$cardtype}) {
         my $avsact = $avs->{$cardtype}->{$avscode};
+        my $warning = '';
         if ($avsact eq 'r') {
           return "AVS code verification failed, cardtype $cardtype, code $avscode";
         } elsif ($avsact eq 'w') {
         if ($avsact eq 'r') {
           return "AVS code verification failed, cardtype $cardtype, code $avscode";
         } elsif ($avsact eq 'w') {
-          warn "AVS code verification did not occur, cardtype $cardtype, code $avscode";
+          $warning = "AVS did not occur, cardtype $cardtype, code $avscode";
         } elsif (!$avsact) {
         } elsif (!$avsact) {
-          warn "AVS code verification did not occur, unknown avscode, cardtype $cardtype, code $avscode";
+          $warning = "AVS code unknown, cardtype $cardtype, code $avscode";
         } # else $avsact eq 'a'
         } # else $avsact eq 'a'
+        if ($warning) {
+          $log->warning($warning);
+          warn $warning;
+        }
       } # else $cardtype avs handling not implemented
     } # else !$transaction->avs_code
 
       } # else $cardtype avs handling not implemented
     } # else !$transaction->avs_code
 
@@ -2086,7 +2095,9 @@ sub realtime_verify_bop {
       $self->payinfo($transaction->card_token);
       my $error = $self->replace;
       if ( $error ) {
       $self->payinfo($transaction->card_token);
       my $error = $self->replace;
       if ( $error ) {
-        warn "WARNING: error storing token: $error, but proceeding anyway\n";
+        my $warning = "WARNING: error storing token: $error, but proceeding anyway\n";
+        $log->warning($warning);
+        warn $warning;
       }
     }
 
       }
     }
 
index 9dba582..ab1b0c3 100644 (file)
@@ -9,6 +9,7 @@ my @contexts = ( qw(
   bill_and_collect
   FS::cust_main::Billing::bill_and_collect
   FS::cust_main::Billing::bill
   bill_and_collect
   FS::cust_main::Billing::bill_and_collect
   FS::cust_main::Billing::bill
+  FS::cust_main::Billing_Realtime::realtime_verify_bop
   FS::pay_batch::import_from_gateway
   FS::Misc::Geo::standardize_uscensus
   Cron::bill
   FS::pay_batch::import_from_gateway
   FS::Misc::Geo::standardize_uscensus
   Cron::bill