summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2009-11-03 01:44:06 +0000
committerivan <ivan>2009-11-03 01:44:06 +0000
commit0a223fd9019513a64959797691b082ca1dd831e0 (patch)
tree7afa69ce9b9479d3f5f2f2152b1b4761aabfe788
parent1bbb913b003271d9921e5968184282c216a8a447 (diff)
add -a option for archive dir
-rwxr-xr-xbin/paymentech-download49
1 files changed, 38 insertions, 11 deletions
diff --git a/bin/paymentech-download b/bin/paymentech-download
index 07d5c7877..23e3a0ef7 100755
--- a/bin/paymentech-download
+++ b/bin/paymentech-download
@@ -12,13 +12,13 @@ use FS::Conf;
use Date::Format 'time2str';
use File::Temp;
-use vars qw( $opt_t $opt_v );
-getopts('vt');
+use vars qw( $opt_t $opt_v $opt_a );
+getopts('vta:');
#$Net::SFTP::Foreign::debug = -1;
sub usage { '
Usage:
- paymentech-download [ -v ] [ -t ] user
+ paymentech-download [ -v ] [ -t ] [ -a archivedir ] user
'
}
@@ -26,6 +26,13 @@ sub usage { '
my $user = shift or die &usage;
adminsuidsetup $user;
+if ( $opt_a ) {
+ die "no such directory: $opt_a\n"
+ unless -d $opt_a;
+ die "archive directory $opt_a is not writeable by the freeside user\n"
+ unless -w $opt_a;
+}
+
my $tmpdir = File::Temp->newdir();
my $conf = new FS::Conf;
@@ -48,19 +55,33 @@ my @files = map { $_->{filename} } @{ $sftp->ls('.', wanted => qr/_resp\.zip$/)
die "no response files found\n" if !@files;
BATCH: foreach my $filename (@files) {
- $filename =~ s/\_resp\.zip$//;
+
+ #get file
+ $filename =~ s/_resp\.zip$//;
print STDERR "Retrieving $filename\n" if $opt_v;
- $sftp->get("$filename\_resp.zip", "$tmpdir/$filename\_resp.zip");
+ $sftp->get("$filename\_resp.zip", "$tmpdir/${filename}_resp.zip");
if($sftp->error) {
warn "failed to download $filename\n";
next BATCH;
}
- system("unzip -P $password -q $tmpdir/$filename\_resp.zip -d $tmpdir");
- if(! -f "$tmpdir/$filename\_resp.xml") {
- warn "failed to extract $filename\_resp.xml\n";
+
+ #unzip file
+ system("unzip -P $password -q $tmpdir/${filename}_resp.zip -d $tmpdir");
+ if(! -f "$tmpdir/${filename}_resp.xml") {
+ warn "failed to extract ${filename}_resp.xml\n";
next BATCH;
}
- open my $fh, "<$tmpdir/$filename\_resp.xml";
+
+ #copy to archive dir
+ if ( $opt_a ) {
+ print STDERR "Copying $tmpdir/${filename}_resp.xml to archive dir $opt_a\n"
+ if $opt_v;
+ system 'cp', "$tmpdir/${filename}_resp.xml", $opt_a;
+ warn "failed to copy $tmpdir/${filename}_resp.xml to $opt_a: $@" if $@;
+ }
+
+ #get batchnum & retrieve pending batch
+ open my $fh, "<$tmpdir/${filename}_resp.xml";
my ($batchnum) = split ('-', $filename);
$batchnum = sprintf("%d", $batchnum); # remove leading zeroes
my $batch = qsearchs('pay_batch', { batchnum => $batchnum });
@@ -68,11 +89,15 @@ BATCH: foreach my $filename (@files) {
warn "batch '$batchnum' not found\n";
next BATCH;
}
+
+ #and import results
print STDERR "Importing batch #$batchnum\n" if $opt_v;
my $error = $batch->import_results( filehandle => $fh,
format => 'paymentech' );
warn "error: $error\n" if $error;
-};
+
+}
+
print STDERR "Finished!\n" if $opt_v;
=head1 NAME
@@ -83,7 +108,7 @@ paymentech-download - Retrieve payment batch responses from Chase Paymentech.
=head1 SYNOPSIS
- paymentech-download [ -v ] [ -t ] user
+ paymentech-download [ -v ] [ -t ] [ -a archivedir ] user
=head1 DESCRIPTION
@@ -95,6 +120,8 @@ by SFTP, extracts the contents, and passes them to L<FS::pay_batch::import_resul
-t: Use the test server.
+-a directory: Archive response files in the provided directory.
+
user: freeside username
=head1 BUGS