retry realtime_card invoice events when a card changes (closes: Bug#417)
authorivan <ivan>
Mon, 10 Jun 2002 22:07:24 +0000 (22:07 +0000)
committerivan <ivan>
Mon, 10 Jun 2002 22:07:24 +0000 (22:07 +0000)
FS/FS/cust_bill_event.pm
FS/FS/cust_main.pm

index d5ca55f..f631987 100644 (file)
@@ -143,6 +143,21 @@ sub cust_bill {
   qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
 }
 
   qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
 }
 
+=item retry
+
+Changes the status of this event from B<done> to B<failed>, allowing it to be
+retried.
+
+=cut
+
+sub retry {
+  my $self = shift;
+  return '' unless $self->status eq 'done';
+  my $old = ref($self)->new( { $self->hash } );
+  $self->status('failed');
+  $self->replace($old);
+}
+
 =back
 
 =head1 BUGS
 =back
 
 =head1 BUGS
index 0faa60c..8a0124a 100644 (file)
@@ -482,6 +482,27 @@ sub replace {
     $self->invoicing_list( $invoicing_list );
   }
 
     $self->invoicing_list( $invoicing_list );
   }
 
+  if ( $self->payby eq 'CARD' &&
+       grep { $self->get($_) ne $old->get($_) } qw(payinfo paydate payname) ) {
+    # card info has changed, want to retry realtime_card invoice events
+    foreach my $cust_bill_event (
+      grep {
+             #$_->part_bill_event->plan eq 'realtime-card'
+             $_->part_bill_event->eventcode eq '$cust_bill->realtime_card();'
+               && $_->status eq 'done'
+               && $_->statustext
+           }
+        $self->open_cust_bill->cust_bill_event
+    ) {
+      my $error = $cust_bill_event->retry;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error scheduling invoice events for retry: $error";
+      }
+    }
+
+  }
+
   #false laziness with sub insert
   my $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
   $error = $queue->insert($self->getfield('last'), $self->company);
   #false laziness with sub insert
   my $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
   $error = $queue->insert($self->getfield('last'), $self->company);
@@ -1203,9 +1224,7 @@ sub collect {
     return '';
   }
 
     return '';
   }
 
-  foreach my $cust_bill (
-    qsearch('cust_bill', { 'custnum' => $self->custnum, } )
-  ) {
+  foreach my $cust_bill ( $self->cust_bill ) {
 
     #this has to be before next's
     my $amount = sprintf( "%.2f", $balance < $cust_bill->owed
 
     #this has to be before next's
     my $amount = sprintf( "%.2f", $balance < $cust_bill->owed
@@ -1708,6 +1727,29 @@ sub charge {
 
 }
 
 
 }
 
+=item cust_bill
+
+Returns all the invoices (see L<FS::cust_bill>) for this customer.
+
+=cut
+
+sub cust_bill {
+  my $self = shift;
+  qsearch('cust_bill', { 'custnum' => $self->custnum, } )
+}
+
+=item open_cust_bill
+
+Returns all the open (owed > 0) invoices (see L<FS::cust_bill>) for this
+customer.
+
+=cut
+
+sub open_cust_bill {
+  my $self = shift;
+  grep { $_->owed > 0 } $self->cust_bill;
+}
+
 =back
 
 =head1 SUBROUTINES
 =back
 
 =head1 SUBROUTINES