fix ACH refunds w/IPPay. B:OP 3.01 and IPPay 0.05_02 required. RT#_7673
[freeside.git] / FS / FS / cust_main.pm
index 746afd7..a45fcf2 100644 (file)
@@ -2475,33 +2475,33 @@ sub bill_and_collect {
   $error = $self->cancel_expired_pkgs( $options{actual_time} );
   if ( $error ) {
     $error = "Error expiring custnum ". $self->custnum. ": $error";
-    if    ( $options{'fatal'} eq 'return' ) { return $error; }
-    elsif ( $options{'fatal'}             ) { die    $error; }
-    else                                    { warn   $error; }
+    if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
+    elsif ( $options{fatal}                                ) { die    $error; }
+    else                                                     { warn   $error; }
   }
 
   $error = $self->suspend_adjourned_pkgs( $options{actual_time} );
   if ( $error ) {
     $error = "Error adjourning custnum ". $self->custnum. ": $error";
-    if    ( $options{'fatal'} eq 'return' ) { return $error; }
-    elsif ( $options{'fatal'}             ) { die    $error; }
-    else                                    { warn   $error; }
+    if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
+    elsif ( $options{fatal}                                ) { die    $error; }
+    else                                                     { warn   $error; }
   }
 
   $error = $self->bill( %options );
   if ( $error ) {
     $error = "Error billing custnum ". $self->custnum. ": $error";
-    if    ( $options{'fatal'} eq 'return' ) { return $error; }
-    elsif ( $options{'fatal'}             ) { die    $error; }
-    else                                    { warn   $error; }
+    if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
+    elsif ( $options{fatal}                                ) { die    $error; }
+    else                                                     { warn   $error; }
   }
 
   $error = $self->apply_payments_and_credits;
   if ( $error ) {
     $error = "Error applying custnum ". $self->custnum. ": $error";
-    if    ( $options{'fatal'} eq 'return' ) { return $error; }
-    elsif ( $options{'fatal'}             ) { die    $error; }
-    else                                    { warn   $error; }
+    if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
+    elsif ( $options{fatal}                                ) { die    $error; }
+    else                                                     { warn   $error; }
   }
 
   unless ( $conf->exists('cancelled_cust-noevents')
@@ -2510,9 +2510,9 @@ sub bill_and_collect {
     $error = $self->collect( %options );
     if ( $error ) {
       $error = "Error collecting custnum ". $self->custnum. ": $error";
-      if    ( $options{'fatal'} eq 'return' ) { return $error; }
-      elsif ( $options{'fatal'}             ) { die    $error; }
-      else                                    { warn   $error; }
+      if    ($options{fatal} && $options{fatal} eq 'return') { return $error; }
+      elsif ($options{fatal}                               ) { die    $error; }
+      else                                                   { warn   $error; }
     }
   }
 
@@ -3065,7 +3065,7 @@ sub _make_lines {
   my $old_cust_pkg = new FS::cust_pkg \%hash;
 
   my @details = ();
-
+  my @discounts = ();
   my $lineitems = 0;
 
   $cust_pkg->pkgpart($part_pkg->pkgpart);
@@ -3150,6 +3150,7 @@ sub _make_lines {
                               );
     my %param = ( 'precommit_hooks'     => $precommit_hooks,
                   'increment_next_bill' => $increment_next_bill,
+                  'discounts'           => \@discounts,
                 );
 
     my $method = $options{cancel} ? 'calc_cancel' : 'calc_recur';
@@ -3229,6 +3230,7 @@ sub _make_lines {
         'unitrecur' => $unitrecur,
         'quantity'  => $cust_pkg->quantity,
         'details'   => \@details,
+        'discounts' => \@discounts,
         'hidden'    => $part_pkg->hidden,
       };
 
@@ -3926,7 +3928,7 @@ sub due_cust_event {
 
   warn "    invalid conditions not eliminated with condition_sql:\n".
        join('', map "      $_: ".$unsat{$_}."\n", keys %unsat )
-    if $DEBUG; # > 1;
+    if keys %unsat && $DEBUG; # > 1;
 
   ##
   # insert
@@ -4107,6 +4109,8 @@ sub realtime_bop {
     warn "  $_ => $options{$_}\n" foreach keys %options;
   }
 
+  return "Amount must be greater than 0" unless $amount > 0;
+
   unless ( $options{'description'} ) {
     if ( $conf->exists('business-onlinepayment-description') ) {
       my $dtempl = $conf->config('business-onlinepayment-description');
@@ -4877,9 +4881,19 @@ sub realtime_refund_bop {
   ) {
     warn "  attempting void\n" if $DEBUG > 1;
     my $void = new Business::OnlinePayment( $processor, @bop_options );
-    $content{'card_number'} = $cust_pay->payinfo
-      if $cust_pay->payby eq 'CARD'
-      && $void->can('info') && $void->info('CC_void_requires_card');
+    if ( $void->can('info') ) {
+      if ( $cust_pay->payby eq 'CARD'
+           && $void->info('CC_void_requires_card') )
+      {
+        $content{'card_number'} = $cust_pay->payinfo
+      } elsif ( $cust_pay->payby eq 'CHEK'
+                && $void->info('ECHECK_void_requires_account') )
+      {
+        ( $content{'account_number'}, $content{'routing_code'} ) =
+          split('@', $cust_pay->payinfo);
+        $content{'name'} = $self->get('first'). ' '. $self->get('last');
+      }
+    }
     $void->content( 'action' => 'void', %content );
     $void->submit();
     if ( $void->is_success ) {
@@ -5043,10 +5057,12 @@ sub _new_bop_required {
   my $botpp = 'Business::OnlineThirdPartyPayment';
 
   return 1
-    if ( $conf->config('business-onlinepayment-namespace') eq $botpp ||
-         scalar( grep { $_->gateway_namespace eq $botpp } 
-                 qsearch( 'payment_gateway', { 'disabled' => '' } )
-               )
+    if (   (     $conf->exists('business-onlinepayment-namespace')
+             &&  $conf->config('business-onlinepayment-namespace') eq $botpp
+           )
+         or scalar( grep { $_->gateway_namespace eq $botpp } 
+                    qsearch( 'payment_gateway', { 'disabled' => '' } )
+                  )
        )
   ;
 
@@ -6218,9 +6234,19 @@ sub _new_realtime_refund_bop {
   ) {
     warn "  attempting void\n" if $DEBUG > 1;
     my $void = new Business::OnlinePayment( $processor, @bop_options );
-    $content{'card_number'} = $cust_pay->payinfo
-      if $cust_pay->payby eq 'CARD'
-      && $void->can('info') && $void->info('CC_void_requires_card');
+    if ( $void->can('info') ) {
+      if ( $cust_pay->payby eq 'CARD'
+           && $void->info('CC_void_requires_card') )
+      {
+        $content{'card_number'} = $cust_pay->payinfo;
+      } elsif ( $cust_pay->payby eq 'CHEK'
+                && $void->info('ECHECK_void_requires_account') )
+      {
+        ( $content{'account_number'}, $content{'routing_code'} ) =
+          split('@', $cust_pay->payinfo);
+        $content{'name'} = $self->get('first'). ' '. $self->get('last');
+      }
+    }
     $void->content( 'action' => 'void', %content );
     $void->submit();
     if ( $void->is_success ) {
@@ -8403,8 +8429,8 @@ sub _money_table_where {
 
 (Class method)
 
-Returns a qsearch hash expression to search for parameters specified in HREF.
-Valid parameters are
+Returns a qsearch hash expression to search for parameters specified in
+HASHREF.  Valid parameters are
 
 =over 4