[freeside-commits] freeside/bin paymentech-download,1.1,1.2
Ivan,,,
ivan at wavetail.420.am
Mon Nov 2 17:44:08 PST 2009
Update of /home/cvs/cvsroot/freeside/bin
In directory wavetail.420.am:/tmp/cvs-serv15027
Modified Files:
paymentech-download
Log Message:
add -a option for archive dir
Index: paymentech-download
===================================================================
RCS file: /home/cvs/cvsroot/freeside/bin/paymentech-download,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- paymentech-download 24 Oct 2009 23:37:42 -0000 1.1
+++ paymentech-download 3 Nov 2009 01:44:06 -0000 1.2
@@ -12,13 +12,13 @@
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 @@
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 @@
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 @@
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 @@
=head1 SYNOPSIS
- paymentech-download [ -v ] [ -t ] user
+ paymentech-download [ -v ] [ -t ] [ -a archivedir ] user
=head1 DESCRIPTION
@@ -95,6 +120,8 @@
-t: Use the test server.
+-a directory: Archive response files in the provided directory.
+
user: freeside username
=head1 BUGS
More information about the freeside-commits
mailing list