summaryrefslogtreecommitdiff
path: root/FS/FS/pay_batch/eft_canada.pm
diff options
context:
space:
mode:
authormark <mark>2011-07-22 19:07:43 +0000
committermark <mark>2011-07-22 19:07:43 +0000
commitdb4d8679af26c301cb66f3f3da7f7cd7a3ae4854 (patch)
tree77806e63e63f18fe099b255aab12edd0feb69f41 /FS/FS/pay_batch/eft_canada.pm
parentc405e80203f323a83b447d6fc899dbba32d52f2a (diff)
EFT Canada batch format and scripts, #13628
Diffstat (limited to 'FS/FS/pay_batch/eft_canada.pm')
-rw-r--r--FS/FS/pay_batch/eft_canada.pm63
1 files changed, 63 insertions, 0 deletions
diff --git a/FS/FS/pay_batch/eft_canada.pm b/FS/FS/pay_batch/eft_canada.pm
new file mode 100644
index 0000000..0e41610
--- /dev/null
+++ b/FS/FS/pay_batch/eft_canada.pm
@@ -0,0 +1,63 @@
+package FS::pay_batch::eft_canada;
+
+use strict;
+use vars qw(@ISA %import_info %export_info $name);
+use FS::Record 'qsearch';
+use FS::Conf;
+use FS::cust_pay_batch;
+use Date::Format 'time2str';
+use Time::Local 'timelocal';
+
+my $conf;
+my $origid;
+
+$name = 'eft_canada';
+
+%import_info = ( filetype => 'NONE' ); # see FS/bin/freeside-eftca-download
+
+my ($trans_code, $process_date);
+
+%export_info = (
+ init => sub {
+ my $conf = shift;
+ my @config = $conf->config('batchconfig-eft_canada');
+ # SFTP login, password, trans code, delay time
+ my $process_delay;
+ ($trans_code, $process_delay) = @config[2,3];
+ $process_delay ||= 1; # days
+ $process_date = time2str('%D', time + ($process_delay * 86400));
+ },
+ delimiter => '', # avoid blank lines for header/footer
+ # EFT Upload Specification for .CSV Files, Rev. 2.0
+ # not a true CSV format--strings aren't quoted, so be careful
+ row => sub {
+ my ($cust_pay_batch, $pay_batch) = @_;
+ my @fields;
+ # company + empty or first + last
+ my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company);
+ if ( $company ) {
+ push @fields, $company, ''
+ }
+ else {
+ push @fields, map { sprintf('%.64s', $_) }
+ $cust_pay_batch->first, $cust_pay_batch->last;
+ }
+ my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
+ # standard format for Canadian bank ID
+ $aba =~ /^0(\d{3})(\d{5})$/
+ or die "invalid routing number '$aba'\n";
+ push @fields, sprintf('%05s', $2),
+ sprintf('%03s', $1),
+ sprintf('%012s', $account),
+ sprintf('%.02f', $cust_pay_batch->amount);
+ # DB = debit
+ push @fields, 'DB', $trans_code, $process_date;
+ push @fields, $cust_pay_batch->paybatchnum; # reference
+ # strip illegal characters that might occur in customer name
+ s/[,|']//g foreach @fields; # better substitution for these?
+ return join(',', @fields) . "\n";
+ },
+
+);
+
+1;