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
14 # Meaning of initial characters in records:
15 # 0 - header row, skipped by begin_condition
16 # 1 - Debit Detail Record (only when subtype is 0)
17 # 2 - Credit Detail Record, we die with a parse error (shouldn't appear in freeside-generated batches)
18 # 3 - Account Trailer Record (appears after Returned items, we skip)
19 # 4 - Client Trailer Record, indicates end of batch in end_condition
21 # Subtypes (27th char) indicate different kinds of Debit/Credit records
22 # 0 - Credit/Debit Detail Record
23 # 3 - Error Message Record
24 # 4 - Foreign Currency Information Records
25 # We skip all subtypes except 0
27 'filetype' => 'fixed',
29 '^([0134]).{18}(.{4}).{3}(.).{11}(.{19}).{6}(.{30}).{17}(.{9})(.{18}).{6}(.{14}).{23}(.).{9}\r?$',
43 $hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} / 100 );
44 $hash->{'_date'} = time;
45 $hash->{'payinfo'} =~ s/^(\S+).*/$1/; # these often have trailing spaces
46 $hash->{'payinfo'} = $hash->{'payinfo'} . '@' . $hash->{'bank'};
50 $hash->{'status'} eq ' '
54 grep { $hash->{'status'} eq $_ } ('E', 'R', 'U', 'T');
56 'begin_condition' => sub {
58 $hash->{recordtype} eq '1'; # Detail Record
61 my( $hash, $total, $line ) = @_;
62 $total = sprintf("%.2f", $total);
63 # We assume here that this is an 'All Records' or 'Input Records'
65 my $batch_total = sprintf("%.2f", substr($line, 59, 18) / 100);
66 return "Our total $total does not match bank total $batch_total!"
67 if $total != $batch_total;
70 'end_condition' => sub {
72 $hash->{recordtype} eq '4'; # Client Trailer Record
74 'skip_condition' => sub {
76 $hash->{'recordtype'} eq '3' ||
77 $hash->{'subtype'} ne '0';
88 ) = $conf->config("batchconfig-RBC");
92 my $pay_batch = shift;
93 '$$AAPASTD0152[PROD[NL$$'."\n".
97 sprintf("%10s", $client_num).
98 sprintf("%-30s", $longname).
99 sprintf("%04u", $pay_batch->batchnum).
100 time2str("%Y%j", $pay_batch->download).
103 ' ' x 87 # filler/reserved fields
107 my ($cust_pay_batch, $pay_batch) = @_;
108 my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
109 my($bankno, $branch);
110 if ( $aba =~ /^0(\d{3})(\d{5})$/ ) { # standard format for Canadian bank ID
111 ($bankno, $branch) = ( $1, $2 );
112 } elsif ( $aba =~ /^(\d{5})\.(\d{3})$/ ) { #how we store branches
113 ($branch, $bankno) = ( $1, $2 );
115 die "invalid branch/routing number '$aba'\n";
121 sprintf("%3s",$trans_code).
122 sprintf("%10s",$client_num).
124 sprintf("%-19s", $cust_pay_batch->paybatchnum).
126 sprintf("%04s", $bankno).
127 sprintf("%05s", $branch).
128 sprintf("%-18s", $account).
130 sprintf("%010.0f",$cust_pay_batch->amount*100).
132 time2str("%Y%j", $pay_batch->download).
133 sprintf("%-30s", $cust_pay_batch->cust_main->first . ' ' .
134 $cust_pay_batch->cust_main->last).
137 sprintf("%-15s", $shortname).
142 'N' # no customer optional information follows
144 # Note: IAT Address Information and Remittance records are not
145 # supported. This means you probably can't process payments
146 # destined to U.S. bank accounts. If you need this feature, contact
147 # Freeside Internet Services.
150 my ($pay_batch, $batchcount, $batchtotal) = @_;
151 sprintf("%06u", $i + 1).
154 sprintf("%10s", $client_num).
156 sprintf("%06u", $batchcount).
157 sprintf("%014.0f", $batchtotal*100).
159 '000000' . # total number of customer information records