+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ ## move refund to credit batch.
+ my %pay_batch = (
+ 'status' => 'O',
+ 'payby' => 'CHEK',
+ 'type' => 'CREDIT',
+ );
+
+ my $pay_batch = qsearchs( 'pay_batch', \%pay_batch );
+
+ unless ( $pay_batch ) {
+ $pay_batch = new FS::pay_batch \%pay_batch;
+ my $error = $pay_batch->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ warn "error creating a check credit batch: $error\n";
+ }
+ }
+
+ my %card_pay_batch = (
+ 'status' => 'O',
+ 'payby' => 'CARD',
+ 'type' => 'CREDIT',
+ );