This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / pay_batch / td_canada_trust.pm
1 package FS::pay_batch::td_canada_trust;
2
3 # Formerly known as csv-td_canada_trust-merchant_pc_batch,
4 # which I'm sure we can all agree is both a terrible name 
5 # and an illegal Perl identifier.
6
7 use strict;
8 use vars qw(@ISA %import_info %export_info $name);
9 use Time::Local 'timelocal';
10 use FS::Conf;
11
12 my $conf;
13 my ($origid, $datacenter, $typecode, $shortname, $longname, $mybank, $myacct);
14
15 $name = 'csv-td_canada_trust-merchant_pc_batch';
16
17 %import_info = (
18   'filetype'    => 'CSV',
19   'fields'      => [
20     'paybatchnum',  
21     'paid',
22     '', # card type
23     '_date',
24     'time',
25     'payinfo', 
26     '', # expiry date
27     '', # auth number
28     'type', # transaction type
29     'result', # processing result
30     '', # terminal ID
31   ],
32   'hook'        => sub {
33       my $hash = shift;
34       my $date = $hash->{'_date'};
35       my $time = $hash->{'time'};
36       $hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} / 100);
37       $hash->{'_date'} = timelocal( substr($time, 4, 2),
38                                     substr($time, 2, 2),
39                                     substr($time, 0, 2),
40                                     substr($date, 6, 2),
41                                     substr($date, 4, 2)-1,
42                                     substr($date, 0, 4)-1900 );
43   },
44   'approved'    => sub { 
45     my $hash = shift;
46     $hash->{'type'} eq '0' && $hash->{'result'} == 3
47   },
48   'declined'    => sub { 
49     my $hash = shift;
50     $hash->{'type'} eq '0' && ( $hash->{'result'} == 4
51                             ||  $hash->{'result'} == 5 )
52   },
53   'end_condition' => sub {
54     my $hash = shift;
55     $hash->{'type'} eq '0BC';
56   },
57   'end_hook' => sub {
58     my ($hash, $total) = @_;
59     $total = sprintf("%.2f", $total);
60     my $batch_total = sprintf("%.2f", $hash->{'paybatchnum'} / 100);
61     return "Our total $total does not match bank total $batch_total!"
62       if $total != $batch_total;
63   },
64 );
65
66 %export_info = (
67   init => sub { 
68     $conf = shift; 
69   },
70   # no header
71   row => sub {
72     my ($cust_pay_batch, $pay_batch) = @_;
73
74     return join(',', 
75       '',
76       '',
77       '',
78       '', 
79       $cust_pay_batch->payinfo,
80       $cust_pay_batch->expmmyy,
81       $cust_pay_batch->amount,
82       $cust_pay_batch->paybatchnum
83       );
84   },
85 # no footer
86 );
87
88
89 1;
90