RT#38363: use cust_payby when saving cards during payments [minor fixes]
[freeside.git] / FS / FS / cust_main.pm
index ee70dea..0c109ce 100644 (file)
@@ -2174,7 +2174,7 @@ sub cust_contact {
 Returns all payment methods (see L<FS::cust_payby>) for this customer.
 
 If one or more PAYBY are specified, returns only payment methods for specified PAYBY.
-Does not validate PAYBY--do not pass tainted values.
+Does not validate PAYBY.
 
 =cut
 
@@ -2186,7 +2186,7 @@ sub cust_payby {
     'hashref'  => { 'custnum' => $self->custnum },
     'order_by' => "ORDER BY payby IN ('CARD','CHEK') DESC, weight ASC",
   };
-  $search->{'extra_sql'} = ' AND payby IN ( ' . join(',', map { "'$_'" } @payby) . ' ) '
+  $search->{'extra_sql'} = ' AND payby IN ( ' . join(',', map { dbh->quote($_) } @payby) . ' ) '
     if @payby;
 
   qsearch($search);
@@ -5482,6 +5482,20 @@ sub _upgrade_data { #class method
 
       }
 
+      # at the time we do this, also migrate paytype into cust_pay_batch
+      # so that batches that are open before the migration can still be 
+      # processed
+      my @cust_pay_batch = qsearch('cust_pay_batch', {
+          'custnum' => $cust_main->custnum,
+          'payby'   => 'CHEK',
+          'paytype' => '',
+      });
+      foreach my $cust_pay_batch (@cust_pay_batch) {
+        $cust_pay_batch->set('paytype', $cust_main->get('paytype'));
+        my $error = $cust_pay_batch->replace;
+        die "$error (setting cust_pay_batch.paytype)" if $error;
+      }
+
       $cust_main->complimentary('Y') if $cust_main->payby eq 'COMP';
 
       $cust_main->invoice_attn( $cust_main->payname )