import torrus 1.0.9
[freeside.git] / FS / FS / pay_batch / ach_spiritone.pm
1 package FS::pay_batch::ach_spiritone;
2
3 use strict;
4 use vars qw(@ISA %import_info %export_info $name);
5 use Time::Local 'timelocal';
6 use FS::Conf;
7 use File::Temp;
8
9 my $conf;
10 my ($origid, $datacenter, $typecode, $shortname, $longname, $mybank, $myacct);
11
12 $name = 'ach-spiritone'; # note spelling
13
14 %import_info = (
15   'filetype'    => 'CSV',
16   'fields'      => [
17     '', #name
18     'paybatchnum',  
19     'aba',
20     'payinfo', 
21     '', #transaction type
22     'paid',
23     '', #default transaction type
24     '', #default amount
25   ],
26   'hook'        => sub {
27       my $hash = shift;
28       $hash->{'_date'} = time;
29       $hash->{'payinfo'} = $hash->{'payinfo'} . '@' . $hash->{'aba'};
30   },
31   'approved'    => sub { 1 },
32   'declined'    => sub { 0 },
33 );
34
35 %export_info = (
36 # This is the simplest case.
37   row => sub {
38     my ($cust_pay_batch, $pay_batch) = @_;
39     my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
40     my $payname = $cust_pay_batch->first . ' ' . $cust_pay_batch->last;
41     $payname =~ tr/",/  /; 
42     qq!"$payname","!.$cust_pay_batch->paybatchnum.
43     qq!","$aba","$account","27","!.$cust_pay_batch->amount.
44     qq!","27","0.00"!; #"
45   },
46   autopost => sub {
47     my ($pay_batch, $batch) = @_;
48     my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
49     my $fh = new File::Temp(
50       TEMPLATE => 'paybatch.'. $pay_batch->batchnum .'.XXXXXXXX',
51       DIR      => $dir,
52     ) or return "can't open temp file: $!\n";
53
54     print $fh $batch;
55     seek $fh, 0, 0;
56
57     my $error = $pay_batch->import_results( 'filehandle' => $fh,
58                                          'format'     => $name,
59                                        );
60     return $error if $error;
61   },
62 );
63
64 1;
65