7 use File::Temp qw(tempdir);
8 use File::Slurp 'write_file';
9 use FS::UID qw(adminsuidsetup dbh);
10 use FS::Record qw(qsearch qsearchs);
14 use vars qw( $opt_a $opt_v $opt_p );
19 freeside-rbc-upload [ -v ] user batchnum
20 freeside-rbc-upload -a [ -p payby ] [ -v ] user\n
24 print STDERR $_[0] if $opt_v;
27 my $user = shift or die &usage;
32 # copied from freeside-paymentech-upload, obviously
34 my %criteria = (status => 'O');
35 $criteria{'payby'} = uc($opt_p) if $opt_p;
36 @batches = qsearch('pay_batch', \%criteria);
37 die "No open batches found".($opt_p ? " of type '$opt_p'" : '').".\n"
42 die &usage if !$batchnum;
43 @batches = qsearchs('pay_batch', { batchnum => $batchnum } );
44 die "Can't find payment batch '$batchnum'\n" if !@batches;
47 my $conf = new FS::Conf;
48 my ($username, $password) = $conf->config('batchconfig-RBC-login');
50 $username and $password
51 or die "RBC FTP login not configured. Enter your username and password in 'batchconfig-rbc-login'.\n";
53 my $host = 'ftpssl.rbc.com';
54 debug "Connecting to $username\@$host...\n";
56 my $date = DateTime->now->strftime('%Y%m%d');
58 my $ftp = Net::FTPSSL->new($host,
60 Debug => ($opt_v ? 1 : 0),
61 Croak => 1, # rely on auto-rollback when dbh closes
63 $ftp->login($username, $password);
65 my $tmpdir = tempdir( CLEANUP => 1 );
67 foreach my $pay_batch (@batches) {
68 my $batchnum = $pay_batch->batchnum;
69 my $filename = $date . '.' . sprintf('%06d', $batchnum);
70 debug "Exporting batch $batchnum to $filename\n";
72 my $text = $pay_batch->export_batch(format => 'RBC');
74 print STDERR "Batch is empty, resolving..." if $opt_v;
77 write_file("$tmpdir/$filename", $text);
79 debug "Uploading $filename...";
80 $ftp->put("$tmpdir/$filename", $filename);
88 freeside-rbc-upload - Transmit a payment batch to RBC via FTP/TLS.
92 freeside-rbc-upload [ -a [ -p PAYBY ] ] [ -v ] user batchnum
96 Command line tool to upload a payment batch to the Royal Bank of Canada
97 ACH service. Use L<freeside-rbc-download> to retrieve the response file.
100 -a: Send all open batches, instead of specifying a batchnum.
102 -p PAYBY: With -a, limit to batches of that payment type, e.g. -p CARD.
106 user: freeside username
108 batchnum: pay_batch primary key