RT# 83044 - fixed cc refund issues
authorChristopher Burger <burgerc@freeside.biz>
Fri, 15 Mar 2019 15:29:50 +0000 (11:29 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Fri, 15 Mar 2019 15:29:50 +0000 (11:29 -0400)
FS/FS/cust_main/Billing_Batch.pm
FS/FS/cust_pay_batch.pm
FS/FS/pay_batch.pm
FS/bin/freeside-paymentech-upload
FS/bin/freeside-rbc-upload
httemplate/edit/process/cust_refund.cgi
httemplate/misc/download-batch.cgi
httemplate/search/elements/cust_pay_batch_top.html

index c1bb35f..c8292cd 100644 (file)
@@ -151,7 +151,7 @@ sub batch_card {
                   ),
     'exp'      => $options{paydate}  || $cust_payby->paydate,
     'payname'  => $options{payname}  || $cust_payby->payname,
-    'paytype'  => $options{paytype}  || $cust_payby->paytype,
+    'paytype'  => $options{paytype}  || $cust_payby->{'Hash'}->{'paytype'},
     'amount'   => $amount,                         # consolidating
     'paycode'  => $options{paycode}  || '',
   } );
index 6e76b34..2931fe7 100644 (file)
@@ -293,6 +293,9 @@ sub approve {
   if ( $error ) {
     return "error approving paybatchnum $paybatchnum: $error\n";
   }
+
+  return if $new->paycode eq "C";
+
   my $cust_pay = new FS::cust_pay ( {
       'custnum'   => $new->custnum,
       'payby'     => $new->payby,
index d0ed7ae..0df9c7a 100644 (file)
@@ -1278,20 +1278,38 @@ sub _upgrade_data {
       my $error = $pay_batch->insert;
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
-          warn "error creating a credit batch: $error\n";
+          warn "error creating a check credit batch: $error\n";
+      }
+    }
+
+    my %card_pay_batch = (
+      'status' => 'O',
+      'payby'  => 'CARD',
+      'type'   => 'CREDIT',
+    );
+
+    my $card_pay_batch = qsearchs( 'pay_batch', \%card_pay_batch );
+
+    unless ( $card_pay_batch ) {
+      $card_pay_batch = new FS::pay_batch \%card_pay_batch;
+      my $error = $card_pay_batch->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+          warn "error creating a card credit batch: $error\n";
       }
     }
 
     my $replace_error;
     foreach my $cust_pay_batch (@batch_refunds) {
-      $cust_pay_batch->batchnum($pay_batch->batchnum);
+      if ($cust_pay_batch->payby eq "CARD") { $cust_pay_batch->batchnum($card_pay_batch->batchnum); }
+      else { $cust_pay_batch->batchnum($pay_batch->batchnum); }
       $replace_error = $cust_pay_batch->replace();
       if ( $replace_error ) {
         $dbh->rollback if $oldAutoCommit;
           warn "Unable o move credit to a credit batch: $replace_error";
       }
       else {
-        warn "Moved cust pay credit ".$cust_pay_batch->paybatchnum." to credit batch ".$cust_pay_batch->batchnum."\n";
+        warn "Moved cust pay credit ".$cust_pay_batch->paybatchnum." to ".$cust_pay_batch->payby." credit batch ".$cust_pay_batch->batchnum."\n";
       }
     }
 
index 9903dd4..283781d 100755 (executable)
@@ -41,8 +41,17 @@ my @batches;
 if($opt_a) {
   my %criteria = (status => 'O');
   $criteria{'payby'} = uc($opt_p) if $opt_p;
-  $criteria{'type'} = 'DEBIT' unless FS::pay_batch->can_handle_electronic_refunds('paymentech');
-  @batches = qsearch('pay_batch', \%criteria);
+
+  my $extra_sql;
+  $extra_sql = " AND ((payby = 'CHEK' AND type != 'CREDIT') OR (payby != 'CHEK'))" unless FS::pay_batch->can_handle_electronic_refunds('paymentech');
+
+  my %hash = (
+    table => 'pay_batch',
+    hashref   => \%criteria,
+    extra_sql => $extra_sql,
+  );
+
+  @batches = qsearch(\%hash);
   log_and_die("No open batches found".($opt_p ? " of type '$opt_p'" : '').".\n")
     if !@batches;
 }
index 5c0ebdd..1d3d0ed 100755 (executable)
@@ -33,8 +33,17 @@ my @batches;
 if($opt_a) {
   my %criteria = (status => 'O');
   $criteria{'payby'} = uc($opt_p) if $opt_p;
-  $criteria{'type'} = 'DEBIT' unless FS::pay_batch->can_handle_electronic_refunds('RBC');
-  @batches = qsearch('pay_batch', \%criteria);
+
+  my $extra_sql;
+  $extra_sql = " AND ((payby = 'CHEK' AND type != 'CREDIT') OR (payby != 'CHEK'))" unless FS::pay_batch->can_handle_electronic_refunds('RBC');
+
+  my %hash = (
+    table => 'pay_batch',
+    hashref   => \%criteria,
+    extra_sql => $extra_sql,
+  );
+
+  @batches = qsearch(\%hash);
   die "No open batches found".($opt_p ? " of type '$opt_p'" : '').".\n" 
     if !@batches;
 }
@@ -45,7 +54,7 @@ else {
   die "Can't find payment batch '$batchnum'\n" if !@batches;
   if ($batches[0]->type eq "CREDIT") {
     warn "running credit\n";
-    log_and_die( "Batch number $batchnum is a credit (batch refund) batch, and this format can not handle batch refunds.\n" )
+    die( "Batch number $batchnum is a credit (batch refund) batch, and this format can not handle batch refunds.\n" )
       unless FS::pay_batch->can_handle_electronic_refunds('RBC');
   }
 }
index 25f6e00..f248d54 100755 (executable)
@@ -55,7 +55,7 @@ if ( $error ) {
              'CHEK' => 'electronic check (ACH)',
              );
 
-my( $cust_pay, $cust_payby, $payinfo, $paycvv, $month, $year, $payname );
+my( $cust_pay, $cust_payby, $payinfo, $paycvv, $month, $year, $payname, $paycardtype );
 my $paymask = '';
 
 ## get cust pay info if paynum exists
@@ -89,6 +89,7 @@ if ( (my $custpaybynum = scalar($cgi->param('custpaybynum'))) > 0 ) {
 } elsif ( $cgi->param('paynum') > 0) {
 
   $payinfo = $cust_pay->payinfo;
+  $paycardtype = $cust_pay->paycardtype;
   $payname = $cust_pay->payname;
 
 } else {
@@ -235,6 +236,10 @@ if ( (my $custpaybynum = scalar($cgi->param('custpaybynum'))) > 0 ) {
       $_, scalar($cgi->param($_))
     } fields('cust_refund');
 
+    $hash{'payinfo'} = $payinfo;
+    $hash{'paymask'} = $paymask;
+    $hash{'paycardtype'} = $paycardtype;
+
     ## unapply payment before creating refund.
     while ( $cust_pay && $cust_pay->unapplied < $refund ) {
       my @cust_bill_pay = $cust_pay->cust_bill_pay;
index e4882d1..6ff6498 100644 (file)
@@ -28,11 +28,6 @@ my $pay_batch = qsearchs({ 'select'    => "*, $credit_transactions",
                          });
 die "Batch not found: '$batchnum'" if !$pay_batch;
 
-if ($pay_batch->{Hash}->{arecredits}) {
-  my $export_format = "FS::pay_batch::".$opt{'format'};
-  die "You are trying to download a credit (batch refund) batch and The format ".$opt{'format'}." can not handle refunds.\n" unless $export_format->can('can_handle_credits');
-}
-
 my $exporttext = $pay_batch->export_batch(%opt);
 unless ($exporttext) {
   http_header('Content-Type' => 'text/html' );
index 90fc9e4..d29e487 100644 (file)
@@ -146,7 +146,7 @@ tie my %upload_formats, 'Tie::IxHash', (
 delete $upload_formats{'td_eft1464'};
 $upload_formats{'PAP'} = '264 byte results for TD Canada Trust PAP Batch';
 
-if ($pay_batch->type eq "CREDIT") {
+if ($pay_batch->type eq "CREDIT" && $pay_batch->payby eq "CHEK") {
   foreach my $key (keys %download_formats) {
     delete $download_formats{$key} unless FS::pay_batch->can_handle_electronic_refunds($key);
     ## remove default format if unable to handle electronic refunds