RT# 80669 Cancelled customers on customer churn report
[freeside.git] / httemplate / misc / process / payment.cgi
index b7d427e..9458217 100644 (file)
@@ -110,7 +110,7 @@ if ( $payby eq 'CHEK' ) {
   validate($payinfo)
     or errorpage(gettext('invalid_card'));
 
-  unless ( $self->payinfo =~ /^99\d{14}$/ ) { #token
+  unless ( $payinfo =~ /^99\d{14}$/ ) { #token
 
     my $cardtype = cardtype($payinfo);
 
@@ -164,7 +164,10 @@ if ( $cgi->param('save') ) {
   #false laziness w/FS:;cust_main::realtime_bop - check both to make sure
   # working correctly
   if ( $payby eq 'CARD' &&
-       grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) {
+       ( (grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save')) 
+         || $conf->exists('business-onlinepayment-verification') 
+       )
+  ) {
     $new->set( 'paycvv' => $paycvv );
   } else {
     $new->set( 'paycvv' => '');
@@ -172,12 +175,12 @@ if ( $cgi->param('save') ) {
 
   if ( $payby eq 'CARD' ) {
     my $bill_location = FS::cust_location->new;
-    $bill_location->set( $_ => $cgi->param($_) )
+    $bill_location->set( $_ => scalar($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}};
+    $new->set( $_ => scalar($cgi->param($_)) ) foreach @{$payby2fields{$payby}};
   }
 
   my $error = $new->replace($cust_main);
@@ -199,7 +202,7 @@ if ( $cgi->param('batch') ) {
                                      'payinfo'  => $payinfo,
                                      'paydate'  => "$year-$month-01",
                                      'payname'  => $payname,
-                                     map { $_ => $cgi->param($_) } 
+                                     map { $_ => scalar($cgi->param($_)) } 
                                        @{$payby2fields{$payby}}
                                    );
   errorpage($error) if $error;
@@ -218,7 +221,9 @@ if ( $cgi->param('batch') ) {
     'paycvv'     => $paycvv,
     'paynum_ref' => \$paynum,
     'discount_term' => $discount_term,
-    map { $_ => $cgi->param($_) } @{$payby2fields{$payby}}
+    'no_auto_apply' => ($cgi->param('apply') eq 'never') ? 'Y' : '',
+    'no_invnum'     => 1,
+    map { $_ => scalar($cgi->param($_)) } @{$payby2fields{$payby}}
   );
   errorpage($error) if $error;
 
@@ -233,12 +238,12 @@ if ( $cgi->param('batch') ) {
 
     #and generate an invoice for it now too
     $error = $cust_main->bill( 'pkg_list' => [ $cust_pkg ] );
-    errorpage("payment processed and fee ordered sucessfully, but error billing fee: $error")
+    errorpage("payment processed and fee ordered successfully, but error billing fee: $error")
       if $error;
 
   }
 
-  $cust_main->apply_payments;
+  $cust_main->apply_payments if ($cgi->param('apply') eq 'yes');
 
 }