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_a $opt_t $opt_v );
18 #$Net::SFTP::Foreign::debug = -1;
22 paymentech-upload [ -v ] [ -t ] user batchnum
23 paymentech-upload -a [ -v ] [ -t ] user
28 my $user = shift or die &usage;
34 @batches = qsearch('pay_batch', { status => 'O' } );
35 die "No open batches found.\n" if !@batches;
39 die &usage if !$batchnum;
40 @batches = qsearchs('pay_batch', { batchnum => $batchnum } );
41 die "Can't find payment batch '$batchnum'\n" if !@batches;
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 my $tmpdir = File::Temp->newdir();
54 foreach my $pay_batch (@batches) {
55 my $batchnum = $pay_batch->batchnum;
56 my $filename = sprintf('%06d',$batchnum) . '-' .time2str('%Y%m%d%H%M%S', time);
57 print STDERR "Exporting batch $batchnum to $filename...\n" if $opt_v;
58 my $text = $pay_batch->export_batch('paymentech');
59 $text =~ s!<fileID>FILEID</fileID>!<fileID>$filename</fileID>!
60 or die "couldn't find FILEID tag\n";
61 open OUT, ">$tmpdir/$filename.xml";
65 system("zip -P $password -q -j $tmpdir/$filename.zip $tmpdir/$filename.xml");
67 die "failed to create zip file\n" if (! -f "$tmpdir/$filename.zip" );
68 push @filenames, $filename;
71 my $host = ($opt_t ? 'orbitalbatchvar.paymentech.net' :
72 'orbitalbatch.paymentech.net');
73 print STDERR "Connecting to $username\@$host...\n" if $opt_v;
75 my $sftp = Net::SFTP::Foreign->new( host => $host,
77 password => $password,
80 die "failed to connect to '$username\@$host'\n(".$sftp->error.")\n"
83 foreach my $filename (@filenames) {
84 $sftp->put("$tmpdir/$filename.zip", "$filename.zip")
85 or die "failed to upload file (".$sftp->error.")\n";
88 print STDERR "Finished!\n" if $opt_v;
94 paymentech-upload - Transmit a payment batch to Chase Paymentech via SFTP.
98 paymentech-upload [ -a ] [ -v ] [ -t ] user batchnum
102 Command line tool to upload a payment batch to the Chase Paymentech gateway.
103 The batch will be exported to the Paymentech XML format, packaged in a ZIP
104 file, and transmitted via SFTP. Use L<paymentech-download> to retrieve the
107 -a: Send all open batches, instead of specifying a batchnum.
111 -t: Send the transaction to the test server.
113 user: freeside username
115 batchnum: pay_batch primary key
119 Passing the zip password on the command line is slightly risky.