import torrus 1.0.9
[freeside.git] / FS / FS / pay_batch / chase_canada.pm
1 package FS::pay_batch::chase_canada;
2
3 use strict;
4 use vars qw(@ISA %import_info %export_info $name);
5 use Time::Local 'timelocal';
6 use FS::Conf;
7
8 my $conf;
9 my $origid;
10
11 $name = 'csv-chase_canada-E-xactBatch';
12
13 %import_info = (
14   'filetype'    => 'CSV',
15   'fields'      => [
16     '',
17     '',
18     '',
19     'paid',
20     'auth',
21     'payinfo',
22     '',
23     '',
24     'bankcode',
25     'bankmess',
26     'etgcode',
27     'etgmess',
28     '',
29     'paybatchnum',
30     '',
31     'result',
32   ],
33   'hook'        => sub {
34     my $hash = shift;
35     my $cpb = shift;
36     $hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} );
37     $hash->{'_date'} = time;
38     $hash->{'payinfo'} = $cpb->{'payinfo'}
39       if( substr($hash->{'payinfo'}, -4) eq substr($cpb->{'payinfo'}, -4) );
40   },
41   'approved'    => sub { 
42     my $hash = shift;
43     $hash->{'etgcode'} eq '00' && $hash->{'result'} eq 'Approved';
44   },
45   'declined'    => sub { 
46     my $hash = shift;
47     $hash->{'etgcode'} ne '00' || $hash->{'result'} eq 'Declined';
48   },
49 );
50
51 %export_info = (
52   init => sub {
53     $conf = shift;
54     ($origid) = $conf->config("batchconfig-$name");
55   },
56   header => sub { 
57     my $pay_batch = shift;
58     sprintf( '$$E-xactBatchFileV1.0$$%s:%03u$$%s',
59       sdate($pay_batch->download),
60       $pay_batch->batchnum, 
61       $origid );
62   },
63   row => sub {
64     my ($cust_pay_batch, $pay_batch) = @_;
65     my $payname = $cust_pay_batch->payname;
66     $payname =~ tr/",/  /;
67                 
68     join(',', 
69       $cust_pay_batch->paybatchnum,
70       $cust_pay_batch->custnum,
71       $cust_pay_batch->invnum,
72       qq!"$payname"!,
73       '00',
74       $cust_pay_batch->payinfo,
75       $cust_pay_batch->amount,
76       $cust_pay_batch->expmmyy,
77       '',
78       ''
79     );
80   },
81   # no footer
82 );
83
84 sub sdate {
85   my (@date) = localtime(shift);
86   sprintf('%02d/%02d/%02d', $date[5] % 100, $date[4] + 1, $date[3]);
87 }
88
89 1;