ignore weight when editing DCRD/DCHK payment methods, #71176
[freeside.git] / FS / FS / cust_payby.pm
index 50d9ee0..62fa9be 100644 (file)
@@ -196,10 +196,6 @@ sub replace {
               ? shift
               : $self->replace_old;
 
-  if ( length($old->paycvv) && $self->paycvv =~ /^\s*[\*x]*\s*$/ ) {
-    $self->paycvv($old->paycvv);
-  }
-
   if ( $self->payby =~ /^(CARD|DCRD)$/
        && (    $self->payinfo =~ /xx/
             || $self->payinfo =~ /^\s*N\/A\s+\(tokenized\)\s*$/
@@ -221,6 +217,17 @@ sub replace {
     $self->payinfo($new_account.'@'.$new_aba);
   }
 
+  # only unmask paycvv if payinfo stayed the same
+  if ( $self->payby =~ /^(CARD|DCRD)$/ and $self->paycvv =~ /^\s*[\*x]+\s*$/ ) {
+    if ( $old->payinfo eq $self->payinfo
+         && $old->paymask eq $self->paymask
+    ) {
+      $self->paycvv($old->paycvv);
+    } else {
+      $self->paycvv('');
+    }
+  }
+
   local($ignore_expired_card) = 1
     if $old->payby  =~ /^(CARD|DCRD)$/
     && $self->payby =~ /^(CARD|DCRD)$/
@@ -708,6 +715,9 @@ sub cgi_hash_callback {
     'CARD' => 'DCRD',
     'CHEK' => 'DCHK',
   );
+  # the payby selector gives the choice of CARD or CHEK (or others, but
+  # those are the ones with auto and on-demand versions). if the user didn't
+  # choose a weight, then they mean DCRD/DCHK.
   $hashref->{payby} = $noauto{$hashref->{payby}}
     if ! $hashref->{weight} && exists $noauto{$hashref->{payby}};
 
@@ -831,6 +841,9 @@ sub search_sql {
       ' LEFT JOIN cust_location AS '.$pre.'location '.
       'ON (cust_main.'.$pre.'locationnum = '.$pre.'location.locationnum) ';
   }
+  # always make referral available in results
+  #   (maybe we should be using FS::UI::Web::join_cust_main instead?)
+  $addl_from .= ' LEFT JOIN (select refnum, referral from part_referral) AS part_referral_x ON (cust_main.refnum = part_referral_x.refnum) ';
 
   my $count_query = "SELECT COUNT(*) FROM cust_payby $addl_from $extra_sql";