summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/pay_batch.pm17
-rw-r--r--FS/FS/pay_batch/paymentech.pm99
2 files changed, 62 insertions, 54 deletions
diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index 83bf7a3dc..e0531f445 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -196,7 +196,7 @@ sub import_results {
or die "unknown format $format";
my $filetype = $info->{'filetype'}; # CSV or fixed
- my @fields = @{ $info->{'fields'} };
+ my @fields = @{ $info->{'fields'}};
my $formatre = $info->{'formatre'}; # for fixed
my @all_values;
my $begin_condition = $info->{'begin_condition'};
@@ -256,7 +256,7 @@ sub import_results {
}
$rows = [ $rows ] if ref($rows) ne 'ARRAY';
foreach my $row (@$rows) {
- push @all_values, [ @{$row}{@xmlkeys} ];
+ push @all_values, [ @{$row}{@xmlkeys}, $row ];
}
}
else {
@@ -269,9 +269,9 @@ sub import_results {
$dbh->rollback if $oldAutoCommit;
return "can't parse: ". $csv->error_input();
};
- push @all_values, [ $csv->fields() ];
+ push @all_values, [ $csv->fields(), $line ];
}elsif ($filetype eq 'fixed'){
- my @values = $line =~ /$formatre/;
+ my @values = ( $line =~ /$formatre/, $line );
unless (@values) {
$dbh->rollback if $oldAutoCommit;
return "can't parse: ". $line;
@@ -288,15 +288,20 @@ sub import_results {
my @values = @$_;
my %hash;
+ my $line = pop @values;
foreach my $field ( @fields ) {
my $value = shift @values;
next unless $field;
$hash{$field} = $value;
}
- if ( defined($end_condition) and &{$end_condition}(\%hash) ) {
+ if ( defined($begin_condition) and &{$begin_condition}(\%hash, $line)) {
+ undef $begin_condition;
+ }
+
+ if ( defined($end_condition) and &{$end_condition}(\%hash, $line) ) {
my $error;
- $error = &{$end_hook}(\%hash, $total) if defined($end_hook);
+ $error = &{$end_hook}(\%hash, $total, $line) if defined($end_hook);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
diff --git a/FS/FS/pay_batch/paymentech.pm b/FS/FS/pay_batch/paymentech.pm
index 44fa78a10..b75f256e6 100644
--- a/FS/FS/pay_batch/paymentech.pm
+++ b/FS/FS/pay_batch/paymentech.pm
@@ -5,6 +5,7 @@ use vars qw(@ISA %import_info %export_info $name);
use Time::Local;
use Date::Format 'time2str';
use Date::Parse 'str2time';
+use Tie::IxHash;
use FS::Conf;
my $conf;
@@ -49,7 +50,7 @@ my %paytype = (
%export_info = (
init => sub {
# Load this at run time
- eval "use XML::Simple";
+ eval "use XML::Writer";
die $@ if $@;
my $conf = shift;
($bin, $terminalID, $merchantID, $username) =
@@ -59,53 +60,55 @@ my %paytype = (
header => sub {
my $pay_batch = shift;
my @cust_pay_batch = @{(shift)};
- my $count = 0;
- XML::Simple::XMLout( {
- transRequest => {
- RequestCount => scalar(@cust_pay_batch),
- batchFileID => {
- userID => $username,
- fileDateTime => time2str('%Y%m%d%H%M%s',time),
- fileID => 'batch'.time2str('%Y%m%d',time),
- },
- newOrder => [ map { {
- # $_ here refers to a cust_pay_batch record.
- BatchRequestNo => $count++,
- industryType => 'EC',
- transType => 'AC',
- bin => $bin,
- merchantID => $merchantID,
- terminalID => $terminalID,
- ($_->payby eq 'CARD') ? (
- # Credit card stuff
- ccAccountNum => $_->payinfo,
- ccExp => time2str('%y%m',str2time($_->exp)),
- ) : (
- # ECP (electronic check) stuff
- ecpCheckRT => ($_->payinfo =~ /@(\d+)/),
- ecpCheckDDA => ($_->payinfo =~ /(\d+)@/),
- ecpBankAcctType => $paytype{lc($_->cust_main->paytype)},
- ecpDelvMethod => 'B'
- ),
- avsZip => $_->zip,
- avsAddress1 => $_->address1,
- avsAddress2 => $_->address2,
- avsCity => $_->city,
- avsState => $_->state,
- avsName => $_->first . ' ' . $_->last,
- avsCountryCode => $_->country,
- orderID => $_->paybatchnum,
- amount => $_->amount * 100,
- } } @cust_pay_batch
- ],
- endOfDay => {
- BatchRequestNo => $count++,
- bin => $bin,
- merchantID => $merchantID,
- terminalID => $terminalID
- },
- }
- }, KeepRoot => 1, NoAttr => 1);
+ my $count = 1;
+ my $output;
+ my $xml = new XML::Writer(OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 2);
+ $xml->startTag('transRequest', RequestCount => scalar(@cust_pay_batch) + 1);
+ $xml->startTag('batchFileID');
+ $xml->dataElement(userID => $username);
+ $xml->dataElement(fileDateTime => time2str('%Y%m%d%H%M%s', time));
+ $xml->dataElement(fileID => 'FILEID');
+ $xml->endTag('batchFileID');
+
+ foreach (@cust_pay_batch) {
+ $xml->startTag('newOrder', BatchRequestNo => $count++);
+ tie my %order, 'Tie::IxHash', (
+ industryType => 'EC',
+ transType => 'AC',
+ bin => $bin,
+ merchantID => $merchantID,
+ terminalID => $terminalID,
+ ($_->payby eq 'CARD') ? (
+ ccAccountNum => $_->payinfo,
+ ccExp => time2str('%m%y', str2time($_->exp))
+ ) : (
+ ecpCheckRT => ($_->payinfo =~ /@(\d+)/),
+ ecpCheckDDA => ($_->payinfo =~ /(\d+)@/),
+ ecpBankAcctType => $paytype{lc($_->cust_main->paytype)},
+ ecpDelvMethod => 'A',
+ ),
+ avsZip => $_->zip,
+ avsAddress1 => $_->address1,
+ avsAddress2 => $_->address2,
+ avsCity => $_->city,
+ avsState => $_->state,
+ avsName => $_->first . ' ' . $_->last,
+ avsCountryCode => $_->country,
+ orderID => $_->paybatchnum,
+ amount => $_->amount * 100,
+ );
+ foreach my $key (keys %order) {
+ $xml->dataElement($key, $order{$key})
+ }
+ $xml->endTag('newOrder');
+ }
+ $xml->startTag('endOfDay', BatchRequestNo => $count);
+ $xml->dataElement(bin => $bin);
+ $xml->dataElement(merchantID => $merchantID);
+ $xml->dataElement(terminalID => $terminalID);
+ $xml->endTag('endOfDay');
+ $xml->endTag('transRequest');
+ return $output;
},
row => sub {},
);