1 package FS::pay_batch::eft_canada;
4 use vars qw(@ISA %import_info %export_info $name);
5 use FS::Record 'qsearch';
7 use FS::cust_pay_batch;
8 use Date::Format 'time2str';
9 use Time::Local 'timelocal';
16 %import_info = ( filetype => 'NONE' ); # see FS/bin/freeside-eftca-download
18 my ($trans_code, $process_date);
23 my @config = $conf->config('batchconfig-eft_canada');
24 # SFTP login, password, trans code, delay time
26 ($trans_code, $process_delay) = @config[2,3];
27 $process_delay ||= 1; # days
28 $process_date = time2str('%D', time + ($process_delay * 86400));
30 delimiter => '', # avoid blank lines for header/footer
31 # EFT Upload Specification for .CSV Files, Rev. 2.0
32 # not a true CSV format--strings aren't quoted, so be careful
34 my ($cust_pay_batch, $pay_batch) = @_;
36 # company + empty or first + last
37 my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company);
39 push @fields, $company, ''
42 push @fields, map { sprintf('%.64s', $_) }
43 $cust_pay_batch->first, $cust_pay_batch->last;
45 my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
47 if ( $aba =~ /^0(\d{3})(\d{5})$/ ) { # standard format for Canadian bank ID
48 ($bankno, $branch) = ( $1, $2 );
49 } elsif ( $aba =~ /^(\d{5})\.(\d{3})$/ ) { #how we store branches
50 ($branch, $bankno) = ( $1, $2 );
52 die "invalid branch/routing number '$aba'\n";
54 push @fields, sprintf('%05s', $branch),
55 sprintf('%03s', $bankno),
56 sprintf('%012s', $account),
57 sprintf('%.02f', $cust_pay_batch->amount);
59 push @fields, 'DB', $trans_code, $process_date;
60 push @fields, $cust_pay_batch->paybatchnum; # reference
61 # strip illegal characters that might occur in customer name
62 s/[,|']//g foreach @fields; # better substitution for these?
63 return join(',', @fields) . "\n";