#33286: Direct Debit by BillBuddy for Bank Accounts
[freeside.git] / FS / FS / pay_batch.pm
index 3ce71b0..364e7f6 100644 (file)
@@ -574,7 +574,14 @@ sub import_from_gateway {
 
   my $processor = $gateway->batch_processor(%proc_opt);
 
-  my @batches = $processor->receive;
+  my @processor_ids = map { $_->processor_id } 
+                        qsearch({
+                          'table' => 'pay_batch',
+                          'hashref' => { 'status' => 'I' },
+                          'extra_sql' => q( AND processor_id != '' AND processor_id IS NOT NULL)
+                        });
+
+  my @batches = $processor->receive(@processor_ids);
 
   my $num = 0;
 
@@ -1059,6 +1066,11 @@ sub export_to_gateway {
   );
   $processor->submit($batch);
 
+  if ($batch->processor_id) {
+    $self->set('processor_id',$batch->processor_id);
+    $self->replace;
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
 }