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;
22 paymentech-upload [ -v ] [ -t ] user batchnum
27 my $user = shift or die &usage;
30 my $batchnum = shift or die &usage;
31 my $pay_batch = qsearchs('pay_batch', { batchnum => $batchnum })
32 or die "can't find payment batch '$batchnum'\n";
34 my $filename = sprintf('%06d',$batchnum) . '-' .time2str('%Y%m%d%H%M%S', time);
35 print STDERR "Exporting batch $batchnum to $filename...\n" if $opt_v;
36 my $tmpdir = File::Temp->newdir();
37 my $text = $pay_batch->export_batch('paymentech');
38 $text =~ s!<fileID>FILEID</fileID>!<fileID>$filename</fileID>!
39 or die "couldn't find FILEID tag\n";
40 open OUT, ">$tmpdir/$filename.xml";
44 my $conf = new FS::Conf;
45 my @batchconf = $conf->config('batchconfig-paymentech');
46 # BIN, terminalID, merchantID, username, password
47 my $username = $batchconf[3] or die "no Paymentech batch username configured\n";
48 my $password = $batchconf[4] or die "no Paymentech batch password configured\n";
50 # This is less than ideal.
51 system("zip -P $password -q -j $tmpdir/$filename.zip $tmpdir/$filename.xml");
53 die "failed to create zip file\n" if (! -f "$tmpdir/$filename.zip" );
56 #my $host = ($opt_t ? 'orbitalbatchvar.paymentech.net' : 'orbitalbatch.paymentech.net');
57 my $host = ($opt_t ? 'orbitalbatchvar.paymentech.net' : '127.0.0.1');
58 print STDERR "Connecting to $username\@$host...\n" if $opt_v;
60 my $sftp = Net::SFTP::Foreign->new( host => $host,
62 password => $password,
65 die "failed to connect to '$username\@$host'\n(".$sftp->error.")\n" if $sftp->error;
67 $sftp->put("$tmpdir/$filename.zip", "$filename.zip")
68 or die "failed to upload file (".$sftp->error.")\n";
70 print STDERR "Finished!\n" if $opt_v;
76 paymentech-upload - Transmit a payment batch to Chase Paymentech via SFTP.
80 paymentech-upload [ -v ] [ -t ] user batchnum
84 Command line tool to upload a payment batch to the Chase Paymentech gateway.
85 The batch will be exported to the Paymentech XML format, packaged in a ZIP
86 file, and transmitted via SFTP. Use L<paymentech-download> to retrieve the
91 -t: Send the transaction to the test server.
93 user: freeside username
95 batchnum: pay_batch primary key
99 Passing the zip password on the command line is slightly risky.