add explicit use of Expect module, so the error is thrown immediate, RT#5650
[freeside.git] / FS / bin / freeside-paymentech-download
index 214b7f8..12b5c79 100755 (executable)
@@ -5,6 +5,7 @@ use Getopt::Std;
 use Date::Format qw(time2str);
 use File::Temp qw(tempdir); #0.19 for ->newdir() interface, not in 5.10.0
 use Net::SFTP::Foreign;
+use Expect;
 use FS::UID qw(adminsuidsetup datasrc);
 use FS::Record qw(qsearch qsearchs);
 use FS::pay_batch;
@@ -17,7 +18,7 @@ getopts('vta:');
 #$Net::SFTP::Foreign::debug = -1;
 sub usage { "
   Usage:
-      paymentech-download [ -v ] [ -t ] [ -a archivedir ] user\n
+      freeside-paymentech-download [ -v ] [ -t ] [ -a archivedir ] user\n
 " }
 
 my $user = shift or die &usage;
@@ -30,6 +31,8 @@ if ( $opt_a ) {
     unless -w $opt_a;
 }
 
+my $unzip_check = `which unzip` or die "can't find unzip executable\n";
+
 #my $tmpdir = File::Temp->newdir();
 my $tmpdir = tempdir( CLEANUP => 1 ); #DIR=>somewhere?
 
@@ -64,9 +67,10 @@ BATCH: foreach my $filename (@files) {
   }
 
   #unzip file
-  system("unzip -P $password -q $tmpdir/${filename}_resp.zip -d $tmpdir");
+  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";
+    warn "failed to extract ${filename}_resp.xml from ${filename}_resp.zip\n";
     next BATCH;
   }
 
@@ -100,9 +104,7 @@ print STDERR "Finished!\n" if $opt_v;
 
 =head1 NAME
 
-paymentech-download
-
-paymentech-download - Retrieve payment batch responses from Chase Paymentech.
+freeside-paymentech-download - Retrieve payment batch responses from Chase Paymentech.
 
 =head1 SYNOPSIS