FS RT #25694 - added two configuration options for requiring CVV data to be entered...
[freeside.git] / httemplate / misc / process / payment.cgi
index f4f9561..27b8186 100644 (file)
@@ -86,8 +86,8 @@ if ( $payby eq 'CHEK' ) {
     $cgi->param('payinfo2') =~ /^(\d+)$/
       or errorpage("Illegal ABA/routing number ". $cgi->param('payinfo2'));
     my $payinfo2 = $1;
-    if ( $conf->exists('cust_main-require-bank-branch') ) {
-      $cgi->param('payinfo3') =~ /^(\d+)$/
+    if ( $conf->config('echeck-country') eq 'CA' ) {
+      $cgi->param('payinfo3') =~ /^(\d{5})$/
         or errorpage("Illegal branch number ". $cgi->param('payinfo2'));
       $payinfo2 = "$1.$payinfo2";
     }
@@ -122,6 +122,8 @@ if ( $payby eq 'CHEK' ) {
           or errorpage("CVV2 (CVC2/CID) is three digits.");
         $paycvv = $1;
       }
+    }elsif( $conf->exists('backoffice-require_cvv') ){
+      errorpage("CVV2 is required");
     }
   }
 
@@ -210,7 +212,15 @@ if ( $cgi->param('save') ) {
     $new->set( 'paycvv' => '');
   }
 
-  $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}};
+  if ( $payby eq 'CARD' ) {
+    my $bill_location = FS::cust_location->new;
+    $bill_location->set( $_ => $cgi->param($_) )
+      foreach @{$payby2fields{$payby}};
+    $new->set('bill_location' => $bill_location);
+    # will do nothing if the fields are all unchanged
+  } else {
+    $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}};
+  }
 
   my $error = $new->replace($cust_main);
   errorpage("payment processed successfully, but error saving info: $error")