5 use Net::SFTP::Foreign;
6 use FS::UID qw(adminsuidsetup datasrc);
7 use FS::Record qw(qsearch qsearchs);
9 use FS::cust_pay_batch;
12 use Date::Format 'time2str';
15 use vars qw( $opt_t $opt_v );
18 #$Net::SFTP::Foreign::debug = -1;
21 paymentech-download [ -v ] [ -t ] user
26 my $user = shift or die &usage;
29 my $tmpdir = File::Temp->newdir();
31 my $conf = new FS::Conf;
32 my @batchconf = $conf->config('batchconfig-paymentech');
33 # BIN, terminalID, merchantID, username, password
34 my $username = $batchconf[3] or die "no Paymentech batch username configured\n";
35 my $password = $batchconf[4] or die "no Paymentech batch password configured\n";
37 my $host = ($opt_t ? 'orbitalbatchvar.paymentech.net' : 'orbitalbatch.paymentech.net');
38 print STDERR "Connecting to $username\@$host...\n" if $opt_v;
40 my $sftp = Net::SFTP::Foreign->new( host => $host,
42 password => $password,
45 die "failed to connect to '$username\@$host'\n(".$sftp->error.")\n" if $sftp->error;
47 my @files = map { $_->{filename} } @{ $sftp->ls('.', wanted => qr/_resp\.zip$/) };
48 die "no response files found\n" if !@files;
50 BATCH: foreach my $filename (@files) {
51 $filename =~ s/\_resp\.zip$//;
52 print STDERR "Retrieving $filename\n" if $opt_v;
53 $sftp->get("$filename\_resp.zip", "$tmpdir/$filename\_resp.zip");
55 warn "failed to download $filename\n";
58 system("unzip -P $password -q $tmpdir/$filename\_resp.zip -d $tmpdir");
59 if(! -f "$tmpdir/$filename\_resp.xml") {
60 warn "failed to extract $filename\_resp.xml\n";
63 open my $fh, "<$tmpdir/$filename\_resp.xml";
64 my ($batchnum) = split ('-', $filename);
65 $batchnum = sprintf("%d", $batchnum); # remove leading zeroes
66 my $batch = qsearchs('pay_batch', { batchnum => $batchnum });
68 warn "batch '$batchnum' not found\n";
71 print STDERR "Importing batch #$batchnum\n" if $opt_v;
72 my $error = $batch->import_results( filehandle => $fh,
73 format => 'paymentech' );
74 warn "error: $error\n" if $error;
76 print STDERR "Finished!\n" if $opt_v;
82 paymentech-download - Retrieve payment batch responses from Chase Paymentech.
86 paymentech-download [ -v ] [ -t ] user
90 Command line tool to download payment batch responses from the Chase Paymentech
91 gateway. These are XML files packaged in ZIP files. This script downloads them
92 by SFTP, extracts the contents, and passes them to L<FS::pay_batch::import_result>.
96 -t: Use the test server.
98 user: freeside username