X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpay_batch%2Ftd_eft1464.pm;h=e16b0ee39e114550760ec44e947bbf28e39ef64b;hp=afdc1bef329406afdb9fe032885871903da6dd96;hb=8a16e8aa94e23ad44c0d4d9713ca009913f15b5b;hpb=38691d4d87bec5b1ceffd5a399cdf299af4b1bd5 diff --git a/FS/FS/pay_batch/td_eft1464.pm b/FS/FS/pay_batch/td_eft1464.pm index afdc1bef3..e16b0ee39 100644 --- a/FS/FS/pay_batch/td_eft1464.pm +++ b/FS/FS/pay_batch/td_eft1464.pm @@ -48,6 +48,7 @@ my $i; $name = 'td_eft1464'; # TD Bank EFT 1464 Byte format +# https://www.payments.ca/sites/default/files/standard-005.pdf %import_info = ( filetype => 'NONE' ); # just to suppress warning; importing this format is a fatal error @@ -101,11 +102,19 @@ $name = 'td_eft1464'; row => sub { my ($cust_pay_batch, $pay_batch) = @_; my ($account, $aba) = split('@', $cust_pay_batch->payinfo); + if ( $aba =~ /^(\d+)\.(\d+)$/ ) { #branch.route + $aba = $2.$1; #routebranch + } $i++; # The 1464 byte format supports up to 5 payments per line, # but we're only going to send 1. + + ## set to D for debit by default, then override to what cust_pay_batch has as payments may not have paycode. + my $debitorcredit = 'D'; + $debitorcredit = $cust_pay_batch->paycode unless !$cust_pay_batch->paycode; + my $control = join('', - 'D', # for 'debit' + $debitorcredit, # D for 'debit' or C for Credit sprintf("%09u", $i), #record number $opt{'origid'}, $opt{'fcn'}, @@ -137,19 +146,37 @@ $name = 'td_eft1464'; }, footer => sub { my ($pay_batch, $batchcount, $batchtotal) = @_; + my $totaldebittxns = $pay_batch->type eq "DEBIT" ? $batchtotal*100 : 0; + my $countdebittxns = $pay_batch->type eq "DEBIT" ? $batchcount : 0; + my $totalcredittxns = $pay_batch->type eq "CREDIT" ? $batchtotal*100 : 0; + my $countcredittxns = $pay_batch->type eq "CREDIT" ? $batchcount : 0; join('', 'Z', sprintf('%09u', $batchcount + 2), $opt{'origid'}, $opt{'fcn'}, - sprintf('%014.0f', $batchtotal*100), # total of debit txns - sprintf('%08u', $batchcount), # number of debit txns - '0' x 14, # total of credit txns - '0' x 8, # total of credit txns + sprintf('%014.0f', $totaldebittxns), # total of debit txns + sprintf('%08u', $countdebittxns), # number of debit txns + sprintf('%014.0f', $totalcredittxns), # total of debit txns + sprintf('%08u', $countcredittxns), # number of debit txns ' ' x 1396, ) }, ); +## this format can handle credit transactions +sub can_handle_credits { + 1; +} + +sub _upgrade_gateway { + my $conf = FS::Conf->new; + my @batchconfig = $conf->config('batchconfig-td_eft1464'); + my %options; + @options{ qw(originator datacentre short_name long_name return_branch + return_account cpa_code) } = @batchconfig; + ( 'TD_EFT', %options ); +} + 1;