summaryrefslogtreecommitdiff
path: root/FS/FS/pay_batch.pm
diff options
context:
space:
mode:
authormark <mark>2010-11-12 23:33:53 +0000
committermark <mark>2010-11-12 23:33:53 +0000
commit5188e8406a1fa2bee63ea81090ffefe3d4bf1b89 (patch)
treea1e17929eaca5e3c5ee73a6ef355365b3f26c4ec /FS/FS/pay_batch.pm
parent718210a60786d78e33031ab60a7614bd009b4851 (diff)
TD EFT batch format, RT#10545
Diffstat (limited to 'FS/FS/pay_batch.pm')
-rw-r--r--FS/FS/pay_batch.pm31
1 files changed, 28 insertions, 3 deletions
diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index b5ef85b..d142411 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -202,9 +202,10 @@ sub import_results {
my $conf = new FS::Conf;
- my $filetype = $info->{'filetype'}; # CSV or fixed
+ my $filetype = $info->{'filetype'}; # CSV, fixed, variable
my @fields = @{ $info->{'fields'}};
my $formatre = $info->{'formatre'}; # for fixed
+ my $parse = $info->{'parse'}; # for variable
my @all_values;
my $begin_condition = $info->{'begin_condition'};
my $end_condition = $info->{'end_condition'};
@@ -213,6 +214,7 @@ sub import_results {
my $hook = $info->{'hook'};
my $approved_condition = $info->{'approved'};
my $declined_condition = $info->{'declined'};
+ my $close_condition = $info->{'close_condition'};
my $csv = new Text::CSV_XS;
@@ -286,7 +288,17 @@ sub import_results {
};
push @values, $line;
push @all_values, \@values;
- }else{
+ }
+ elsif ($filetype eq 'variable') {
+ my @values = ( eval { $parse->($self, $line) } );
+ if( $@ ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $@;
+ };
+ push @values, $line;
+ push @all_values, \@values;
+ }
+ else {
$dbh->rollback if $oldAutoCommit;
return "Unknown file type $filetype";
}
@@ -420,7 +432,20 @@ sub import_results {
}
}
-
+
+ if ( defined($close_condition) ) {
+ # Allow the module to decide whether to close the batch.
+ # This is used for TD EFT, which requires two imports before
+ # closing.
+ # $close_condition can also die() to abort the whole import.
+ my $close = eval { $close_condition->($self) };
+ if ( $@ ) {
+ $dbh->rollback;
+ die $@;
+ }
+ $self->set_status('I') if !$close;
+ }
+
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';