1 package FS::pay_batch::td_eft1464;
4 use vars qw(@ISA %import_info %export_info $name);
5 use Date::Format 'time2str';
7 use FS::Record qw(qsearch);
11 td_eft1464 - TD Commercial Banking EFT1464 format
15 The Freeside option 'batchconfig-td_eft1464' must be set
16 with the following values on separate lines:
22 =item TD Datacenter Location
35 =item Returned Payment Branch (5 digits)
37 =item Returned Payment Account
39 =item Transaction Type Code - defaults to "437" (Internet access)
50 # TD Bank EFT 1464 Byte format
53 'filetype' => 'variable',
62 $hash->{'_date'} = time;
63 $hash->{'paid'} = sprintf('%.2f', $hash->{'paid'});
67 $hash->{'status'} eq 'A'
71 $hash->{'status'} eq 'D';
73 'begin_condition' => sub {
75 $hash->{'status'} eq 'A' or $hash->{'status'} eq 'D';
77 'end_condition' => sub {
79 $hash->{'status'} eq 'END'
81 'close_condition' => sub {
83 my @cust_pay_batch = qsearch('cust_pay_batch',
84 { batchnum => $batch->batchnum }
86 return ( (grep {! length($_->status) } @cust_pay_batch) == 0 );
91 my ($batch, $line) = @_;
92 $batch->setfield('import_state','') if !$batch->import_state;
93 return 'END' if $batch->import_state eq 'END';
94 if( $batch->import_state eq '212' ) {
96 # trace number, trans type, amount, due date, routing number,
97 # account number, xref number, return routing number and account
98 # The only ones we take are amount and xref number.
99 if( $line =~ /CREDITS\s+DEBITS/ ) {
100 $batch->setfield('import_state', 'END');
103 $line =~ /^\d{22} D\d{3} (.{14}) \d{5} \d{4}-\d{5} .{12} (.{19}).*$/
104 or die "can't parse: $line";
105 # strip leading zeroes/spaces from paybatchnum at this point
106 return ('A', $1, sprintf('%u',$2));
108 elsif( $batch->import_state eq '234' ) {
110 # payor name, xref number, due date, routing number, account number,
111 # amount, reason for return
112 if( $line =~ /TOTAL NUMBER -/ ) {
113 $batch->setfield('import_state', 'END');
116 $line =~ /^.{22} (.{19}) \d\d\/\d\d\/\d\d \d{9} .{12} (.{14}).*$/
117 or die "can't parse: $line";
118 return ('D', $2, sprintf('%u',$1));
121 if ( $line =~ /ITEM TRACE NUMBER/ ) {
122 $batch->setfield('import_state','212');
124 elsif ( $line =~ /REASON FOR RETURN/ ) {
125 $batch->setfield('import_state','234');
126 } # else leave it undefined
142 } = $conf->config("batchconfig-td_eft1464");
143 $opt{'origid'} = sprintf('%-10s', $opt{'origid'});
144 $opt{'shortname'} = sprintf('%-15s', $opt{'shortname'});
145 $opt{'longname'} = sprintf('%-30s', $opt{'longname'});
146 $opt{'retbranch'} = '0004'.sprintf('%5s',$opt{'retbranch'});
147 $opt{'retacct'} = sprintf('%-11s', $opt{'retacct'}). ' ';
151 my $pay_batch = shift;
152 my @cust_pay_batch = @{(shift)};
153 my $time = $pay_batch->download || time;
154 my $now = sprintf("%03u%03u",
155 (localtime(time))[5],#year since 1900
156 (localtime(time))[7]+1);#day of year
158 # Request settlement the next day
159 my $duedate = time+86400;
160 $opt{'due'} = sprintf("%03u%03u",
161 (localtime($duedate))[5],
162 (localtime($duedate))[7]+1);
165 sprintf('%04u', ($pay_batch->batchnum % 9999)+1), # file creation number
168 sprintf('%09u', 1), #record number
177 my ($cust_pay_batch, $pay_batch) = @_;
178 my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
180 # The 1464 byte format supports up to 5 payments per line,
181 # but we're only going to send 1.
182 my $control = join('',
184 sprintf("%09u", $i), #record number
188 my $payment = join('',
189 $opt{'cpacode'} || 437, # CPA code, defaults to "Internet access"
190 sprintf('%010.0f', $cust_pay_batch->amount*100),
191 $opt{'due'}, #due date...? XXX
192 sprintf('%09u', $aba),
193 sprintf('%-12s', $account),
199 $cust_pay_batch->first, $cust_pay_batch->last)
203 sprintf('%-19s', $cust_pay_batch->paybatchnum), # originator reference num
210 return $control . $payment . (' ' x 720);
213 my ($pay_batch, $batchcount, $batchtotal) = @_;
216 sprintf('%09u', $batchcount + 2),
219 sprintf('%014.0f', $batchtotal*100), # total of debit txns
220 sprintf('%08u', $batchcount), # number of debit txns
221 '0' x 14, # total of credit txns
222 '0' x 8, # total of credit txns