fix a series of unfortunate upgrades which resulted in too much payment receiptery...
[freeside.git] / FS / FS / pay_batch.pm
index 9a0b235..2561d3d 100644 (file)
@@ -7,6 +7,7 @@ use Text::CSV_XS;
 use FS::Record qw( dbh qsearch qsearchs );
 use FS::cust_pay;
 use FS::Conf;
+use Business::CreditCard qw(cardtype);
 
 @ISA = qw(FS::Record);
 
@@ -198,6 +199,8 @@ sub import_results {
   my $job = $param->{'job'};
   $job->update_statustext(0) if $job;
 
+  my $conf = new FS::Conf;
+
   my $filetype            = $info->{'filetype'};      # CSV or fixed
   my @fields              = @{ $info->{'fields'}};
   my $formatre            = $info->{'formatre'};      # for fixed
@@ -357,8 +360,13 @@ sub import_results {
     }
 
     # purge CVV when the batch is processed
-    $new_cust_pay_batch->cust_main->remove_cvv
-      if ( $payby eq 'CARD' or $payby eq 'DCRD' );
+    if ( $payby =~ /^(CARD|DCRD)$/ ) {
+      my $payinfo = $hash{'payinfo'} || $cust_pay_batch->payinfo;
+      if ( ! grep { $_ eq cardtype($payinfo) }
+          $conf->config('cvv-save') ) {
+        $new_cust_pay_batch->cust_main->remove_cvv;
+      }
+    }
 
     if ( $new_cust_pay_batch->status =~ /Approved/i ) {
 
@@ -406,11 +414,11 @@ sub import_results {
           return $error;
        }
 
-      } # foreach $cust_event
+      }
 
-    } # if(status eq 'Approved')
+    }
 
-  } # foreach(@all_values)
+  }
   
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';