1 package FS::pay_batch::RBC;
4 use vars qw(@ISA %import_info %export_info $name);
5 use Date::Format 'time2str';
9 my ($client_num, $shortname, $longname, $trans_code, $i);
12 # Royal Bank of Canada ACH Direct Payments Service
15 'filetype' => 'fixed',
17 '^([0134]).{18}(.{4}).{3}(.).{11}(.{19}).{6}(.{30}).{17}(.{9})(.{18}).{6}(.{14}).{23}(.).{9}\r?$',
31 $hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} / 100 );
32 $hash->{'_date'} = time;
33 $hash->{'payinfo'} =~ s/^(\S+).*/$1/; # these often have trailing spaces
34 $hash->{'payinfo'} = $hash->{'payinfo'} . '@' . $hash->{'bank'};
38 $hash->{'status'} eq ' '
42 grep { $hash->{'status'} eq $_ } ('E', 'R', 'U', 'T');
44 'begin_condition' => sub {
46 $hash->{recordtype} eq '1'; # Detail Record
49 my( $hash, $total, $line ) = @_;
50 $total = sprintf("%.2f", $total);
51 # We assume here that this is an 'All Records' or 'Input Records'
53 my $batch_total = sprintf("%.2f", substr($line, 59, 18) / 100);
54 return "Our total $total does not match bank total $batch_total!"
55 if $total != $batch_total;
58 'end_condition' => sub {
60 $hash->{recordtype} eq '4'; # Client Trailer Record
62 'skip_condition' => sub {
64 $hash->{'recordtype'} eq '3' ||
65 $hash->{'subtype'} ne '0';
76 ) = $conf->config("batchconfig-RBC");
80 my $pay_batch = shift;
81 '$$AAPASTD0152[PROD[NL$$'."\n".
85 sprintf("%10s", $client_num).
86 sprintf("%-30s", $longname).
87 sprintf("%04u", $pay_batch->batchnum).
88 time2str("%Y%j", $pay_batch->download).
91 ' ' x 87 # filler/reserved fields
95 my ($cust_pay_batch, $pay_batch) = @_;
96 my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
98 if ( $aba =~ /^0(\d{3})(\d{5})$/ ) { # standard format for Canadian bank ID
99 ($bankno, $branch) = ( $1, $2 );
100 } elsif ( $aba =~ /^(\d{5})\.(\d{3})$/ ) { #how we store branches
101 ($branch, $bankno) = ( $1, $2 );
103 die "invalid branch/routing number '$aba'\n";
109 sprintf("%3s",$trans_code).
110 sprintf("%10s",$client_num).
112 sprintf("%-19s", $cust_pay_batch->paybatchnum).
114 sprintf("%04s", $bankno).
115 sprintf("%05s", $branch).
116 sprintf("%-18s", $account).
118 sprintf("%010.0f",$cust_pay_batch->amount*100).
120 time2str("%Y%j", $pay_batch->download).
121 sprintf("%-30s", $cust_pay_batch->cust_main->first . ' ' .
122 $cust_pay_batch->cust_main->last).
125 sprintf("%-15s", $shortname).
130 'N' # no customer optional information follows
132 # Note: IAT Address Information and Remittance records are not
133 # supported. This means you probably can't process payments
134 # destined to U.S. bank accounts. If you need this feature, contact
135 # Freeside Internet Services.
138 my ($pay_batch, $batchcount, $batchtotal) = @_;
139 sprintf("%06u", $i + 1).
142 sprintf("%10s", $client_num).
144 sprintf("%06u", $batchcount).
145 sprintf("%014.0f", $batchtotal*100).
147 '000000' . # total number of customer information records